Binary python extensions with Free Pascal Compiler
caleb.hattingh at gmail.com
Thu Mar 16 21:49:03 CET 2006
I want to write python extensions with FPC (Free Pascal Compiler,
http://www.freepascal.org). In Delphi, this is trivially easy due to
the great work of the P4D (Python-for-Delphi, http://mmm-experts.com/)
guys; however, when aiming for cross-platform binary extensions, that
strategy naturally doesn't work.
FPC has great cross-platform support, and to date I have written
library units that compile to .dlls (on win32) and .so's (on posix),
and then used these via ctypes. This has worked very well, but for
certain applications I would prefer to create a new python type via
binary extension, rather than a python class with method wrappers
around library calls. I could just use C, I guess, but I have a large
amount of pascal code that I would like to use, and I would prefer not
to fiddle with a C-binary extension intermediate.
I have explored the python.h header, and as expected, there appears to
be much use of the C standard library. Using a tool that converts a C
header into an object pascal unit (intended to be the interface to
python.dll) gets me some of the way, but of course, calls to the C
stdlib don't get automatically translated into equivalent pascal-coded
functionality. I'm afraid I am answering my own question here: is the
only way of getting this working to change all the stdlib calls in my
newly created pascal unit (created from python.h) to matching
functionality in pascal?
If there is another, simpler way I'm just not seeing, I would be glad
to hear it.
More information about the Python-list