Binary python extensions with Free Pascal Compiler

C

Caleb Hattingh

Hi all

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.

Regards
Caleb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top