#include "detail/class.h"
#include "detail/init.h"
#include "attr.h"
#include "gil.h"
#include "options.h"
#include <cstdlib>
#include <cstring>
#include <memory>
#include <new>
#include <string>
#include <utility>
#include <vector>
Go to the source code of this file.
Macros | |
#define | PYBIND11_STD_LAUNDER |
#define | PYBIND11_HAS_STD_LAUNDER 0 |
#define | PYBIND11_COMPAT_STRDUP strdup |
#define | PYBIND11_ENUM_OP_STRICT(op, expr, strict_behavior) |
#define | PYBIND11_ENUM_OP_CONV(op, expr) |
#define | PYBIND11_ENUM_OP_CONV_LHS(op, expr) |
#define | PYBIND11_THROW throw type_error("Expected an enumeration of matching type!"); |
#define | PYBIND11_OVERRIDE_IMPL(ret_type, cname, name, ...) |
#define | PYBIND11_OVERRIDE_NAME(ret_type, cname, name, fn, ...) |
\rst Macro to populate the virtual method in the trampoline class. More... | |
#define | PYBIND11_OVERRIDE_PURE_NAME(ret_type, cname, name, fn, ...) |
\rst Macro for pure virtual functions, this function is identical to :c:macro:PYBIND11_OVERRIDE_NAME , except that it throws if no override can be found. More... | |
#define | PYBIND11_OVERRIDE(ret_type, cname, fn, ...) PYBIND11_OVERRIDE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__) |
\rst Macro to populate the virtual method in the trampoline class. More... | |
#define | PYBIND11_OVERRIDE_PURE(ret_type, cname, fn, ...) |
\rst Macro for pure virtual functions, this function is identical to :c:macro:PYBIND11_OVERRIDE , except that it throws if no override can be found. More... | |
#define | PYBIND11_OVERLOAD_INT(ret_type, cname, name, ...) PYBIND11_OVERRIDE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) |
#define | PYBIND11_OVERLOAD_NAME(ret_type, cname, name, fn, ...) PYBIND11_OVERRIDE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, fn, __VA_ARGS__) |
#define | PYBIND11_OVERLOAD_PURE_NAME(ret_type, cname, name, fn, ...) |
#define | PYBIND11_OVERLOAD(ret_type, cname, fn, ...) PYBIND11_OVERRIDE(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), fn, __VA_ARGS__) |
#define | PYBIND11_OVERLOAD_PURE(ret_type, cname, fn, ...) PYBIND11_OVERRIDE_PURE(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), fn, __VA_ARGS__); |
Typedefs | |
using | module = module_ |
template<typename IntLike > | |
using | equivalent_integer_t = typename equivalent_integer< std::is_signed< IntLike >::value, sizeof(IntLike)>::type |
Functions | |
bool | apply_exception_translators (std::forward_list< ExceptionTranslator > &translators) |
dict | globals () |
Return a dictionary representing the global variables in the current execution frame, or __main__.__dict__ if there is no frame (usually when the interpreter is embedded). More... | |
template<typename... Args, typename = detail::enable_if_t<args_are_all_keyword_or_ds<Args...>()>> | |
PYBIND11_DEPRECATED ("make_simple_namespace should be replaced with " "py::module_::import(\"types\").attr(\"SimpleNamespace\") ") object make_simple_namespace(Args &&...args_) | |
template<typename T , typename = void_t<decltype(static_cast<void *(*) (size_t)>(T::operator new))>> | |
void | set_operator_new (type_record *r) |
Set the pointer to operator new if it exists. The cast is needed because it can be overloaded. More... | |
template<typename > | |
void | set_operator_new (...) |
template<typename T , enable_if_t< has_operator_delete< T >::value, int > = 0> | |
void | call_operator_delete (T *p, size_t, size_t) |
Call class-specific delete if it exists or global otherwise. Can also be an overload set. More... | |
void | call_operator_delete (void *p, size_t s, size_t a) |
void | add_class_method (object &cls, const char *name_, const cpp_function &cf) |
template<typename , typename F > | |
auto | method_adaptor (F &&f) -> decltype(std::forward< F >(f)) |
Given a pointer to a member function, cast it to its Derived version. More... | |
template<typename Derived , typename Return , typename Class , typename... Args> | |
auto | method_adaptor (Return(Class::*pmf)(Args...)) -> Return(Derived::*)(Args...) |
template<typename... Args> | |
detail::initimpl::constructor< Args... > | init () |
Binds an existing constructor taking arguments Args... More... | |
template<typename... Args> | |
detail::initimpl::alias_constructor< Args... > | init_alias () |
Like init<Args...>() , but the instance is always constructed through the alias class (even when not inheriting on the Python side). More... | |
template<typename Func , typename Ret = detail::initimpl::factory<Func>> | |
Ret | init (Func &&f) |
Binds a factory function as a constructor. More... | |
template<typename CFunc , typename AFunc , typename Ret = detail::initimpl::factory<CFunc, AFunc>> | |
Ret | init (CFunc &&c, AFunc &&a) |
Dual-argument factory function: the first function is called when no alias is needed, the second when an alias is needed (i.e. More... | |
template<typename GetState , typename SetState > | |
detail::initimpl::pickle_factory< GetState, SetState > | pickle (GetState &&g, SetState &&s) |
Binds pickling functions __getstate__ and __setstate__ and ensures that the type returned by __getstate__ is the same as the argument accepted by __setstate__ . More... | |
str | enum_name (handle arg) |
PYBIND11_NOINLINE void | keep_alive_impl (handle nurse, handle patient) |
PYBIND11_NOINLINE void | keep_alive_impl (size_t Nurse, size_t Patient, function_call &call, handle ret) |
std::pair< decltype(internals::registered_types_py)::iterator, bool > | all_type_info_get_cache (PyTypeObject *type) |
template<typename Access , return_value_policy Policy, typename Iterator , typename Sentinel , typename ValueType , typename... Extra> | |
iterator | make_iterator_impl (Iterator first, Sentinel last, Extra &&...extra) |
template<return_value_policy Policy = return_value_policy::reference_internal, typename Iterator , typename Sentinel , typename ValueType = typename detail::iterator_access<Iterator>::result_type, typename... Extra> | |
iterator | make_iterator (Iterator first, Sentinel last, Extra &&...extra) |
Makes a python iterator from a first and past-the-end C++ InputIterator. More... | |
template<return_value_policy Policy = return_value_policy::reference_internal, typename Iterator , typename Sentinel , typename KeyType = typename detail::iterator_key_access<Iterator>::result_type, typename... Extra> | |
iterator | make_key_iterator (Iterator first, Sentinel last, Extra &&...extra) |
Makes a python iterator over the keys (.first ) of a iterator over pairs from a first and past-the-end InputIterator. More... | |
template<return_value_policy Policy = return_value_policy::reference_internal, typename Iterator , typename Sentinel , typename ValueType = typename detail::iterator_value_access<Iterator>::result_type, typename... Extra> | |
iterator | make_value_iterator (Iterator first, Sentinel last, Extra &&...extra) |
Makes a python iterator over the values (.second ) of a iterator over pairs from a first and past-the-end InputIterator. More... | |
template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra> | |
iterator | make_iterator (Type &value, Extra &&...extra) |
Makes an iterator over values of an stl container or other container supporting std::begin() /std::end() More... | |
template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra> | |
iterator | make_key_iterator (Type &value, Extra &&...extra) |
Makes an iterator over the keys (.first ) of a stl map-like container supporting std::begin() /std::end() More... | |
template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra> | |
iterator | make_value_iterator (Type &value, Extra &&...extra) |
Makes an iterator over the values (.second ) of a stl map-like container supporting std::begin() /std::end() More... | |
template<typename InputType , typename OutputType > | |
void | implicitly_convertible () |
void | register_exception_translator (ExceptionTranslator &&translator) |
void | register_local_exception_translator (ExceptionTranslator &&translator) |
Add a new module-local exception translator. More... | |
template<typename CppException > | |
exception< CppException > & | get_exception_object () |
template<typename CppException > | |
exception< CppException > & | register_exception_impl (handle scope, const char *name, handle base, bool isLocal) |
template<typename CppException > | |
exception< CppException > & | register_exception (handle scope, const char *name, handle base=PyExc_Exception) |
Registers a Python exception in m of the given name and installs a translator to translate the C++ exception to the created Python exception using the what() method. More... | |
template<typename CppException > | |
exception< CppException > & | register_local_exception (handle scope, const char *name, handle base=PyExc_Exception) |
Registers a Python exception in m of the given name and installs a translator to translate the C++ exception to the created Python exception using the what() method. More... | |
PYBIND11_NOINLINE void | print (const tuple &args, const dict &kwargs) |
template<return_value_policy policy = return_value_policy::automatic_reference, typename... Args> | |
void | print (Args &&...args) |
function | get_type_override (const void *this_ptr, const type_info *this_type, const char *name) |
template<class T > | |
function | get_override (const T *this_ptr, const char *name) |
\rst Try to retrieve a python method by the provided name from the instance pointed to by the this_ptr. More... | |
function | get_type_overload (const void *this_ptr, const detail::type_info *this_type, const char *name) |
template<class T > | |
function | get_overload (const T *this_ptr, const char *name) |
#define PYBIND11_COMPAT_STRDUP strdup |
Definition at line 76 of file pybind11.h.
#define PYBIND11_ENUM_OP_CONV | ( | op, | |
expr | |||
) |
#define PYBIND11_ENUM_OP_CONV_LHS | ( | op, | |
expr | |||
) |
#define PYBIND11_ENUM_OP_STRICT | ( | op, | |
expr, | |||
strict_behavior | |||
) |
#define PYBIND11_HAS_STD_LAUNDER 0 |
Definition at line 32 of file pybind11.h.
#define PYBIND11_OVERLOAD | ( | ret_type, | |
cname, | |||
fn, | |||
... | |||
) | PYBIND11_OVERRIDE(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), fn, __VA_ARGS__) |
Definition at line 2877 of file pybind11.h.
#define PYBIND11_OVERLOAD_INT | ( | ret_type, | |
cname, | |||
name, | |||
... | |||
) | PYBIND11_OVERRIDE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) |
Definition at line 2870 of file pybind11.h.
#define PYBIND11_OVERLOAD_NAME | ( | ret_type, | |
cname, | |||
name, | |||
fn, | |||
... | |||
) | PYBIND11_OVERRIDE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, fn, __VA_ARGS__) |
Definition at line 2872 of file pybind11.h.
#define PYBIND11_OVERLOAD_PURE | ( | ret_type, | |
cname, | |||
fn, | |||
... | |||
) | PYBIND11_OVERRIDE_PURE(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), fn, __VA_ARGS__); |
Definition at line 2879 of file pybind11.h.
#define PYBIND11_OVERLOAD_PURE_NAME | ( | ret_type, | |
cname, | |||
name, | |||
fn, | |||
... | |||
) |
Definition at line 2874 of file pybind11.h.
#define PYBIND11_OVERRIDE | ( | ret_type, | |
cname, | |||
fn, | |||
... | |||
) | PYBIND11_OVERRIDE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__) |
\rst Macro to populate the virtual method in the trampoline class.
This macro tries to look up the method from the Python side, deals with the :ref:gil
and necessary argument conversions to call this method and return the appropriate type. This macro should be used if the method name in C and in Python are identical. See :ref:overriding_virtuals
for more information.
.. code-block:: cpp
class PyAnimal : public Animal { public: Inherit the constructors using Animal::Animal;
Trampoline (need one for each virtual function) std::string go(int n_times) override { PYBIND11_OVERRIDE_PURE( std::string, // Return type (ret_type) Animal, // Parent class (cname) go, // Name of function in C++ (must match Python name) (fn) n_times // Argument(s) (...) ); } }; \endrst
Definition at line 2846 of file pybind11.h.
#define PYBIND11_OVERRIDE_IMPL | ( | ret_type, | |
cname, | |||
name, | |||
... | |||
) |
Definition at line 2771 of file pybind11.h.
#define PYBIND11_OVERRIDE_NAME | ( | ret_type, | |
cname, | |||
name, | |||
fn, | |||
... | |||
) |
\rst Macro to populate the virtual method in the trampoline class.
This macro tries to look up a method named 'fn' from the Python side, deals with the :ref:gil
and necessary argument conversions to call this method and return the appropriate type. See :ref:overriding_virtuals
for more information. This macro should be used when the method name in C is not the same as the method name in Python. For example with __str__
.
.. code-block:: cpp
std::string toString() override { PYBIND11_OVERRIDE_NAME( std::string, // Return type (ret_type) Animal, // Parent class (cname) "__str__", // Name of method in Python (name) toString, // Name of function in C++ (fn) ); } \endrst
Definition at line 2804 of file pybind11.h.
#define PYBIND11_OVERRIDE_PURE | ( | ret_type, | |
cname, | |||
fn, | |||
... | |||
) |
\rst Macro for pure virtual functions, this function is identical to :c:macro:PYBIND11_OVERRIDE
, except that it throws if no override can be found.
\endrst
Definition at line 2853 of file pybind11.h.
#define PYBIND11_OVERRIDE_PURE_NAME | ( | ret_type, | |
cname, | |||
name, | |||
fn, | |||
... | |||
) |
\rst Macro for pure virtual functions, this function is identical to :c:macro:PYBIND11_OVERRIDE_NAME
, except that it throws if no override can be found.
\endrst
Definition at line 2814 of file pybind11.h.
#define PYBIND11_STD_LAUNDER |
Definition at line 31 of file pybind11.h.
#define PYBIND11_THROW throw type_error("Expected an enumeration of matching type!"); |
using equivalent_integer_t = typename equivalent_integer<std::is_signed<IntLike>::value, sizeof(IntLike)>::type |
Definition at line 2155 of file pybind11.h.
Definition at line 1275 of file pybind11.h.
|
inline |
Definition at line 1456 of file pybind11.h.
References cpp_function::name().
Referenced by class_< type_, options >::def().
|
inline |
Definition at line 2265 of file pybind11.h.
References handle::dec_ref(), get_internals(), internals::inactive_override_cache, last(), internals::registered_types_py, and object::release().
Referenced by all_type_info().
|
inline |
Definition at line 59 of file pybind11.h.
void call_operator_delete | ( | T * | p, |
size_t | s, | ||
size_t | |||
) |
Call class-specific delete if it exists or global otherwise. Can also be an overload set.
Definition at line 1426 of file pybind11.h.
Definition at line 1436 of file pybind11.h.
Definition at line 1937 of file pybind11.h.
Referenced by enum_base::init().
exception< CppException > & get_exception_object | ( | ) |
Definition at line 2552 of file pybind11.h.
|
inline |
Definition at line 2866 of file pybind11.h.
References get_override().
function get_override | ( | const T * | this_ptr, |
const char * | name | ||
) |
\rst Try to retrieve a python method by the provided name from the instance pointed to by the this_ptr.
:this_ptr: The pointer to the object the overridden method should be retrieved for. This should be the first non-trampoline class encountered in the inheritance chain. :name: The name of the overridden Python method to retrieve. :return: The Python method by this name from the object or an empty function wrapper. \endrst
Definition at line 2766 of file pybind11.h.
|
inline |
Definition at line 2861 of file pybind11.h.
|
inline |
Definition at line 2666 of file pybind11.h.
References dict_getitem(), get_internals(), get_object_handle(), getattr(), type::handle_of(), internals::inactive_override_cache, handle::ptr(), and self.
void implicitly_convertible | ( | ) |
Definition at line 2473 of file pybind11.h.
References handle::ptr(), and pybind11_fail().
detail::initimpl::constructor< Args... > init | ( | ) |
Binds an existing constructor taking arguments Args...
Definition at line 1904 of file pybind11.h.
Referenced by class_< type_, options >::def(), and enum_< Type >::enum_().
Ret init | ( | CFunc && | c, |
AFunc && | a | ||
) |
Dual-argument factory function: the first function is called when no alias is needed, the second when an alias is needed (i.e.
due to python-side inheritance). Arguments must be identical.
Definition at line 1924 of file pybind11.h.
Ret init | ( | Func && | f | ) |
Binds a factory function as a constructor.
Definition at line 1916 of file pybind11.h.
detail::initimpl::alias_constructor< Args... > init_alias | ( | ) |
Like init<Args...>()
, but the instance is always constructed through the alias class (even when not inheriting on the Python side).
Definition at line 1910 of file pybind11.h.
PYBIND11_NOINLINE void keep_alive_impl | ( | handle | nurse, |
handle | patient | ||
) |
Definition at line 2216 of file pybind11.h.
References add_patient(), all_type_info(), handle::dec_ref(), and pybind11_fail().
Referenced by type_caster_generic::cast().
PYBIND11_NOINLINE void keep_alive_impl | ( | size_t | Nurse, |
size_t | Patient, | ||
function_call & | call, | ||
handle | ret | ||
) |
Definition at line 2247 of file pybind11.h.
References function_call::args, function_call::init_self, and keep_alive_impl().
Referenced by process_attribute< keep_alive< Nurse, Patient > >::postcall(), and process_attribute< keep_alive< Nurse, Patient > >::precall().
iterator make_iterator | ( | Iterator | first, |
Sentinel | last, | ||
Extra &&... | extra | ||
) |
Makes a python iterator from a first and past-the-end C++ InputIterator.
Definition at line 2401 of file pybind11.h.
iterator make_iterator | ( | Type & | value, |
Extra &&... | extra | ||
) |
Makes an iterator over values of an stl container or other container supporting std::begin()
/std::end()
Definition at line 2447 of file pybind11.h.
iterator make_iterator_impl | ( | Iterator | first, |
Sentinel | last, | ||
Extra &&... | extra | ||
) |
Definition at line 2364 of file pybind11.h.
References cast(), class_< type_, options >::def(), first(), and last().
iterator make_key_iterator | ( | Iterator | first, |
Sentinel | last, | ||
Extra &&... | extra | ||
) |
Makes a python iterator over the keys (.first
) of a iterator over pairs from a first and past-the-end InputIterator.
Definition at line 2417 of file pybind11.h.
iterator make_key_iterator | ( | Type & | value, |
Extra &&... | extra | ||
) |
Makes an iterator over the keys (.first
) of a stl map-like container supporting std::begin()
/std::end()
Definition at line 2457 of file pybind11.h.
iterator make_value_iterator | ( | Iterator | first, |
Sentinel | last, | ||
Extra &&... | extra | ||
) |
Makes a python iterator over the values (.second
) of a iterator over pairs from a first and past-the-end InputIterator.
Definition at line 2433 of file pybind11.h.
iterator make_value_iterator | ( | Type & | value, |
Extra &&... | extra | ||
) |
Makes an iterator over the values (.second
) of a stl map-like container supporting std::begin()
/std::end()
Definition at line 2467 of file pybind11.h.
auto method_adaptor | ( | F && | f | ) | -> decltype(std::forward<F>(f)) |
Given a pointer to a member function, cast it to its Derived
version.
Forward everything else unchanged.
Definition at line 1468 of file pybind11.h.
auto method_adaptor | ( | Return(Class::*)(Args...) | pmf | ) | -> Return (Derived::*)(Args...) |
Definition at line 1473 of file pybind11.h.
detail::initimpl::pickle_factory< GetState, SetState > pickle | ( | GetState && | g, |
SetState && | s | ||
) |
Binds pickling functions __getstate__
and __setstate__
and ensures that the type returned by __getstate__
is the same as the argument accepted by __setstate__
.
Definition at line 1931 of file pybind11.h.
References pickle().
void print | ( | Args &&... | args | ) |
Definition at line 2645 of file pybind11.h.
PYBIND11_NOINLINE void print | ( | const tuple & | args, |
const dict & | kwargs | ||
) |
Definition at line 2611 of file pybind11.h.
References object::cast(), dict::contains(), module_::import(), and tuple::size().
PYBIND11_DEPRECATED | ( | "make_simple_namespace should be replaced with " "py::module_::import(\"types\").attr(\"SimpleNamespace\") " | ) | && |
Definition at line 1286 of file pybind11.h.
References module_::import().
exception< CppException > & register_exception | ( | handle | scope, |
const char * | name, | ||
handle | base = PyExc_Exception |
||
) |
Registers a Python exception in m
of the given name
and installs a translator to translate the C++ exception to the created Python exception using the what() method.
This is intended for simple exception translations; for more complex translation, register the exception object and translator directly.
Definition at line 2592 of file pybind11.h.
exception< CppException > & register_exception_impl | ( | handle | scope, |
const char * | name, | ||
handle | base, | ||
bool | isLocal | ||
) |
Definition at line 2560 of file pybind11.h.
References register_exception_translator(), and register_local_exception_translator().
|
inline |
Definition at line 2504 of file pybind11.h.
exception< CppException > & register_local_exception | ( | handle | scope, |
const char * | name, | ||
handle | base = PyExc_Exception |
||
) |
Registers a Python exception in m
of the given name
and installs a translator to translate the C++ exception to the created Python exception using the what() method.
This translator will only be used for exceptions that are thrown in this module and will be tried before global exception translators, including those registered with register_exception. This is intended for simple exception translations; for more complex translation, register the exception object and translator directly.
Definition at line 2606 of file pybind11.h.
|
inline |
Add a new module-local exception translator.
Locally registered functions will be tried before any globally registered exception translators, which will only be invoked if the module-local handlers do not deal with the exception.
Definition at line 2515 of file pybind11.h.
void set_operator_new | ( | ... | ) |
Definition at line 1410 of file pybind11.h.
void set_operator_new | ( | type_record * | r | ) |
Set the pointer to operator new if it exists. The cast is needed because it can be overloaded.
Definition at line 1405 of file pybind11.h.
References type_record::operator_new.