waling a directory with very many files

Jean-Paul Calderone exarkun at divmod.com
Mon Jun 15 10:38:44 EDT 2009


On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood <nick at craig-wood.com> wrote:
>Hrvoje Niksic <hniksic at xemacs.org> wrote:
>>  Nick Craig-Wood <nick at 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



More information about the Python-list mailing list