[pypy-dev] ZODB3

Amaury Forgeot d'Arc amauryfa at gmail.com
Wed Mar 21 20:46:41 CET 2012


2012/3/21 Armin Rigo <arigo at tunes.org>:
> On Fri, Mar 2, 2012 at 11:03, Aroldo Souza-Leite <asouzaleite at gmx.de> wrote:
>>    data = self.__dict__.pop('_container')
>> KeyError: '_container'
>
> Last I heard, the Persistent base class, written in C, uses old tricks
> that are kind of deprecated; if I remember correctly, before Python
> 2.2, it was known as the place that introduced the trick called
> "extension classes" to Python, which later became "new-style classes"
> in Python 2.2.

The answer is a bit simpler:
Persistent.__getstate__ uses _PyObject_GetDictPtr(), which always
returns NULL in cpyext.
So the state is None and data is lost.

This function is near to impossible to implement with cpyext.
In the same file (cPersistence.c) you have:
   PyObject **dict = _PyObject_GetDictPtr(self);
   if (!*dict) *dict = PyDict_New();
   PyDict_Update(*dict, state);

This code should probably be rewritten with more conventional API:
PyObject_GetAttrString(self, "__dict__") for example.
Or even with pure Python code.

-- 
Amaury Forgeot d'Arc


More information about the pypy-dev mailing list