μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Macros | Typedefs | Functions | Variables
internals.h File Reference
#include "common.h"
#include "../pytypes.h"
#include <exception>
Include dependency graph for internals.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  type_hash
 
struct  type_equal_to
 
struct  override_hash
 
struct  internals
 Internal data structure used to track registered instances and types. More...
 
struct  type_info
 Additional type information which does not fit into the PyTypeObject. More...
 
struct  local_internals
 

Macros

#define PYBIND11_INTERNALS_VERSION   4
 Tracks the internals and type_info ABI version independent of the main library version. More...
 
#define PYBIND11_TLS_KEY_REF   decltype(PyThread_create_key())
 
#define PYBIND11_TLS_KEY_INIT(var)   PYBIND11_TLS_KEY_REF var = 0;
 
#define PYBIND11_TLS_KEY_CREATE(var)   (((var) = PyThread_create_key()) != -1)
 
#define PYBIND11_TLS_GET_VALUE(key)   PyThread_get_key_value((key))
 
#define PYBIND11_TLS_DELETE_VALUE(key)   PyThread_set_key_value((key), nullptr)
 
#define PYBIND11_TLS_REPLACE_VALUE(key, value)   PyThread_set_key_value((key), (value))
 
#define PYBIND11_TLS_FREE(key)   (void) key
 
#define PYBIND11_BUILD_TYPE   ""
 On MSVC, debug and release builds are not ABI-compatible! More...
 
#define PYBIND11_COMPILER_TYPE   "_unknown"
 Let's assume that different compilers are ABI-incompatible. More...
 
#define PYBIND11_STDLIB   ""
 Also standard libs. More...
 
#define PYBIND11_BUILD_ABI   ""
 On Linux/OSX, changes in GXX_ABI_VERSION indicate ABI incompatibility. More...
 
#define PYBIND11_INTERNALS_KIND   "_without_thread"
 
#define PYBIND11_INTERNALS_ID
 
#define PYBIND11_MODULE_LOCAL_ID
 

Typedefs

using ExceptionTranslator = void(*)(std::exception_ptr)
 
template<typename value_type >
using type_map = std::unordered_map< std::type_index, value_type, type_hash, type_equal_to >
 

Functions

PyTypeObject * make_static_property_type ()
 A static_property is the same as a property but the __get__() and __set__() methods are modified to always use the object type instead of a concrete instance. More...
 
PyTypeObject * make_default_metaclass ()
 This metaclass is assigned by default to all pybind11 types and is required in order for static properties to function correctly. More...
 
PyObject * make_object_base_type (PyTypeObject *metaclass)
 Create the type which can be used as a common base for all classes. More...
 
bool same_type (const std::type_info &lhs, const std::type_info &rhs)
 
internals **& get_internals_pp ()
 Each module locally stores a pointer to the internals data. More...
 
void translate_exception (std::exception_ptr)
 
template<class T , enable_if_t< std::is_same< std::nested_exception, remove_cvref_t< T > >::value, int > = 0>
bool handle_nested_exception (const T &exc, const std::exception_ptr &p)
 
bool raise_err (PyObject *exc_type, const char *msg)
 
void translate_local_exception (std::exception_ptr p)
 
PYBIND11_NOINLINE internalsget_internals ()
 Return a reference to the current internals data. More...
 
local_internalsget_local_internals ()
 Works like get_internals, but for things which are locally registered. More...
 
template<typename... Args>
const char * c_str (Args &&...args)
 Constructs a std::string with the given arguments, stores it in internals, and returns its c_str(). More...
 
const char * get_function_record_capsule_name ()
 
bool is_function_record_capsule (const capsule &cap)
 
PYBIND11_NOINLINE void * get_shared_data (const std::string &name)
 Returns a named pointer that is shared among all extension modules (using the same pybind11 version) running in the current interpreter. More...
 
PYBIND11_NOINLINE void * set_shared_data (const std::string &name, void *data)
 Set the shared data that can be later recovered by get_shared_data(). More...
 
template<typename T >
T & get_or_create_shared_data (const std::string &name)
 Returns a typed reference to a shared data entry (by using get_shared_data()) if such entry exists. More...
 

Variables

constexpr const char * internals_function_record_capsule_name = "pybind11_function_record_capsule"
 

Macro Definition Documentation

◆ PYBIND11_BUILD_ABI

#define PYBIND11_BUILD_ABI   ""

On Linux/OSX, changes in GXX_ABI_VERSION indicate ABI incompatibility.

Definition at line 288 of file internals.h.

◆ PYBIND11_BUILD_TYPE

