[Zope3-checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.15 cPersistence.h:1.3 cPersistenceAPI.h:1.3
Jeremy Hylton
jeremy@zope.com
Wed, 24 Jul 2002 18:55:50 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv31380/Persistence
Modified Files:
cPersistence.c cPersistence.h cPersistenceAPI.h
Log Message:
Change internal API to register with Connection instead of Transaction.
(This mirrors a change made in the Zope 2 trunk.)
As a result, _PyPersist_RegisterTransaction() is not needed. Change
the PER_CHANGED() and PyPersist_CHANGED() macros to use
_PyPersist_RegisterDataManager() via the CAPI struct.
Extend _PyPersist_RegisterDataManager() to set state to CHANGED.
=== Zope3/lib/python/Persistence/cPersistence.c 1.14 => 1.15 ===
result = PyObject_Call(meth, arg, NULL);
Py_DECREF(arg);
Py_DECREF(meth);
+ if (self->po_state == UPTODATE || self->po_state == STICKY)
+ self->po_state = CHANGED;
return result;
}
@@ -102,78 +104,6 @@
return result;
}
-/* A helper function to register an object with the current
- transaction. Returns 1 if the object is successfully registered.
- Returns 0 if the object doesn't need to be registered. Returns -1
- on error.
-*/
-
-int
-_PyPersist_RegisterTransaction(PyPersistBaseObject *self)
-{
- static PyObject *get_transaction = NULL;
- PyObject *mod = NULL;
- PyObject *args, *trans, *reg, *ret;
-
- if (!((self->po_state == UPTODATE || self->po_state == STICKY)
- && self->po_dm))
- return 0;
-
- /* If get_transaction is not NULL, then s_register is not either. */
- if (get_transaction == NULL) {
- if (s_register == NULL) {
- s_register = PyString_InternFromString("register");
- if (s_register == NULL)
- return -1;
- }
- mod = PyImport_ImportModule("Transaction");
- if (mod == NULL)
- return -1;
- get_transaction = PyObject_GetAttrString(mod, "get_transaction");
- if (get_transaction == NULL)
- goto get_transaction_error;
- Py_DECREF(mod);
- }
- /* The C code below is equivalent to this Python code:
- get_transaction().register(self)
- */
- args = PyTuple_New(0);
- if (args == NULL)
- return -1;
- trans = PyObject_Call(get_transaction, args, NULL);
- Py_DECREF(args);
- args = NULL;
- if (trans == NULL)
- return -1;
- reg = PyObject_GetAttr(trans, s_register);
- if (reg == NULL)
- goto register_error;
- args = PyTuple_New(1);
- if (args == NULL)
- goto register_error;
- Py_INCREF(self);
- PyTuple_SET_ITEM(args, 0, (PyObject *)self);
- ret = PyObject_Call(reg, args, NULL);
- if (ret == NULL)
- goto register_error;
- Py_DECREF(ret);
- Py_DECREF(args);
- Py_DECREF(reg);
- Py_DECREF(trans);
- self->po_state = CHANGED;
- return 1;
-
- register_error:
- Py_XDECREF(args);
- Py_XDECREF(trans);
- Py_XDECREF(reg);
- return -1;
-
- get_transaction_error:
- Py_XDECREF(mod);
- return -1;
-}
-
/* A helper function to set the atime from the current time. The
po_atime slot stores seconds since the start of the day. The need
for an atime slot and its particular semantics are specific to the
@@ -457,11 +387,14 @@
Implement with simple check on s_name[0] to avoid two strncmp()
calls for all attribute names that don't start with an
underscore.
+
+ XXX Don't revive a ghost just to get its __class__.
*/
- if ((s_name[0] != '_')
- || ((strncmp(s_name, "_p_", 3) != 0)
- && (strcmp(s_name, "__dict__") != 0))) {
+ if ((s_name[0] != '_') ||
+ ((strncmp(s_name, "_p_", 3) != 0) &&
+ (strcmp(s_name, "__dict__") != 0) &&
+ (strcmp(s_name, "__class__") != 0))) {
if (self->po_state == GHOST) {
/* Prevent the object from being registered as changed.
@@ -825,7 +758,7 @@
&PyPersistBase_Type,
&PyPersist_Type,
_PyPersist_Load,
- _PyPersist_RegisterTransaction,
+ _PyPersist_RegisterDataManager,
_PyPersist_SetATime
};
=== Zope3/lib/python/Persistence/cPersistence.h 1.2 => 1.3 ===
extern PyObject *_PyPersist_Load(PyPersistBaseObject *);
extern PyObject *_PyPersist_RegisterDataManager(PyPersistBaseObject *);
-extern int _PyPersist_RegisterTransaction(PyPersistBaseObject *);
extern void _PyPersist_SetATime(PyPersistBaseObject *);
/* A struct to encapsulation the PyPersist C API for use by other
@@ -53,7 +52,7 @@
PyTypeObject *base_type;
PyTypeObject *instance_type;
PyObject *(*load)(PyPersistBaseObject *);
- int (*reg_trans)(PyPersistBaseObject *);
+ PyObject *(*reg_mgr)(PyPersistBaseObject *);
void (*set_atime)(PyPersistBaseObject *);
} PyPersist_C_API_struct;
=== Zope3/lib/python/Persistence/cPersistenceAPI.h 1.2 => 1.3 ===
((O)->po_state == STICKY || (O)->po_state == CHANGED)
#define PyPersist_CHANGED(O) \
- PyPersist_C_API->reg_trans((PyPersistBaseObject *)(O))
+ PyPersist_C_API->reg_mgr((PyPersistBaseObject *)(O))
#define PyPersist_SetATime(O) \
PyPersist_C_API->set_atime((PyPersistBaseObject *)(O))
@@ -46,7 +46,7 @@
(O)->po_state = STICKY; \
}
-#define PER_CHANGED(O) PyPersist_C_API->reg_trans((PyPersistBaseObject *)(O))
+#define PER_CHANGED(O) PyPersist_C_API->reg_mgr((PyPersistBaseObject *)(O))
#define PER_ALLOW_DEACTIVATION(O) \
{ \