Writing a C extension - borrowed references

Tom Evans tevans.uk at googlemail.com
Tue Mar 20 14:00:35 EDT 2018


On Tue, Mar 20, 2018 at 5:36 PM, Rob Gaddi
<rgaddi at highlandtechnology.invalid> wrote:
> If all you're doing is a thin-wrapper around a C library, have you thought
> about just using ctypes?

Yep; the C library whose API I'm using uses macros to cast things to
the right structure, and (similar to Cython), as I already _have_ the
code, I wasn't particularly interested in working out how to convert
things like:

        LASSO_SAMLP2_NAME_ID_POLICY(LASSO_SAMLP2_AUTHN_REQUEST(
                LASSO_PROFILE(login)->request)->NameIDPolicy
            )->Format = strdup(LASSO_SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT);

into ctypes compatible syntax, when I can simply adapt the working C
code to Python. :)

Plus, there is the library static initialisation to manage, the issues
of distributing the C libraries if I do a C wrapper to call from
ctypes. This way, it can be distributed from our devpi very easily.

Cheers

Tom



More information about the Python-list mailing list