[MERGE] DirState pyrex helpers
John Arbash Meinel
john at arbash-meinel.com
Thu Jul 19 16:32:19 BST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Matthew D. Fuller wrote:
> On Wed, Jul 18, 2007 at 03:34:05PM -0500 I heard the voice of
> John Arbash Meinel, and lo! it spake thus:
>> I've tried to track down an "official" definition, but GNU seems to
>> have it as part of the compiler. I see stuff like:
>
> It's almost certainly in header files somewhere, but it may take some
> tracking down.
>
> FreeBSD/i386 has:
> typedef __uint32_t __size_t; /* sizeof() */
>
> FreeBSD/amd64 has:
> typedef __uint64_t __size_t; /* sizeof() */
>
> (size_t becomes defined in terms of __size_t)
>
>
> A Fedora/i386 box I can see has it defined back to unsigned int.
>
>
> Certainly it's neither int nor long (it's size_t, after all), but it
> should be able to hold the size of the largest possible
> continuously-addressable block of memory. On any currently-sane
> platform, unsigned long would probably work. Would be nice if it
> could just learn it from the system headers and DTRT up the stack into
> python...
It generally does. Looking here:
http://www.python.org/doc/current/api/intObjects.html
There is, in fact, a PyInt_FromSsize_t, and PyInt_AsSsize_t. But they are
introduced in python2.5, and are for 'ssize_t' the signed form of size_t.
There are also the PyLong functions:
http://www.python.org/doc/current/api/longObjects.html
Which include things like PyLong_FromUnsignedLong, and
PyLong_FromUnsignedLongLong. (At least I thought gcc+amd64 went with unsigned
long == 32bits, unsigned long long == 64bits).
The problem with all of these, is that we generally really want to be using
PyInt, because it is a bit faster (but can only represent a signed 32-bit integer).
As I said earlier, though, the generated C code uses a 'size_t' for the
variables that need it, so it is passed around correctly.
For example doing:
cdef typedef int size_t
def foo(x):
cdef size_t my_size
my_size = x
Would probably generate:
size_t __pyx_v_mysize;
__pyx_v_mysize = PyInt_AsLong(x)
If we changed the typedef to 'typedef unsigned long size_t'
you would probably get:
__pyx_v_mysize = PyInt_AsUnsignedLongMask(x)
And for the sizes we are dealing with, all of them are equivalent. (Since we
shouldn't be operating in anything that is >2GB. I would guess everything is
actually <1k in fact. I think most lines are around 200 bytes.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGn4QDJdeBCYSNAAMRAjxZAKCSwfPaI5zedGR/Xv25E05r4ABeAgCeJdVc
O8RNZ6UmrPx0+2Cdsr+FiqE=
=8YQu
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list