FAQ
Hi All,

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? Are there
functions in the python api to deal with the differences? For
example, byte ordering, how is that controlled?


Thanks in advance,

Search Discussions

  • Martin v. Löwis at Nov 14, 2007 at 8:36 am

    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
    PyMODINIT_FUNC macros.

    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.

    Regards,
    Martin
  • Gabriel Genellina at Nov 14, 2007 at 11:13 pm
    En Wed, 14 Nov 2007 05:36:04 -0300, Martin v. L?wis <martin at v.loewis.de>
    escribi?:
    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?#
    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).
    Is there any rules/criteria to decide when to use Py_ssize_t, int, or
    long? I've seen them somewhat mixed and don't know when exactly to use
    Py_ssize_t.

    --
    Gabriel Genellina
  • Martin v. Löwis at Nov 14, 2007 at 11:49 pm

    Is there any rules/criteria to decide when to use Py_ssize_t, int, or
    long? I've seen them somewhat mixed and don't know when exactly to use
    Py_ssize_t.
    You should use Py_ssize_t when you are counting things, and when there
    is no small limit (e.g. 66536) to the maximum number of things you can
    have. More precisely, you should use it if the maximum number of things
    you could possibly have correlates to the available address space.

    Regards,
    Martin
  • Gabriel Genellina at Nov 15, 2007 at 12:39 am
    En Wed, 14 Nov 2007 20:49:35 -0300, Martin v. L?wis <martin at v.loewis.de>
    escribi?:
    Is there any rules/criteria to decide when to use Py_ssize_t, int, or
    long? I've seen them somewhat mixed and don't know when exactly to use
    Py_ssize_t.
    You should use Py_ssize_t when you are counting things, and when there
    is no small limit (e.g. 66536) to the maximum number of things you can
    have. More precisely, you should use it if the maximum number of things
    you could possibly have correlates to the available address space.
    It's perfectly clear now, thanks!

    --
    Gabriel Genellina

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 14, '07 at 1:36a
activeNov 15, '07 at 12:39a
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase