[Zodb-checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.1.2.9
Jeremy Hylton
jeremy@zope.com
Thu, 21 Feb 2002 16:33:32 -0500
Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv13518/lib/python/Persistence
Modified Files:
Tag: Zope-3x-branch
cPersistence.c
Log Message:
A bunch of bug fixes uncovered by BTrees testing.
In persist_getstate(), ignore _v_ and _p_ attributes. I'm not sure
that ignoring _p_ attrs is right, but the tests still pass.
Check return value of _PyObject_GetDictPtr() to see if it's NULL.
Add __safe_for_unpickling attribute, which seems to be necessary to
unpickle BTrees objects.
Add Py_TPFLAGS_HEAPTYPE to Persistent tp_flags!
=== Zope3/lib/python/Persistence/cPersistence.c 1.1.2.8 => 1.1.2.9 ===
if (strncmp(attrname, "_v_", 3) == 0)
continue;
+ /* XXX Should I ignore _p_ too? */
+ if (strncmp(attrname, "_p_", 3) == 0)
+ continue;
}
if (PyDict_SetItem(state, k, v) < 0) {
Py_DECREF(state);
@@ -242,7 +245,7 @@
return NULL;
}
dict = *pdict;
-
+
if (PyDict_Check(state)) {
PyObject *k, *v;
int pos = 0;
@@ -310,7 +313,7 @@
{
if (self->po_state == UPTODATE && self->po_dm) {
PyObject **pdict = _PyObject_GetDictPtr((PyObject *)self);
- if (*pdict) {
+ if (pdict && *pdict) {
/* Would prefer to free the dict, but need to extend other parts of
the implementation to check for the dict's existence.
*/
@@ -423,9 +426,19 @@
return self->po_dict;
}
+static PyObject *
+persist_safe(PyPersistObject *self)
+{
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
static PyGetSetDef persist_getsets[] = {
{"_p_changed", (getter)persist_get_state, (setter)persist_set_state},
{"__dict__", (getter)persist_get_dict},
+
+ /* XXX This seems to be necessary for unpickling via reduce. */
+ {"__safe_for_unpickling__", (getter)persist_safe},
{NULL}
};
@@ -637,7 +650,7 @@
(getattrofunc)persist_getattro, /* tp_getattro */
(setattrofunc)persist_setattro, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HEAPTYPE |
Py_TPFLAGS_BASETYPE, /* tp_flags */
0, /* tp_doc */
(traverseproc)persist_traverse, /* tp_traverse */