[Python-3000] Ctypes as cross-interpreter C calling interface

"Martin v. Löwis" martin at v.loewis.de
Sun Aug 20 23:10:41 CEST 2006

Paul Prescod schrieb:
> Thanks for everyone who contributed. It seems that the emerging
> consensus (bar a security question from Guido) is that ctypes it the way
> forward for calling C code in Python 3000. 

I don't think that can ever work (so I don't participate in that
consensus). There are too many issues with C that make ctypes not
general enough.
a) it requires code to be packaged in a DLL; static libraries
   are not supported (conceptually)
b) it requires you to know the layout of data structures, or
   atleast to duplicate declarations in Python. As the layout
   of the same structure may change over time or across
   implementations (e.g. FILE in stdio), you can never get good
   platform coverage.
c) A good deal of C API is through macros, for various usages
   (symbolic constants, function inlining,
    customization/configuration/conditional compilation)
d) No real support for C++ (where there are even more ABI
   issues: (multiple) inheritance, vtables, constructors,
   operator overload, templates, ...)

To access a C API, the only "right" way is to use a C compiler.
ctypes is for people who want to avoid using a C compiler at
all costs.


More information about the Python-3000 mailing list