[Zodb-checkins] CVS: ZODB3/Persistence - cPersistence.c:1.72.8.9
Jeremy Hylton
jeremy at zope.com
Thu Jul 3 15:19:17 EDT 2003
Update of /cvs-repository/ZODB3/Persistence
In directory cvs.zope.org:/tmp/cvs-serv27311/Persistence
Modified Files:
Tag: zodb33-devel-branch
cPersistence.c
Log Message:
Implement _p_changed and _p_serial using getsets.
=== ZODB3/Persistence/cPersistence.c 1.72.8.8 => 1.72.8.9 ===
--- ZODB3/Persistence/cPersistence.c:1.72.8.8 Thu Jul 3 13:25:11 2003
+++ ZODB3/Persistence/cPersistence.c Thu Jul 3 14:19:11 2003
@@ -454,21 +454,7 @@
if (*n++=='p' && *n++=='_') {
switch(*n++)
{
- case 'c':
- if (strcmp(n,"hanged")==0)
- {
- if (self->state < 0)
- {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return PyInt_FromLong(self->state ==
- cPersistent_CHANGED_STATE);
- }
- break;
case 's':
- if (strcmp(n,"erial")==0)
- return PyString_FromStringAndSize(self->serial, 8);
if (strcmp(n,"elf")==0)
return orNothing((PyObject *)self);
break;
@@ -549,66 +535,6 @@
return -1;
if (*name == '_' && name[1] == 'p' && name[2] == '_') {
- if (strcmp(name + 3, "serial") == 0) {
- if (v) {
- if (PyString_Check(v) && PyString_GET_SIZE(v) == 8)
- memcpy(self->serial, PyString_AS_STRING(v), 8);
- else {
- PyErr_SetString(PyExc_ValueError,
- "_p_serial must be an 8-character string");
- return -1;
- }
- } else
- memset(self->serial, 0, 8);
- return 0;
- }
- else if (strcmp(name+3, "changed") == 0) {
- int deactivate = 0;
- if (!v)
- {
- /* delatter is used to invalidate the object
- *even* if it has changed.
- */
- if (self->state != cPersistent_GHOST_STATE)
- self->state = cPersistent_UPTODATE_STATE;
- deactivate = 1;
- }
- else if (v == Py_None)
- deactivate = 1;
- if (deactivate)
- {
- PyObject *res, *meth;
- meth = PyObject_GetAttr((PyObject *)self, py__p_deactivate);
- if (meth == NULL)
- return -1;
- res = PyObject_CallObject(meth, NULL);
- if (res) {
- Py_DECREF(res);
- }
- else {
- /* an error occured in _p_deactivate().
-
- It's not clear what we should do here. The code is
- obviously ignoring the exception, but it shouldn't
- return 0 for a getattr and set an exception. The
- simplest change is to clear the exception, but that
- simply masks the error.
-
- XXX We'll print an error to stderr just like
- exceptions in __del__(). It would probably be
- better to log it but that would be painful from C.
- */
- PyErr_WriteUnraisable(meth);
- }
- Py_DECREF(meth);
- return 0;
- }
- if (PyObject_IsTrue(v))
- return changed(self);
- if (self->state >= 0)
- self->state=cPersistent_UPTODATE_STATE;
- return 0;
- }
}
else
{
@@ -685,6 +611,66 @@
*/
static PyObject *
+Per_get_changed(cPersistentObject *self)
+{
+ if (self->state < 0) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyInt_FromLong(self->state == cPersistent_CHANGED_STATE);
+}
+
+static int
+Per_set_changed(cPersistentObject *self, PyObject *v)
+{
+ int deactivate = 0, true;
+ if (!v) {
+ /* delattr is used to invalidate an object *even* if it has changed. */
+ if (self->state != cPersistent_GHOST_STATE)
+ self->state = cPersistent_UPTODATE_STATE;
+ deactivate = 1;
+ }
+ else if (v == Py_None)
+ deactivate = 1;
+
+ if (deactivate) {
+ PyObject *res, *meth;
+ meth = PyObject_GetAttr((PyObject *)self, py__p_deactivate);
+ if (meth == NULL)
+ return -1;
+ res = PyObject_CallObject(meth, NULL);
+ if (res)
+ Py_DECREF(res);
+ else {
+ /* an error occured in _p_deactivate().
+
+ It's not clear what we should do here. The code is
+ obviously ignoring the exception, but it shouldn't return
+ 0 for a getattr and set an exception. The simplest change
+ is to clear the exception, but that simply masks the
+ error.
+
+ XXX We'll print an error to stderr just like exceptions in
+ __del__(). It would probably be better to log it but that
+ would be painful from C.
+ */
+ PyErr_WriteUnraisable(meth);
+ }
+ Py_DECREF(meth);
+ return 0;
+ }
+ true = PyObject_IsTrue(v);
+ if (true == -1)
+ return -1;
+ else if (true)
+ return changed(self);
+
+ if (self->state >= 0)
+ self->state = cPersistent_UPTODATE_STATE;
+ return 0;
+}
+
+static PyObject *
Per_get_oid(cPersistentObject *self)
{
PyObject *oid = self->oid ? self->oid : Py_None;
@@ -750,11 +736,33 @@
return 0;
}
+static PyObject *
+Per_get_serial(cPersistentObject *self)
+{
+ return PyString_FromStringAndSize(self->serial, 8);
+}
+
+static int
+Per_set_serial(cPersistentObject *self, PyObject *v)
+{
+ if (v) {
+ if (PyString_Check(v) && PyString_GET_SIZE(v) == 8)
+ memcpy(self->serial, PyString_AS_STRING(v), 8);
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "_p_serial must be an 8-character string");
+ return -1;
+ }
+ } else
+ memset(self->serial, 0, 8);
+ return 0;
+}
static PyGetSetDef Per_getsets[] = {
-/* {"_p_changed", (getter)Per_get_state, (setter)Per_set_state}, */
- {"_p_oid", (getter)Per_get_oid, (setter)Per_set_oid},
+ {"_p_changed", (getter)Per_get_changed, (setter)Per_set_changed},
{"_p_jar", (getter)Per_get_jar, (setter)Per_set_jar},
+ {"_p_oid", (getter)Per_get_oid, (setter)Per_set_oid},
+ {"_p_serial", (getter)Per_get_serial, (setter)Per_set_serial},
{NULL}
};
More information about the Zodb-checkins
mailing list