|
|
Subscribe / Log in / New account

C extensions

C extensions

Posted May 16, 2011 2:54 UTC (Mon) by njs (subscriber, #40338)
In reply to: C extensions by kingdon
Parent article: A brief experiment with PyPy

Python has that -- 'ctypes', in the standard library since 2006 -- but that doesn't mean that all existing code uses it. (Nor is it necessarily a great match for extensions that are extending the interpreter in low-level ways, as opposed to just wrapping an existing C library.)


to post comments

C extensions

Posted May 16, 2011 18:33 UTC (Mon) by foom (subscriber, #14868) [Link] (1 responses)

ctypes is not a great way of wrapping a C library either, since it doesn't give you access to the header files, which you need to use if you want portability.

Redefining all the structs/#defines/etc manually in ctypes is a great way to make a completely unportable library wrapper.

C extensions

Posted May 16, 2011 18:54 UTC (Mon) by njs (subscriber, #40338) [Link]

Yeah, it works well for some simpler cases, but that's why I use cython :-).

(Actually, I think most of the times I've used ctypes were to commit horrors by poking at the innards of the interpreter -- casting id(myobj) to a pointer and then screwing with C-level fields. It's not easy to guarantee portability between different implementations of a language!)


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds