Summary
In this chapter, you learned the most important aspects of writing code that uses ctypes
, CFFI
, and how to extend the Python functionality using native C. These topics can be extensive enough to fill books on their own, but you should have a grasp of the most important topics now. Even though you are able to create C/C++ extensions now, I still recommend that you avoid these as much as possible. This is because bugs are so easily made by not being careful enough. It is actually likely that at least some of the examples given in this chapter contain bugs when it comes to memory management and can crash your Python interpreter when given the wrong input. Unfortunately, this is a side effect of C. A tiny mistake can have a huge impact.
While building the examples in this chapter, you may have noticed that we used a setup.py
file and imported from the setuptools
library. This is what the next chapter will cover—packaging your code into an installable Python library and distributing...