
25 Oct
2010
25 Oct
'10
12:36 p.m.
Nikolaus Rath Nikolaus@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;