[capi-sig] How to inspect module objects.
mal at egenix.com
Mon Feb 15 14:51:54 CET 2010
Guillaume Yziquel wrote:
> M.-A. Lemburg a écrit :
>> Some pointers:
>> The C-API documentation should help you dig further into
>> Python objects:
> Here's a question on which I find little information on the web. About
> First, some quick background about OCaml values: OCaml values are
> essentially of two sorts. There are integers, or integer-like OCaml
> values. And pointers of blocks in the OCaml heap. Both live in the same
> 32-bit or 64-bit type, called "value".
> Blocks in the OCaml heap are aligned, and the lowest 2 or 3 bits of a
> pointer are therefore always nulled. Taking advantage of this, an OCaml
> integer always ends with a lowest bit set to 1. To get the real /
> semantic integer, you just do a >> 1. And therefore OCaml ints are
> stored as 31 bits or 63 bits, depending on your architecture.
> The lowest bit thingy is used for OCaml's garbage collector, in order to
> know whether or not it should follow the value/pointer when doing its
> job traversing the OCaml heap.
> So my question is the following: is there any alignment voodoo in Python
> that would imply that Py_ssize_t values have their lowest bit cleared?
No, Py_ssize_t values can use the full (signed) range provided by
the underlying type. They are used for positive-only values such
as length information as well as positive and negative values
such as indexes. In some cases -1 is used to flag an error for
APIs that normally only return non-negative values.
> If yes, I could map it to an integral OCaml type by adding 1. (The GC
> would not follow the value/pointer). If not, I have no other choice but
> to box the Py_ssize_t value.
Professional Python Services directly from the Source (#1, Feb 15 2010)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the capi-sig