#define PYBIND11_BUILD_TYPE   ""

On MSVC, debug and release builds are not ABI-compatible!

Definition at line 246 of file internals.h.

◆ PYBIND11_COMPILER_TYPE

#define PYBIND11_COMPILER_TYPE   "_unknown"

Let's assume that different compilers are ABI-incompatible.

A user can manually set this string if they know their compiler is compatible.

Definition at line 268 of file internals.h.

◆ PYBIND11_INTERNALS_ID

#define PYBIND11_INTERNALS_ID
Value:
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
PYBIND11_BUILD_TYPE "__"
#define PYBIND11_TOSTRING(x)
Definition: common.h:344
#define PYBIND11_STDLIB
Also standard libs.
Definition: internals.h:259
#define PYBIND11_INTERNALS_KIND
Definition: internals.h:276
#define PYBIND11_INTERNALS_VERSION
Tracks the internals and type_info ABI version independent of the main library version.
Definition: internals.h:31
#define PYBIND11_COMPILER_TYPE
Let's assume that different compilers are ABI-incompatible.
Definition: internals.h:248

Definition at line 300 of file internals.h.

◆ PYBIND11_INTERNALS_KIND

#define PYBIND11_INTERNALS_KIND   "_without_thread"

Definition at line 296 of file internals.h.

◆ PYBIND11_INTERNALS_VERSION

#define PYBIND11_INTERNALS_VERSION   4

Tracks the internals and type_info ABI version independent of the main library version.

Some portions of the code use an ABI that is conditional depending on this version number. That allows ABI-breaking changes to be "pre-implemented". Once the default version number is incremented, the conditional logic that no longer applies can be removed. Additionally, users that need not maintain ABI compatibility can increase the version number in order to take advantage of any functionality/efficiency improvements that depend on the newer ABI.

WARNING: If you choose to manually increase the ABI version, note that pybind11 may not be tested as thoroughly with a non-default ABI version, and further ABI-incompatible changes may be made before the ABI is officially changed to the new version.

Definition at line 37 of file internals.h.

◆ PYBIND11_MODULE_LOCAL_ID

#define PYBIND11_MODULE_LOCAL_ID
Value:
"__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
PYBIND11_BUILD_TYPE "__"

Definition at line 305 of file internals.h.

◆ PYBIND11_STDLIB

#define PYBIND11_STDLIB   ""

Also standard libs.

Definition at line 279 of file internals.h.

◆ PYBIND11_TLS_DELETE_VALUE

#define PYBIND11_TLS_DELETE_VALUE (   key)    PyThread_set_key_value((key), nullptr)

Definition at line 105 of file internals.h.

◆ PYBIND11_TLS_FREE

#define PYBIND11_TLS_FREE (   key)    (void) key

Definition at line 108 of file internals.h.

◆ PYBIND11_TLS_GET_VALUE

#define PYBIND11_TLS_GET_VALUE (   key)    PyThread_get_key_value((key))

Definition at line 92 of file internals.h.

◆ PYBIND11_TLS_KEY_CREATE

#define PYBIND11_TLS_KEY_CREATE (   var)    (((var) = PyThread_create_key()) != -1)

Definition at line 91 of file internals.h.

◆ PYBIND11_TLS_KEY_INIT

#define PYBIND11_TLS_KEY_INIT (   var)    PYBIND11_TLS_KEY_REF var = 0;

Definition at line 90 of file internals.h.

◆ PYBIND11_TLS_KEY_REF

#define PYBIND11_TLS_KEY_REF   decltype(PyThread_create_key())

Definition at line 89 of file internals.h.

◆ PYBIND11_TLS_REPLACE_VALUE

#define PYBIND11_TLS_REPLACE_VALUE (   key,
  value 
)    PyThread_set_key_value((key), (value))

Definition at line 106 of file internals.h.

Typedef Documentation

◆ ExceptionTranslator

using ExceptionTranslator = void (*)(std::exception_ptr)

Definition at line 42 of file internals.h.

◆ type_map

template<typename value_type >
using type_map = std::unordered_map<std::type_index, value_type, type_hash, type_equal_to>

Definition at line 145 of file internals.h.

Function Documentation

◆ c_str()

template<typename... Args>
const char * c_str ( Args &&...  args)

Constructs a std::string with the given arguments, stores it in internals, and returns its c_str().

