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

Jeremy Hylton jeremy@zope.com
Wed, 17 Jul 2002 18:14:19 -0400


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

Modified Files:
	cPersistence.c 
Log Message:
Get get_transaction() from Transaction not from __builtins__.
Export the enum values for GHOST &c. as Python constants


=== Zope3/lib/python/Persistence/cPersistence.c 1.10 => 1.11 ===
 _PyPersist_RegisterTransaction(PyPersistBaseObject *self)
 {
     static PyObject *get_transaction = NULL;
-    PyObject *mainmod = NULL, *builtins = NULL;
+    PyObject *mod = NULL;
     PyObject *args, *trans, *reg, *ret;
 
     if (!((self->po_state == UPTODATE || self->po_state == STICKY)
@@ -126,17 +126,13 @@
 	    if (s_register == NULL)
 		return -1;
 	}
-	mainmod = PyImport_ImportModule("__main__");
-	if (mainmod == NULL)
+	mod = PyImport_ImportModule("Transaction");
+	if (mod == NULL)
 	    return -1;
-	builtins = PyObject_GetAttrString(mainmod, "__builtins__");
-	if (builtins == NULL)
-	    goto get_transaction_error;
-	get_transaction = PyObject_GetAttrString(builtins, "get_transaction");
+	get_transaction = PyObject_GetAttrString(mod, "get_transaction");
 	if (get_transaction == NULL)
 	    goto get_transaction_error;
-	Py_DECREF(builtins);
-	Py_DECREF(mainmod);
+	Py_DECREF(mod);
     }
     /* The C code below is equivalent to this Python code:
        get_transaction().register(self)
@@ -851,6 +847,19 @@
     return r;
 }
 
+static int 
+insenum(PyObject *d, char *key, enum PyPersist_State val)
+{
+    PyObject *n = PyInt_FromLong(val);
+    int success = 1;
+    if (n == NULL)
+	return 0;
+    if (PyDict_SetItemString(d, key, n) < 0)
+	success = 0;
+    Py_DECREF(n);
+    return success;
+}
+
 void 
 initcPersistence(void)
 {
@@ -890,4 +899,13 @@
     if (PyDict_SetItemString(d, "C_API", v) < 0)
 	return;
     Py_DECREF(v);
+
+    if (!insenum(d, "UPTODATE", UPTODATE))
+	return;
+    if (!insenum(d, "CHANGED", CHANGED))
+	return;
+    if (!insenum(d, "STICKY", STICKY))
+	return;
+    if (!insenum(d, "GHOST", GHOST))
+	return;
 }