Suppose given a C extension module that internally defines a variety of useful functions that can be exported as a public C API for use elsewhere. Now if we want to use these functions inside other extension modules. Then, it is important to know how to link them together but doing it with the C compiler/linker seems excessively complicated.
Code #1 : [C code] Point objects including some utility functions
Now, the issue to deal with is how to handle the exportation of the
PyPoint_FromPoint() functions as an API that can be used by and can link to other extension modules. (For example – any other extensions also want to use the wrapped Point objects).
Code #2 : Introducing a new header file called
Pythonsample.h for the
Code #3 : Import the API table from “work”
_PointAPIMethods table of function pointers is the most important feature as it will be initialized in the exporting module and found by importing modules. The code below shows how to change the original extension module to populate the table and export it.
Code #4 : Destructor and Utility Function
Code #5 : Module function
- C Extension Module using Python
- C API from Extension Module in Python | Set 2
- Python | Passing Filenames to Extension in C
- Python | Sort and store files with same extension
- Python | Opaque Pointers in C extension modules
- Python | Repeat and Multiply list extension
- Python | Extension function operating on Arrays
- pwd module in Python
- grp module in Python
- Python | Calendar Module
- Python winsound module
- Fraction module in Python
- Python Urllib Module
- Keyboard module in Python
- Pygorithm module in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.