On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood <n...@craig-wood.com> wrote:
Hrvoje Niksic <hnik...@xemacs.org> wrote:
 Nick Craig-Wood <n...@craig-wood.com> writes:

> Here is a ctypes generator listdir for unix-like OSes.

 ctypes code scares me with its duplication of the contents of system
 headers.  I understand its use as a proof of concept, or for hacks one
 needs right now, but can anyone seriously propose using this kind of
 code in a Python program?  For example, this seems much more
 "Linux-only", or possibly even "32-bit-Linux-only", than
 "unix-like":

It was a proof of concept certainly..

It can be done properly with gccxml though which converts structures
into ctypes definitions.

That said the dirent struct is specified by POSIX so if you get the
correct types for all the individual members then it should be correct
everywhere.  Maybe ;-)


The problem is that POSIX specifies the fields with types like off_t and
ino_t.  Since ctypes doesn't know anything about these types, application
code has to specify their size and other attributes.  As these vary from
platform to platform, you can't get it correct without asking a real C
compiler.

In other words, POSIX talks about APIs and ctypes deals with ABIs.

http://pypi.python.org/pypi/ctypes_configure/0.1 helps with the problem,
and is a bit more accessible than gccxml.

It is basically correct to say that using ctypes without using something
like gccxml or ctypes_configure will give you non-portable code.

Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to