Commit c613ded0 authored by Boxiang Sun's avatar Boxiang Sun

Use PyObject_GetDict instead of _PyObject_GetDictPtr

ZODB try to get object's dict and copy it without modification.
Pyston can't provide a writable dict. However, it can provide a
copy of object's dict. So add a new PyObject_GetDict API to return
a copy of object's dict. And let ZODB use this API.
parent 5eeec82d
...@@ -171,13 +171,16 @@ ghostify(cPersistentObject *self) ...@@ -171,13 +171,16 @@ ghostify(cPersistentObject *self)
_estimated_size_in_bytes(self->estimated_size); _estimated_size_in_bytes(self->estimated_size);
ring_del(&self->ring); ring_del(&self->ring);
self->state = cPersistent_GHOST_STATE; self->state = cPersistent_GHOST_STATE;
// Pyston change:
PyObject_ClearDict((PyObject *)self);
#if 0
dictptr = _PyObject_GetDictPtr((PyObject *)self); dictptr = _PyObject_GetDictPtr((PyObject *)self);
if (dictptr && *dictptr) if (dictptr && *dictptr)
{ {
Py_DECREF(*dictptr); Py_DECREF(*dictptr);
*dictptr = NULL; *dictptr = NULL;
} }
#endif
/* We remove the reference to the just ghosted object that the ring /* We remove the reference to the just ghosted object that the ring
* holds. Note that the dictionary of oids->objects has an uncounted * holds. Note that the dictionary of oids->objects has an uncounted
* reference, so if the ring's reference was the only one, this frees * reference, so if the ring's reference was the only one, this frees
...@@ -251,12 +254,15 @@ Per__p_deactivate(cPersistentObject *self) ...@@ -251,12 +254,15 @@ Per__p_deactivate(cPersistentObject *self)
{ {
if (self->state == cPersistent_UPTODATE_STATE && self->jar) if (self->state == cPersistent_UPTODATE_STATE && self->jar)
{ {
PyObject_ClearDict(self);
#if 0
PyObject **dictptr = _PyObject_GetDictPtr((PyObject *)self); PyObject **dictptr = _PyObject_GetDictPtr((PyObject *)self);
if (dictptr && *dictptr) if (dictptr && *dictptr)
{ {
Py_DECREF(*dictptr); Py_DECREF(*dictptr);
*dictptr = NULL; *dictptr = NULL;
} }
#endif
/* Note that we need to set to ghost state unless we are /* Note that we need to set to ghost state unless we are
called directly. Methods that override this need to called directly. Methods that override this need to
do the same! */ do the same! */
...@@ -390,9 +396,19 @@ pickle___getstate__(PyObject *self) ...@@ -390,9 +396,19 @@ pickle___getstate__(PyObject *self)
if (!slotnames) if (!slotnames)
return NULL; return NULL;
/**
* Pyston change: Pyston didn't support _PyObject_GetDictPtr fully
* And will not support it in future
*/
#if 0
dictp = _PyObject_GetDictPtr(self); dictp = _PyObject_GetDictPtr(self);
if (dictp) if (dictp)
state = pickle_copy_dict(*dictp); state = pickle_copy_dict(*dictp);
#endif
PyObject *dict = PyObject_GetDict(self);
if (dict)
state = pickle_copy_dict(dict);
else else
{ {
state = Py_None; state = Py_None;
...@@ -502,6 +518,7 @@ pickle___setstate__(PyObject *self, PyObject *state) ...@@ -502,6 +518,7 @@ pickle___setstate__(PyObject *self, PyObject *state)
{ {
PyObject **dict; PyObject **dict;
#if 0
dict = _PyObject_GetDictPtr(self); dict = _PyObject_GetDictPtr(self);
if (!dict) if (!dict)
...@@ -521,6 +538,9 @@ pickle___setstate__(PyObject *self, PyObject *state) ...@@ -521,6 +538,9 @@ pickle___setstate__(PyObject *self, PyObject *state)
PyDict_Clear(*dict); PyDict_Clear(*dict);
if (PyDict_Update(*dict, state) < 0) if (PyDict_Update(*dict, state) < 0)
return NULL; return NULL;
#endif
PyObject_ClearDict((PyObject*)self);
PyObject_SetDict(self, state);
} }
if (slots && pickle_setattrs_from_dict(self, slots) < 0) if (slots && pickle_setattrs_from_dict(self, slots) < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment