This presentation aims to show how libraries like Python PIL, ScyPy, NumPy do interfaces with C libraries. Python allows this communication natively. We’ll see the concepts, the Python compiler resources, code API and some code examples.
performance (Scipy) ❖ Don't want to recreate mature a stable C libraries (PIL) ❖ Get control over the memory allocation (embedded systems) ❖ Embed Python in some application (GoDot game engine)
Used by modules ➢ _Py - Internal Python interpreter use https://docs.python.org/3/c-api/intro.html ❖ Avoid using those prefixes ➢ Confuses the Interpreter ➢ Legibility ➢ Conflicts in future versions of Python
object ➢ Every Python object pointer can best cast to a PyObject ❖ Most python objects are allocated in the Heap ➢ Pymalloc != malloc static PyObject * https://docs.python.org/3/c-api/module.html
name called by Python */ PyCFunction ml_meth; /* Function reference */ int ml_flags; /* Function parameters type */ char *ml_doc; /* Function description */ }; https://docs.python.org/3/c-api/structures.html#c.PyMethodDef
l d .text 0000000000000000 .text 0000000000000690 l F .text 0000000000000000 deregister_tm_clones 00000000000006d0 l F .text 0000000000000000 register_tm_clones 0000000000000720 l F .text 0000000000000000 __do_global_dtors_aux 0000000000000760 l F .text 0000000000000000 frame_dummy 0000000000000790 l F .text 0000000000000015 hello 00000000000007b0 g F .text 000000000000001d initmodule $> man objdump