[pypy-dev] Re: [pypy-svn] r18792 - in pypy/dist/pypy/translator/c: . src test
tismer at stackless.com
Sun Oct 23 20:12:28 CEST 2005
arigo at codespeak.net wrote:
> C version of opendir/readdir/closedir. Hopefully this works on
> Windows as well -- looking at the CPython posixmodule.c, there is
> a chance that modern Windows have these functions as well, but I
> can't tell for sure.
Unfortunately it has absolutely not. :-(
The semantics are quite a bit different.
First of all, the directory parameter must be augmented with r"\*.*".
I first tried that from ll_os, but it makes all code windows dependent.
Then, there is no plain opendir() equivalent, but only FindFirstFile,
which is like opendir and readdir() in one call.
As a result, I created a DIR structure that holds the windows handle
plus the search structure,and it acts as the dirent structure as well.
The opendir() allocates and returns this structure and sets a flag.
readdir() checks the flag on first call and takes the already existing
resultfrom the structure. Otherwise it behaves as expected.
Implementing this at a higher level would be quite some
trouble AFAICT. At least the current simple model in ros.py would not
fit at all. I'm not sure if we should make these matters more complicated.
Maybe it will be necessary when we support unicode directories.
For now, I just hacked around the needed interface from the C code.
It is not that long. But I would have been happier with less C.
And I'm especially unhappy that I needed to use malloc. But to avoid
this, the opendir() would need to have an interface to pass some
memory in, you would need a call to obtain its needed size, ...
Please let me know if you see a better solution. For now, it works :-)
ciao - chris
Christian Tismer :^) <mailto:tismer at stackless.com>
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
More information about the Pypy-dev