[capi-sig] How to inspect module objects.

Guillaume Yziquel guillaume.yziquel at citycable.ch
Sun Feb 14 22:41:46 CET 2010

M.-A. Lemburg a écrit :
> Some pointers:
> http://docs.python.org/c-api/module.html#PyModule_GetDict
> http://docs.python.org/c-api/dict.html
> The C-API documentation should help you dig further into
> Python objects:
> http://docs.python.org/c-api/index.html

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?

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.

Thoughts welcome.

      Guillaume Yziquel

More information about the capi-sig mailing list