μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
internals.h
Go to the documentation of this file.
1/*
2 pybind11/detail/internals.h: Internal data structure and related functions
3
4 Copyright (c) 2017 Wenzel Jakob <wenzel.jakob@epfl.ch>
5
6 All rights reserved. Use of this source code is governed by a
7 BSD-style license that can be found in the LICENSE file.
8*/
9
10#pragma once
11
12#include "../pytypes.h"
13
14#include <exception>
15
30#ifndef PYBIND11_INTERNALS_VERSION
31# define PYBIND11_INTERNALS_VERSION 4
32#endif
33
35
36using ExceptionTranslator = void (*)(std::exception_ptr);
37
39
40// Forward declarations
41inline PyTypeObject *make_static_property_type();
42inline PyTypeObject *make_default_metaclass();
43inline PyObject *make_object_base_type(PyTypeObject *metaclass);
44
45// The old Python Thread Local Storage (TLS) API is deprecated in Python 3.7 in favor of the new
46// Thread Specific Storage (TSS) API.
47#if PY_VERSION_HEX >= 0x03070000
48// Avoid unnecessary allocation of `Py_tss_t`, since we cannot use
49// `Py_LIMITED_API` anyway.
50# if PYBIND11_INTERNALS_VERSION > 4
51# define PYBIND11_TLS_KEY_REF Py_tss_t &
52# ifdef __GNUC__
53// Clang on macOS warns due to `Py_tss_NEEDS_INIT` not specifying an initializer
54// for every field.
55# define PYBIND11_TLS_KEY_INIT(var) \
56 _Pragma("GCC diagnostic push") \
57 _Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") \
58 Py_tss_t var \
59 = Py_tss_NEEDS_INIT; \
60 _Pragma("GCC diagnostic pop")
61# else
62# define PYBIND11_TLS_KEY_INIT(var) Py_tss_t var = Py_tss_NEEDS_INIT;
63# endif
64# define PYBIND11_TLS_KEY_CREATE(var) (PyThread_tss_create(&(var)) == 0)
65# define PYBIND11_TLS_GET_VALUE(key) PyThread_tss_get(&(key))
66# define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_tss_set(&(key), (value))
67# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_tss_set(&(key), nullptr)
68# define PYBIND11_TLS_FREE(key) PyThread_tss_delete(&(key))
69# else
70# define PYBIND11_TLS_KEY_REF Py_tss_t *
71# define PYBIND11_TLS_KEY_INIT(var) Py_tss_t *var = nullptr;
72# define PYBIND11_TLS_KEY_CREATE(var) \
73 (((var) = PyThread_tss_alloc()) != nullptr && (PyThread_tss_create((var)) == 0))
74# define PYBIND11_TLS_GET_VALUE(key) PyThread_tss_get((key))
75# define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_tss_set((key), (value))
76# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_tss_set((key), nullptr)
77# define PYBIND11_TLS_FREE(key) PyThread_tss_free(key)
78# endif
79#else
80// Usually an int but a long on Cygwin64 with Python 3.x
81# define PYBIND11_TLS_KEY_REF decltype(PyThread_create_key())
82# define PYBIND11_TLS_KEY_INIT(var) PYBIND11_TLS_KEY_REF var = 0;
83# define PYBIND11_TLS_KEY_CREATE(var) (((var) = PyThread_create_key()) != -1)
84# define PYBIND11_TLS_GET_VALUE(key) PyThread_get_key_value((key))
85# if PY_MAJOR_VERSION < 3 || defined(PYPY_VERSION)
86// On CPython < 3.4 and on PyPy, `PyThread_set_key_value` strangely does not set
87// the value if it has already been set. Instead, it must first be deleted and
88// then set again.
89inline void tls_replace_value(PYBIND11_TLS_KEY_REF key, void *value) {
90 PyThread_delete_key_value(key);
91 PyThread_set_key_value(key, value);
92}
93# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_delete_key_value(key)
94# define PYBIND11_TLS_REPLACE_VALUE(key, value) \
95 ::pybind11::detail::tls_replace_value((key), (value))
96# else
97# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_set_key_value((key), nullptr)
98# define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_set_key_value((key), (value))
99# endif
100# define PYBIND11_TLS_FREE(key) (void) key
101#endif
102
103// Python loads modules by default with dlopen with the RTLD_LOCAL flag; under libc++ and possibly
104// other STLs, this means `typeid(A)` from one module won't equal `typeid(A)` from another module
105// even when `A` is the same, non-hidden-visibility type (e.g. from a common include). Under
106// libstdc++, this doesn't happen: equality and the type_index hash are based on the type name,
107// which works. If not under a known-good stl, provide our own name-based hash and equality
108// functions that use the type name.
109#if defined(__GLIBCXX__)
110inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) { return lhs == rhs; }
111using type_hash = std::hash<std::type_index>;
112using type_equal_to = std::equal_to<std::type_index>;
113#else
114inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) {
115 return lhs.name() == rhs.name() || std::strcmp(lhs.name(), rhs.name()) == 0;
116}
117
118struct type_hash {
119 size_t operator()(const std::type_index &t) const {
120 size_t hash = 5381;
121 const char *ptr = t.name();
122 while (auto c = static_cast<unsigned char>(*ptr++)) {
123 hash = (hash * 33) ^ c;
124 }
125 return hash;
126 }
127};
128
130 bool operator()(const std::type_index &lhs, const std::type_index &rhs) const {
131 return lhs.name() == rhs.name() || std::strcmp(lhs.name(), rhs.name()) == 0;
132 }
133};
134#endif
135
136template <typename value_type>
137using type_map = std::unordered_map<std::type_index, value_type, type_hash, type_equal_to>;
138
140 inline size_t operator()(const std::pair<const PyObject *, const char *> &v) const {
141 size_t value = std::hash<const void *>()(v.first);
142 value ^= std::hash<const void *>()(v.second) + 0x9e3779b9 + (value << 6) + (value >> 2);
143 return value;
144 }
145};
146
150struct internals {
151 // std::type_index -> pybind11's type information
153 // PyTypeObject* -> base type_info(s)
154 std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py;
155 std::unordered_multimap<const void *, instance *> registered_instances; // void * -> instance*
156 std::unordered_set<std::pair<const PyObject *, const char *>, override_hash>
158 type_map<std::vector<bool (*)(PyObject *, void *&)>> direct_conversions;
159 std::unordered_map<const PyObject *, std::vector<PyObject *>> patients;
160 std::forward_list<ExceptionTranslator> registered_exception_translators;
161 std::unordered_map<std::string, void *> shared_data; // Custom data to be shared across
162 // extensions
163#if PYBIND11_INTERNALS_VERSION == 4
164 std::vector<PyObject *> unused_loader_patient_stack_remove_at_v5;
165#endif
166 std::forward_list<std::string> static_strings; // Stores the std::strings backing
167 // detail::c_str()
168 PyTypeObject *static_property_type;
169 PyTypeObject *default_metaclass;
170 PyObject *instance_base;
171#if defined(WITH_THREAD)
173# if PYBIND11_INTERNALS_VERSION > 4
174 PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
175# endif // PYBIND11_INTERNALS_VERSION > 4
176 PyInterpreterState *istate = nullptr;
177 ~internals() {
178# if PYBIND11_INTERNALS_VERSION > 4
179 PYBIND11_TLS_FREE(loader_life_support_tls_key);
180# endif // PYBIND11_INTERNALS_VERSION > 4
181
182 // This destructor is called *after* Py_Finalize() in finalize_interpreter().
183 // That *SHOULD BE* fine. The following details what happens when PyThread_tss_free is
184 // called. PYBIND11_TLS_FREE is PyThread_tss_free on python 3.7+. On older python, it does
185 // nothing. PyThread_tss_free calls PyThread_tss_delete and PyMem_RawFree.
186 // PyThread_tss_delete just calls TlsFree (on Windows) or pthread_key_delete (on *NIX).
187 // Neither of those have anything to do with CPython internals. PyMem_RawFree *requires*
188 // that the `tstate` be allocated with the CPython allocator.
189 PYBIND11_TLS_FREE(tstate);
190 }
191#endif
192};
193
196struct type_info {
197 PyTypeObject *type;
198 const std::type_info *cpptype;
200 void *(*operator_new)(size_t);
201 void (*init_instance)(instance *, const void *);
203 std::vector<PyObject *(*) (PyObject *, PyTypeObject *)> implicit_conversions;
204 std::vector<std::pair<const std::type_info *, void *(*) (void *)>> implicit_casts;
205 std::vector<bool (*)(PyObject *, void *&)> *direct_conversions;
206 buffer_info *(*get_buffer)(PyObject *, void *) = nullptr;
207 void *get_buffer_data = nullptr;
208 void *(*module_local_load)(PyObject *, const type_info *) = nullptr;
209 /* A simple type never occurs as a (direct or indirect) parent
210 * of a class that makes use of multiple inheritance.
211 * A type can be simple even if it has non-simple ancestors as long as it has no descendants.
212 */
213 bool simple_type : 1;
214 /* True if there is no multiple inheritance in this type's inheritance tree */
216 /* for base vs derived holder_type checks */
218 /* true if this is a type registered with py::module_local */
219 bool module_local : 1;
220};
221
223#if defined(_MSC_VER) && defined(_DEBUG)
224# define PYBIND11_BUILD_TYPE "_debug"
225#else
226# define PYBIND11_BUILD_TYPE ""
227#endif
228
232#ifndef PYBIND11_COMPILER_TYPE
233# if defined(_MSC_VER)
234# define PYBIND11_COMPILER_TYPE "_msvc"
235# elif defined(__INTEL_COMPILER)
236# define PYBIND11_COMPILER_TYPE "_icc"
237# elif defined(__clang__)
238# define PYBIND11_COMPILER_TYPE "_clang"
239# elif defined(__PGI)
240# define PYBIND11_COMPILER_TYPE "_pgi"
241# elif defined(__MINGW32__)
242# define PYBIND11_COMPILER_TYPE "_mingw"
243# elif defined(__CYGWIN__)
244# define PYBIND11_COMPILER_TYPE "_gcc_cygwin"
245# elif defined(__GNUC__)
246# define PYBIND11_COMPILER_TYPE "_gcc"
247# else
248# define PYBIND11_COMPILER_TYPE "_unknown"
249# endif
250#endif
251
253#ifndef PYBIND11_STDLIB
254# if defined(_LIBCPP_VERSION)
255# define PYBIND11_STDLIB "_libcpp"
256# elif defined(__GLIBCXX__) || defined(__GLIBCPP__)
257# define PYBIND11_STDLIB "_libstdcpp"
258# else
259# define PYBIND11_STDLIB ""
260# endif
261#endif
262
264#ifndef PYBIND11_BUILD_ABI
265# if defined(__GXX_ABI_VERSION)
266# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION)
267# else
268# define PYBIND11_BUILD_ABI ""
269# endif
270#endif
271
272#ifndef PYBIND11_INTERNALS_KIND
273# if defined(WITH_THREAD)
274# define PYBIND11_INTERNALS_KIND ""
275# else
276# define PYBIND11_INTERNALS_KIND "_without_thread"
277# endif
278#endif
279
280#define PYBIND11_INTERNALS_ID \
281 "__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
282 PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
283 PYBIND11_BUILD_TYPE "__"
284
285#define PYBIND11_MODULE_LOCAL_ID \
286 "__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
287 PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
288 PYBIND11_BUILD_TYPE "__"
289
293 static internals **internals_pp = nullptr;
294 return internals_pp;
295}
296
297#if PY_VERSION_HEX >= 0x03030000
298// forward decl
299inline void translate_exception(std::exception_ptr);
300
301template <class T,
303bool handle_nested_exception(const T &exc, const std::exception_ptr &p) {
304 std::exception_ptr nested = exc.nested_ptr();
305 if (nested != nullptr && nested != p) {
306 translate_exception(nested);
307 return true;
308 }
309 return false;
310}
311
312template <class T,
314bool handle_nested_exception(const T &exc, const std::exception_ptr &p) {
315 if (const auto *nep = dynamic_cast<const std::nested_exception *>(std::addressof(exc))) {
316 return handle_nested_exception(*nep, p);
317 }
318 return false;
319}
320
321#else
322
323template <class T>
324bool handle_nested_exception(const T &, std::exception_ptr &) {
325 return false;
326}
327#endif
328
329inline bool raise_err(PyObject *exc_type, const char *msg) {
330#if PY_VERSION_HEX >= 0x03030000
331 if (PyErr_Occurred()) {
332 raise_from(exc_type, msg);
333 return true;
334 }
335#endif
336 PyErr_SetString(exc_type, msg);
337 return false;
338}
339
340inline void translate_exception(std::exception_ptr p) {
341 if (!p) {
342 return;
343 }
344 try {
345 std::rethrow_exception(p);
346 } catch (error_already_set &e) {
348 e.restore();
349 return;
350 } catch (const builtin_exception &e) {
351 // Could not use template since it's an abstract class.
352 if (const auto *nep = dynamic_cast<const std::nested_exception *>(std::addressof(e))) {
354 }
355 e.set_error();
356 return;
357 } catch (const std::bad_alloc &e) {
359 raise_err(PyExc_MemoryError, e.what());
360 return;
361 } catch (const std::domain_error &e) {
363 raise_err(PyExc_ValueError, e.what());
364 return;
365 } catch (const std::invalid_argument &e) {
367 raise_err(PyExc_ValueError, e.what());
368 return;
369 } catch (const std::length_error &e) {
371 raise_err(PyExc_ValueError, e.what());
372 return;
373 } catch (const std::out_of_range &e) {
375 raise_err(PyExc_IndexError, e.what());
376 return;
377 } catch (const std::range_error &e) {
379 raise_err(PyExc_ValueError, e.what());
380 return;
381 } catch (const std::overflow_error &e) {
383 raise_err(PyExc_OverflowError, e.what());
384 return;
385 } catch (const std::exception &e) {
387 raise_err(PyExc_RuntimeError, e.what());
388 return;
389 } catch (const std::nested_exception &e) {
391 raise_err(PyExc_RuntimeError, "Caught an unknown nested exception!");
392 return;
393 } catch (...) {
394 raise_err(PyExc_RuntimeError, "Caught an unknown exception!");
395 return;
396 }
397}
398
399#if !defined(__GLIBCXX__)
400inline void translate_local_exception(std::exception_ptr p) {
401 try {
402 if (p) {
403 std::rethrow_exception(p);
404 }
405 } catch (error_already_set &e) {
406 e.restore();
407 return;
408 } catch (const builtin_exception &e) {
409 e.set_error();
410 return;
411 }
412}
413#endif
414
417 auto **&internals_pp = get_internals_pp();
418 if (internals_pp && *internals_pp) {
419 return **internals_pp;
420 }
421
422 // Ensure that the GIL is held since we will need to make Python calls.
423 // Cannot use py::gil_scoped_acquire here since that constructor calls get_internals.
424 struct gil_scoped_acquire_local {
425 gil_scoped_acquire_local() : state(PyGILState_Ensure()) {}
426 ~gil_scoped_acquire_local() { PyGILState_Release(state); }
427 const PyGILState_STATE state;
428 } gil;
429
431 auto builtins = handle(PyEval_GetBuiltins());
432 if (builtins.contains(id) && isinstance<capsule>(builtins[id])) {
433 internals_pp = static_cast<internals **>(capsule(builtins[id]));
434
435 // We loaded builtins through python's builtins, which means that our `error_already_set`
436 // and `builtin_exception` may be different local classes than the ones set up in the
437 // initial exception translator, below, so add another for our local exception classes.
438 //
439 // libstdc++ doesn't require this (types there are identified only by name)
440 // libc++ with CPython doesn't require this (types are explicitly exported)
441 // libc++ with PyPy still need it, awaiting further investigation
442#if !defined(__GLIBCXX__)
444#endif
445 } else {
446 if (!internals_pp) {
447 internals_pp = new internals *();
448 }
449 auto *&internals_ptr = *internals_pp;
450 internals_ptr = new internals();
451#if defined(WITH_THREAD)
452
453# if PY_VERSION_HEX < 0x03090000
454 PyEval_InitThreads();
455# endif
456 PyThreadState *tstate = PyThreadState_Get();
457 if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->tstate)) {
458 pybind11_fail("get_internals: could not successfully initialize the tstate TSS key!");
459 }
460 PYBIND11_TLS_REPLACE_VALUE(internals_ptr->tstate, tstate);
461
462# if PYBIND11_INTERNALS_VERSION > 4
463 if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->loader_life_support_tls_key)) {
464 pybind11_fail("get_internals: could not successfully initialize the "
465 "loader_life_support TSS key!");
466 }
467# endif
468 internals_ptr->istate = tstate->interp;
469#endif
470 builtins[id] = capsule(internals_pp);
471 internals_ptr->registered_exception_translators.push_front(&translate_exception);
472 internals_ptr->static_property_type = make_static_property_type();
473 internals_ptr->default_metaclass = make_default_metaclass();
474 internals_ptr->instance_base = make_object_base_type(internals_ptr->default_metaclass);
475 }
476 return **internals_pp;
477}
478
479// the internals struct (above) is shared between all the modules. local_internals are only
480// for a single module. Any changes made to internals may require an update to
481// PYBIND11_INTERNALS_VERSION, breaking backwards compatibility. local_internals is, by design,
482// restricted to a single module. Whether a module has local internals or not should not
483// impact any other modules, because the only things accessing the local internals is the
484// module that contains them.
487 std::forward_list<ExceptionTranslator> registered_exception_translators;
488#if defined(WITH_THREAD) && PYBIND11_INTERNALS_VERSION == 4
489
490 // For ABI compatibility, we can't store the loader_life_support TLS key in
491 // the `internals` struct directly. Instead, we store it in `shared_data` and
492 // cache a copy in `local_internals`. If we allocated a separate TLS key for
493 // each instance of `local_internals`, we could end up allocating hundreds of
494 // TLS keys if hundreds of different pybind11 modules are loaded (which is a
495 // plausible number).
496 PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
497
498 // Holds the shared TLS key for the loader_life_support stack.
499 struct shared_loader_life_support_data {
500 PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
501 shared_loader_life_support_data() {
502 if (!PYBIND11_TLS_KEY_CREATE(loader_life_support_tls_key)) {
503 pybind11_fail("local_internals: could not successfully initialize the "
504 "loader_life_support TLS key!");
505 }
506 }
507 // We can't help but leak the TLS key, because Python never unloads extension modules.
508 };
509
511 auto &internals = get_internals();
512 // Get or create the `loader_life_support_stack_key`.
513 auto &ptr = internals.shared_data["_life_support"];
514 if (!ptr) {
515 ptr = new shared_loader_life_support_data;
516 }
517 loader_life_support_tls_key
518 = static_cast<shared_loader_life_support_data *>(ptr)->loader_life_support_tls_key;
519 }
520#endif // defined(WITH_THREAD) && PYBIND11_INTERNALS_VERSION == 4
521};
522
525 static local_internals locals;
526 return locals;
527}
528
533template <typename... Args>
534const char *c_str(Args &&...args) {
535 auto &strings = get_internals().static_strings;
536 strings.emplace_front(std::forward<Args>(args)...);
537 return strings.front().c_str();
538}
539
541
542
546 auto &internals = detail::get_internals();
547 auto it = internals.shared_data.find(name);
548 return it != internals.shared_data.end() ? it->second : nullptr;
549}
550
552PYBIND11_NOINLINE void *set_shared_data(const std::string &name, void *data) {
553 detail::get_internals().shared_data[name] = data;
554 return data;
555}
556
560template <typename T>
561T &get_or_create_shared_data(const std::string &name) {
562 auto &internals = detail::get_internals();
563 auto it = internals.shared_data.find(name);
564 T *ptr = (T *) (it != internals.shared_data.end() ? it->second : nullptr);
565 if (!ptr) {
566 ptr = new T();
568 }
569 return *ptr;
570}
571
Definition: pytypes.h:1776
C++ bindings of builtin Python exceptions.
Definition: common.h:961
Fetch and hold an error which was already set in Python.
Definition: pytypes.h:379
void restore()
Give the currently-held error back to Python, if any.
Definition: pytypes.h:395
const char * what() const noexcept override
The what() result is built lazily on demand.
Definition: pybind11.h:2657
\rst Holds a reference to a Python object (no reference counting)
Definition: pytypes.h:194
ssize_t hash(handle obj)
Definition: pytypes.h:581
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: common.h:625
PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Thrown when pybind11::cast or.
Definition: common.h:992
#define PYBIND11_NOINLINE
Definition: common.h:129
#define PYBIND11_STR_TYPE
Definition: common.h:320
std::size_t size_t
Definition: common.h:461
#define PYBIND11_NAMESPACE_END(name)
Definition: common.h:21
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: common.h:20
#define PYBIND11_TLS_KEY_INIT(var)
Definition: internals.h:82
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.
Definition: internals.h:561
std::unordered_map< std::type_index, value_type, type_hash, type_equal_to > type_map
Definition: internals.h:137
internals **& get_internals_pp()
Each module locally stores a pointer to the internals data.
Definition: internals.h:292
bool handle_nested_exception(const T &, std::exception_ptr &)
Definition: internals.h:324
PyTypeObject * make_default_metaclass()
This metaclass is assigned by default to all pybind11 types and is required in order for static prope...
Definition: class.h:243
PyObject * make_object_base_type(PyTypeObject *metaclass)
Create the type which can be used as a common base for all classes.
Definition: class.h:465
void tls_replace_value(PYBIND11_TLS_KEY_REF key, void *value)
Definition: internals.h:89
bool raise_err(PyObject *exc_type, const char *msg)
Definition: internals.h:329
#define PYBIND11_TLS_KEY_REF
Definition: internals.h:81
void(*)(std::exception_ptr) ExceptionTranslator
Definition: internals.h:36
PYBIND11_NOINLINE internals & get_internals()
Return a reference to the current internals data.
Definition: internals.h:416
PyTypeObject * make_static_property_type()
A static_property is the same as a property but the __get__() and __set__() methods are modified to a...
Definition: class.h:61
void translate_local_exception(std::exception_ptr p)
Definition: internals.h:400
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: internals.h:552
void translate_exception(std::exception_ptr p)
Definition: internals.h:340
#define PYBIND11_TLS_REPLACE_VALUE(key, value)
Definition: internals.h:94
#define PYBIND11_INTERNALS_ID
Definition: internals.h:280
#define PYBIND11_TLS_KEY_CREATE(var)
Definition: internals.h:83
const char * c_str(Args &&...args)
Constructs a std::string with the given arguments, stores it in internals, and returns its c_str().
Definition: internals.h:534
local_internals & get_local_internals()
Works like get_internals, but for things which are locally registered.
Definition: internals.h:524
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) ...
Definition: internals.h:545
bool same_type(const std::type_info &lhs, const std::type_info &rhs)
Definition: internals.h:114
arr data(const arr &a, Ix... index)
#define PYBIND11_TLS_KEY_INIT(var)
Definition: internals.h:90
#define PYBIND11_TLS_FREE(key)
Definition: internals.h:108
std::unordered_map< std::type_index, value_type, type_hash, type_equal_to > type_map
Definition: internals.h:145
PYBIND11_NOINLINE internals & get_internals()
Return a reference to the current internals data.
Definition: internals.h:425
void raise_from(PyObject *type, const char *message)
Replaces the current Python error indicator with the chosen error, performing a 'raise from' to indic...
Definition: pytypes.h:721
Information record describing a Python buffer object.
Definition: buffer_info.h:43
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Definition: common.h:554
Internal data structure used to track registered instances and types.
Definition: internals.h:150
type_map< type_info * > registered_types_cpp
Definition: internals.h:152
std::unordered_map< std::string, void * > shared_data
Definition: internals.h:161
std::unordered_multimap< const void *, instance * > registered_instances
Definition: internals.h:155
std::unordered_map< const PyObject *, std::vector< PyObject * > > patients
Definition: internals.h:159
std::unordered_map< PyTypeObject *, std::vector< type_info * > > registered_types_py
Definition: internals.h:154
PyTypeObject * static_property_type
Definition: internals.h:168
type_map< std::vector< bool(*)(PyObject *, void *&)> > direct_conversions
Definition: internals.h:158
PyTypeObject * default_metaclass
Definition: internals.h:169
PyObject * instance_base
Definition: internals.h:170
std::forward_list< ExceptionTranslator > registered_exception_translators
Definition: internals.h:160
std::forward_list< std::string > static_strings
Definition: internals.h:166
std::unordered_set< std::pair< const PyObject *, const char * >, override_hash > inactive_override_cache
Definition: internals.h:157
type_map< type_info * > registered_types_cpp
Definition: internals.h:486
std::forward_list< ExceptionTranslator > registered_exception_translators
Definition: internals.h:487
Annotation which requests that a special metaclass is created for a type.
Definition: attr.h:81
Annotation for function names.
Definition: attr.h:47
size_t operator()(const std::pair< const PyObject *, const char * > &v) const
Definition: internals.h:140
bool operator()(const std::type_index &lhs, const std::type_index &rhs) const
Definition: internals.h:130
size_t operator()(const std::type_index &t) const
Definition: internals.h:119
Additional type information which does not fit into the PyTypeObject.
Definition: internals.h:196
std::vector< std::pair< const std::type_info *, void *(*)(void *)> > implicit_casts
Definition: internals.h:204
bool simple_type
Definition: internals.h:213
void(* dealloc)(value_and_holder &v_h)
Definition: internals.h:202
size_t holder_size_in_ptrs
Definition: internals.h:199
size_t type_size
Definition: internals.h:199
const std::type_info * cpptype
Definition: internals.h:198
void(* init_instance)(instance *, const void *)
Definition: internals.h:201
std::vector< bool(*)(PyObject *, void *&)> * direct_conversions
Definition: internals.h:205
bool module_local
Definition: internals.h:219
bool simple_ancestors
Definition: internals.h:215
size_t type_align
Definition: internals.h:199
std::vector< PyObject *(*)(PyObject *, PyTypeObject *)> implicit_conversions
Definition: internals.h:203
void * get_buffer_data
Definition: internals.h:207
PyTypeObject * type
Definition: internals.h:197
bool default_holder
Definition: internals.h:217