[Zodb-checkins] CVS: ZODB3/Persistence - cPersistence.c:1.72.8.8

Jeremy Hylton jeremy at zope.com
Thu Jul 3 14:25:46 EDT 2003


Update of /cvs-repository/ZODB3/Persistence
In directory cvs.zope.org:/tmp/cvs-serv19607/Persistence

Modified Files:
      Tag: zodb33-devel-branch
	cPersistence.c 
Log Message:
Start a test module for Persistent, and convert attribute access to
_p_oid and _p_jar to use getsets.



=== ZODB3/Persistence/cPersistence.c 1.72.8.7 => 1.72.8.8 ===
--- ZODB3/Persistence/cPersistence.c:1.72.8.7	Tue Jul  1 19:14:58 2003
+++ ZODB3/Persistence/cPersistence.c	Thu Jul  3 13:25:11 2003
@@ -17,6 +17,7 @@
 "$Id$\n";
 
 #include "cPersistence.h"
+#include "structmember.h"
 
 struct ccobject_head_struct {
     CACHE_HEAD
@@ -453,12 +454,6 @@
       if (*n++=='p' && *n++=='_') {
 	switch(*n++)
 	  {
-	  case 'o':
-	    if (*n++=='i' && *n++=='d' && ! *n) return orNothing(self->oid);
-	    break;
-	  case 'j':
-	    if (*n++=='a' && *n++=='r' && ! *n) return orNothing(self->jar);
-	    break;
 	  case 'c':
 	    if (strcmp(n,"hanged")==0)
 	      {
@@ -554,47 +549,7 @@
 	return -1;
 
     if (*name == '_' && name[1] == 'p' && name[2] == '_') {
-	if (strcmp(name + 3, "oid") == 0) {
-	    if (self->cache) {
-		int result;
-		if (v == NULL) {
-		    PyErr_SetString(PyExc_ValueError,
-				    "can not delete oid of cached object");
-		    return -1;
-		}
-		if (PyObject_Cmp(self->oid, v, &result) < 0)
-		    return -1;
-		if (result) {
-		    PyErr_SetString(PyExc_ValueError,
-				    "can not change oid of cached object");
-		    return -1;
-		}
-	    }
-	    Py_XINCREF(v);
-	    ASSIGN(self->oid, v);
-	    return 0;
-	}
-	else if (strcmp(name + 3, "jar") == 0) {
-	    if (self->cache && self->jar) {
-		int result;
-		if (v == NULL) {
-		    PyErr_SetString(PyExc_ValueError,
-				    "can not delete jar of cached object");
-		    return -1;
-		}
-		if (PyObject_Cmp(self->jar, v, &result) < 0)
-		    return -1;
-		if (result) {
-		    PyErr_SetString(PyExc_ValueError,
-				    "can not change jar of cached object");
-		    return -1;
-		}
-	    }
-	    Py_XINCREF(v);
-	    ASSIGN(self->jar, v);
-	    return 0;
-	}
-	else if (strcmp(name + 3, "serial") == 0) {
+	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);
@@ -714,6 +669,95 @@
   return -1;
 }
 
+/*
+
+static PyMethodDef Per_methods[] = {
+    {"__reduce__", (PyCFunction)persist_reduce, METH_NOARGS, },
+    {"__getstate__", (PyCFunction)persist_getstate, METH_NOARGS, },
+    {"__setstate__", persist_setstate, METH_O, },
+    {"_p_activate", (PyCFunction)persist_activate, METH_NOARGS, },
+    {"_p_deactivate", (PyCFunction)persist_deactivate, METH_KEYWORDS, },
+    {"_p_setattr", (PyCFunction)persist_p_setattr, METH_VARARGS, },
+    {"_p_delattr", (PyCFunction)persist_p_delattr, METH_O, },
+    {NULL}
+};
+
+*/
+
+static PyObject *
+Per_get_oid(cPersistentObject *self)
+{
+    PyObject *oid = self->oid ? self->oid : Py_None;
+    Py_INCREF(oid);
+    return oid;
+}
+
+static int
+Per_set_oid(cPersistentObject *self, PyObject *v)
+{
+    if (self->cache) {
+	int result;
+
+	if (v == NULL) {
+	    PyErr_SetString(PyExc_ValueError,
+			    "can't delete _p_oid of cached object");
+	    return -1;
+	}
+	if (PyObject_Cmp(self->oid, v, &result) < 0)
+	    return -1;
+	if (result) {
+	    PyErr_SetString(PyExc_ValueError,
+			    "can not change _p_oid of cached object");
+	    return -1;
+	}
+    }
+    Py_XDECREF(self->oid);
+    Py_XINCREF(v);
+    self->oid = v;
+    return 0;
+}
+
+static PyObject *
+Per_get_jar(cPersistentObject *self)
+{
+    PyObject *jar = self->jar ? self->jar : Py_None;
+    Py_INCREF(jar);
+    return jar;
+}
+
+static int
+Per_set_jar(cPersistentObject *self, PyObject *v)
+{
+    if (self->cache) {
+	int result;
+
+	if (v == NULL) {
+	    PyErr_SetString(PyExc_ValueError,
+			    "can't delete _p_jar of cached object");
+	    return -1;
+	}
+	if (PyObject_Cmp(self->jar, v, &result) < 0)
+	    return -1;
+	if (result) {
+	    PyErr_SetString(PyExc_ValueError,
+			    "can not change _p_jar of cached object");
+	    return -1;
+	}
+    }
+    Py_XDECREF(self->jar);
+    Py_XINCREF(v);
+    self->jar = v;
+    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_jar", (getter)Per_get_jar, (setter)Per_set_jar},
+    {NULL}
+};
+
 /* This module is compiled as a shared library.  Some compilers don't
    allow addresses of Python objects defined in other libraries to be
    used in static initializers here.  The DEFERRED_ADDRESS macro is
@@ -758,6 +802,8 @@
     0,					/* tp_iter */
     0,					/* tp_iternext */
     Per_methods,			/* tp_methods */
+    0,			/* tp_members */
+    Per_getsets,			/* tp_getset */
 };
 
 /* End of code for Persistent objects */




More information about the Zodb-checkins mailing list