Such strings objects have a long storage duration – the internal strings are only cleared when the program exits or after interpreter shutdown (when embedding), and so are suitable for c-style strings needed by Python internals (such as PyTypeObject's tp_name).

Definition at line 554 of file internals.h.

References get_internals(), and internals::static_strings.

◆ get_function_record_capsule_name()

const char * get_function_record_capsule_name ( )
inline

Definition at line 560 of file internals.h.

References get_internals().

Referenced by cpp_function::dispatcher(), and is_function_record_capsule().

◆ get_internals()

PYBIND11_NOINLINE internals & get_internals ( )

◆ get_internals_pp()

internals **& get_internals_pp ( )
inline

Each module locally stores a pointer to the internals data.

The data itself is shared among modules with the same PYBIND11_INTERNALS_ID.

Definition at line 312 of file internals.h.

◆ get_local_internals()

local_internals & get_local_internals ( )
inline

Works like get_internals, but for things which are locally registered.

Definition at line 539 of file internals.h.

◆ get_or_create_shared_data()

template<typename T >
T & get_or_create_shared_data ( const std::string &  name)

Returns a typed reference to a shared data entry (by using get_shared_data()) if such entry exists.

Otherwise, a new object of default-constructible type T is added to the shared data under the given name and a reference to it is returned.

Definition at line 600 of file internals.h.

References internals::shared_data.

◆ get_shared_data()

PYBIND11_NOINLINE void * get_shared_data ( const std::string &  name)

Returns a named pointer that is shared among all extension modules (using the same pybind11 version) running in the current interpreter.

Names starting with underscores are reserved for internal usage. Returns nullptr if no matching entry was found.

Definition at line 584 of file internals.h.

References internals::shared_data.

◆ handle_nested_exception()

template<class T , enable_if_t< std::is_same< std::nested_exception, remove_cvref_t< T > >::value, int > = 0>
bool handle_nested_exception ( const T &  exc,
const std::exception_ptr &  p 
)

Definition at line 322 of file internals.h.

References translate_exception().

◆ is_function_record_capsule()

bool is_function_record_capsule ( const capsule cap)
inline

Definition at line 574 of file internals.h.

References get_function_record_capsule_name().

◆ make_default_metaclass()

PyTypeObject * make_default_metaclass ( )
inline

This metaclass is assigned by default to all pybind11 types and is required in order for static properties to function correctly.

Users may override this using py::metaclass. Return value: New reference.

Definition at line 243 of file class.h.

References pybind11_fail(), PYBIND11_FROM_STRING, pybind11_meta_call(), pybind11_meta_dealloc(), pybind11_meta_getattro(), pybind11_meta_setattro(), PYBIND11_SET_OLDPY_QUALNAME, setattr(), and type_incref().

◆ make_object_base_type()

PyObject * make_object_base_type ( PyTypeObject *  metaclass)
inline

Create the type which can be used as a common base for all classes.

This is needed in order to satisfy Python's requirements for multiple inheritance. Return value: New reference.

Definition at line 465 of file class.h.

References error_string(), pybind11_fail(), PYBIND11_FROM_STRING, pybind11_object_dealloc(), pybind11_object_init(), pybind11_object_new(), PYBIND11_SET_OLDPY_QUALNAME, setattr(), and type_incref().

◆ make_static_property_type()

PyTypeObject * make_static_property_type ( )
inline

A static_property is the same as a property but the __get__() and __set__() methods are modified to always use the object type instead of a concrete instance.

Return value: New reference.

Definition at line 61 of file class.h.

References enable_dynamic_attributes(), pybind11_fail(), PYBIND11_FROM_STRING, PYBIND11_SET_OLDPY_QUALNAME, pybind11_static_get(), pybind11_static_set(), setattr(), and type_incref().

◆ raise_err()

bool raise_err ( PyObject *  exc_type,
const char *  msg 
)
inline

Definition at line 340 of file internals.h.

References raise_from().

◆ same_type()

bool same_type ( const std::type_info &  lhs,
const std::type_info &  rhs 
)
inline

Definition at line 122 of file internals.h.

◆ set_shared_data()

PYBIND11_NOINLINE void * set_shared_data ( const std::string &  name,
void *  data 
)

Set the shared data that can be later recovered by get_shared_data().

Definition at line 591 of file internals.h.

References data().

◆ translate_exception()

void translate_exception ( std::exception_ptr  p)
inline

◆ translate_local_exception()

void translate_local_exception ( std::exception_ptr  p)
inline

Definition at line 409 of file internals.h.

References error_already_set::restore().

Variable Documentation

◆ internals_function_record_capsule_name

constexpr const char* internals_function_record_capsule_name = "pybind11_function_record_capsule"
constexpr

Definition at line 46 of file internals.h.