[Zodb-checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.1.2.11

Jeremy Hylton jeremy@zope.com
Mon, 4 Mar 2002 16:45:34 -0500


Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv23883

Modified Files:
      Tag: Zope-3x-branch
	cPersistence.c 
Log Message:
Add __implements__ attribute to Persistent type implemented in C.

Extend test suite to verify that Persistent implements IPersistent and
other tests implied by the first one.

Remove persist_safe() method from cPersistence.c; was obsolete as of
previous checkin.

Add persist_set_interface() that adds __implements__ to type's tp_dict
after the type is initialized.


=== Zope3/lib/python/Persistence/cPersistence.c 1.1.2.10 => 1.1.2.11 ===
 #include "Python.h"
 #include "structmember.h"
 #include "cPersistence.h"
@@ -426,13 +427,6 @@
     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},
@@ -680,6 +674,31 @@
     PyPersist_SetATime
 };
 
+static int
+persist_set_interface(PyTypeObject *type)
+{
+    PyObject *mod = NULL, *iface = NULL, *implements = NULL;
+    int r = -1;
+
+    mod = PyImport_ImportModule("Persistence.IPersistent");
+    if (mod == NULL)
+	goto err;
+    iface = PyObject_GetAttrString(mod, "IPersistent");
+    if (iface == NULL)
+	goto err;
+    implements = PyTuple_New(1);
+    if (implements == NULL) 
+	goto err;
+    PyTuple_SET_ITEM(implements, 0, iface);
+    assert(type->typ_dict != NULL);
+    r = PyDict_SetItemString(type->tp_dict, "__implements__", implements);
+ err:
+    Py_XDECREF(mod);
+    Py_XDECREF(iface);
+    Py_XDECREF(implements);
+    return r;
+}
+
 void 
 initcPersistence(void)
 {
@@ -687,6 +706,8 @@
 
     PyPersist_Type.ob_type = &PyType_Type;
     if (PyType_Ready(&PyPersist_Type) < 0)
+	return;
+    if (persist_set_interface(&PyPersist_Type) < 0)
 	return;
 
     m = Py_InitModule3("cPersistence", PyPersist_methods,