cross-platform c questions
"Martin v. Löwis"
martin at v.loewis.de
Wed Nov 14 09:36:04 CET 2007
> When writing a python c extension for needs to be compiled for
> Windows, Linux, and the Mac,
> what cross-platform differences need to be accounted for?#
>From a Python point of view, it's primarily the difference in the
size of types. For example, long may vary across platforms, and
so changes the result value range for PyInt_AsLong.
Another issue is the mechanism to export things from a shared
library; on Windows, you have to use __declspec(export).
Yet another issue the question what basic functions are available
in the system (e.g. whether strdup is available)
> Are there
> functions in the python api to deal with the differences? For
> example, byte ordering, how is that controlled?
Not functions, no, but macros and typedefs. For example, there is
now a typedef Py_ssize_t that you should use if you measure the
number of bytes (or, more generally, things in a collection).
For the __declspec(export) thing, there are the PyAPI_FUNC and
For detecting platform-specific details, autoconf is used,
which defines things like HAVE_STRDUP. autoconf also defines
WORDS_BIGENDIAN if the system uses the bigendian byte order.
More information about the Python-list