These macros handle module initialization, injection, and extension module creation.
They manage the Python module lifecycle from creation to registration with the Python interpreter.
If you're building a Python extension module (a .pyd or .so file), you will typically use the entrypoint macros to create the required PyInit_* function that Python calls:
The injection macros are more low-level and can be used to create modules at runtime to be registered with an embedded Python interpreter.
Macros | |
| #define | PY_MODULE_ENTRYPOINT_NAME(i_module, i_name) |
Create a PyInit_* Python module initialization function with custom name. | |
| #define | PY_MODULE_ENTRYPOINT(i_module) |
| Create a Python module initialization function using the module identifier as the name. | |
| #define | PY_INJECT_MODULE(i_module) |
| Inject a Python module so Python becomes aware of it. | |
| #define | PY_INJECT_MODULE_EX(i_module, s_moduleName, s_doc) |
| Inject a module with name and documentation override. | |
| #define | PY_INJECT_MODULE_NAME(i_module, s_moduleName) |
| Inject a module with name override. | |
| #define | PY_INJECT_MODULE_DOC(i_module, s_doc) |
| Inject a module with documentation override. | |
| #define | PY_EXTENSION_MODULE_EX(i_module, f_injection, s_doc) |
| Inject a python module so Python is aware of it and produce all necessary code so a module can be used as extension of Python. | |
| #define | PY_EXTENSION_MODULE_DOC(i_module, f_injection, s_doc) |
| Create an extension module with documentation. | |
| #define | PY_EXTENSION_MODULE(i_module, f_injection) |
| Create an extension module (no documentation). | |
| #define PY_MODULE_ENTRYPOINT_NAME | ( | i_module, | |
| i_name ) |
Create a PyInit_* Python module initialization function with custom name.
Generates the PyInit_* function required for Python extension modules. This function will be called by Python when the module is imported.
| i_module | Module identifier declared with PY_DECLARE_MODULE_* |
| i_name | Name for the initialization function (PyInit_<i_name> will be generated) Must be the same as your modoule name |
Definition at line 288 of file pyobject_macros.h.
| #define PY_MODULE_ENTRYPOINT | ( | i_module | ) |
Create a Python module initialization function using the module identifier as the name.
Wraps PY_MODULE_ENTRYPOINT_NAME() with i_name = i_module.
| i_module | Module identifier (used for both module reference and function name) |
Definition at line 305 of file pyobject_macros.h.
| #define PY_INJECT_MODULE | ( | i_module | ) |
Inject a Python module so Python becomes aware of it.
Creates the actual Python module object with all accumulated definitions (functions, classes, enums, constants). This should be done at runtime, typically in your main() function or during Python initialization.
| i_module | Module identifier declared by PY_DECLARE_MODULE_* |
nullptr on error (with Python exception set)Definition at line 333 of file pyobject_macros.h.
| #define PY_INJECT_MODULE_EX | ( | i_module, | |
| s_moduleName, | |||
| s_doc ) |
Inject a module with name and documentation override.
Definition at line 341 of file pyobject_macros.h.
| #define PY_INJECT_MODULE_NAME | ( | i_module, | |
| s_moduleName ) |
Inject a module with name override.
Definition at line 351 of file pyobject_macros.h.
| #define PY_INJECT_MODULE_DOC | ( | i_module, | |
| s_doc ) |
Inject a module with documentation override.
Definition at line 360 of file pyobject_macros.h.
| #define PY_EXTENSION_MODULE_EX | ( | i_module, | |
| f_injection, | |||
| s_doc ) |
Inject a python module so Python is aware of it and produce all necessary code so a module can be used as extension of Python.
A limitation in comparison with embedded modules is that the name of the module cannot be changed anymore upon injection.
| i_module | the identifier of a module declared by PY_DECLARE_MODULE |
| f_injection | the function that will inject all the classes for this module |
| s_doc | documentation of module as shown in Python (zero terminated C string) |
Definition at line 378 of file pyobject_macros.h.
| #define PY_EXTENSION_MODULE_DOC | ( | i_module, | |
| f_injection, | |||
| s_doc ) |
Create an extension module with documentation.
Wraps PY_EXTENSION_MODULE_EX() with s_doc parameter.
| i_module | Module identifier declared by PY_DECLARE_MODULE_*() |
| f_injection | Injection function to call during module creation |
| s_doc | Module documentation string (const char* string with static storage duration) |
Definition at line 393 of file pyobject_macros.h.
| #define PY_EXTENSION_MODULE | ( | i_module, | |
| f_injection ) |
Create an extension module (no documentation).
Wraps PY_EXTENSION_MODULE_EX() with s_doc = nullptr.
| i_module | Module identifier declared by PY_DECLARE_MODULE_*() |
| f_injection | Injection function to call during module creation |
Definition at line 403 of file pyobject_macros.h.