[capi-sig] What can I do without GIL?

Hrvoje Niksic hniksic at xemacs.org
Mon Oct 25 12:36:16 CEST 2010


Nikolaus Rath <Nikolaus at rath.org> writes:

> I'd like to follow up with another question directly: if I call
> PyBytes_AsString() on a Python object (and keep a reference to that
> object), can I rely on the char* to stay valid when I am releasing the
> GIL?
[...]
> Is this a problem with Python as well, or can I rely on the string
> staying at the same memory location all the time?

CPython string data is stored inside the PyStringObject structure, so it
is pretty much guaranteed to be immovable in the current implementation.

typedef struct {
    PyObject_VAR_HEAD
    long ob_shash;
    int ob_sstate;
    char ob_sval[1];    // PyString_AS_STRING returns pointer to this member
} PyStringObject;


More information about the capi-sig mailing list