[Zope-Checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.6
Jeremy Hylton
jeremy@zope.com
Mon, 24 Jun 2002 15:03:54 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv27742/Persistence
Modified Files:
cPersistence.c
Log Message:
Add _p_delattr(), which is analogous to _p_setattr().
Also, be sure to check for error return from convert_name().
=== Zope3/lib/python/Persistence/cPersistence.c 1.5 => 1.6 ===
name = convert_name(name);
+ if (!name)
+ return NULL;
s_name = PyString_AS_STRING(name);
/* If any attribute other than an _p_ attribute or __dict__ is
accessed, make sure that the object state is loaded.
@@ -610,6 +612,8 @@
int r;
name = convert_name(name);
+ if (!name)
+ return -1;
if (persist_setattr_prep(self, name, value) < 0)
return -1;
@@ -618,22 +622,16 @@
return r;
}
-/* Exported as _p_setattr()
-
- Returns True if the internal persistence machinery handled the setattr.
- Returns False if it did not.
-*/
-
static PyObject *
-persist_p_setattr(PyPersistBaseObject *self, PyObject *args)
+persist_p_set_or_delattr(PyPersistBaseObject *self, PyObject *name,
+ PyObject *value)
{
+ PyObject *res;
int r;
- PyObject *res, *name, *value;
-
- if (!PyArg_ParseTuple(args, "OO:_p_setattr", &name, &value))
- return NULL;
name = convert_name(name);
+ if (!name)
+ return NULL;
r = persist_setattr_prep(self, name, value);
if (r < 0)
return NULL;
@@ -653,6 +651,35 @@
return res;
}
+/* Exported as _p_setattr()
+
+ Returns True if the internal persistence machinery handled the setattr.
+ Returns False if it did not.
+*/
+
+static PyObject *
+persist_p_setattr(PyPersistBaseObject *self, PyObject *args)
+{
+ PyObject *name, *value;
+
+ if (!PyArg_ParseTuple(args, "OO:_p_setattr", &name, &value))
+ return NULL;
+
+ return persist_p_set_or_delattr(self, name, value);
+}
+
+/* Exported as _p_delattr()
+
+ Returns True if the internal persistence machinery handled the setattr.
+ Returns False if it did not.
+*/
+
+static PyObject *
+persist_p_delattr(PyPersistBaseObject *self, PyObject *name)
+{
+ return persist_p_set_or_delattr(self, name, NULL);
+}
+
static void
persist_dealloc(PyPersistObject *self)
{
@@ -706,6 +733,7 @@
{"_p_activate", (PyCFunction)_PyPersist_Load, METH_NOARGS, },
{"_p_deactivate", (PyCFunction)persist_deactivate, METH_NOARGS, },
{"_p_setattr", (PyCFunction)persist_p_setattr, METH_VARARGS, },
+ {"_p_delattr", (PyCFunction)persist_p_delattr, METH_O, },
{NULL}
};
@@ -715,6 +743,7 @@
{"_p_activate", (PyCFunction)_PyPersist_Load, METH_NOARGS, },
{"_p_deactivate", (PyCFunction)persist_deactivate, METH_NOARGS, },
{"_p_setattr", (PyCFunction)persist_p_setattr, METH_VARARGS, },
+ {"_p_delattr", (PyCFunction)persist_p_delattr, METH_O, },
{NULL}
};