[Zodb-checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.1.2.13 cPersistence.h:1.1.2.5 cPersistenceAPI.h:1.1.2.5
Jeremy Hylton
jeremy@zope.com
Tue, 4 Jun 2002 11:45:40 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv19248
Modified Files:
Tag: Zope-3x-branch
cPersistence.c cPersistence.h cPersistenceAPI.h
Log Message:
Define a PyPersistBaseObject that has the layout of PyPersist_HEAD.
The distinction between PyPersistBaseObject and PyPersistObject is
that the latter has po_dict, which can hold an __dict__ attribute.
Change the basic persistence API to deal in PyPersistBaseObject.
=== Zope3/lib/python/Persistence/cPersistence.c 1.1.2.12 => 1.1.2.13 ===
PyObject *
-PyPersist_RegisterDataManager(PyPersistObject *self)
+PyPersist_RegisterDataManager(PyPersistBaseObject *self)
{
PyObject *meth, *arg, *result;
@@ -71,7 +71,7 @@
*/
PyObject *
-PyPersist_Load(PyPersistObject *self)
+PyPersist_Load(PyPersistBaseObject *self)
{
static PyObject *s_setstate = NULL;
PyObject *meth, *arg, *result;
@@ -105,7 +105,7 @@
*/
int
-PyPersist_RegisterTransaction(PyPersistObject *self)
+PyPersist_RegisterTransaction(PyPersistBaseObject *self)
{
static PyObject *get_transaction = NULL;
PyObject *mainmod = NULL, *builtins = NULL;
@@ -182,7 +182,7 @@
*/
void
-PyPersist_SetATime(PyPersistObject *self)
+PyPersist_SetATime(PyPersistBaseObject *self)
{
time_t t = time(NULL);
self->po_atime = t % 86400;
@@ -378,7 +378,7 @@
if (newstate == CHANGED_TRUE || newstate == CHANGED_FALSE) {
/* Turn a ghost into a real object. */
self->po_state = CHANGED;
- if (PyPersist_Load(self) == NULL)
+ if (PyPersist_Load((PyPersistBaseObject *)self) == NULL)
return -1;
if (newstate == CHANGED_TRUE)
self->po_state = CHANGED;
@@ -389,7 +389,7 @@
/* Mark an up-to-date object as changed. */
if (self->po_state == UPTODATE) {
self->po_state = CHANGED;
- if (PyPersist_RegisterDataManager(self) == NULL)
+ if (!PyPersist_RegisterDataManager((PyPersistBaseObject *)self))
return -1;
}
} else if (newstate == CHANGED_FALSE) {
@@ -491,14 +491,14 @@
&& (strcmp(s_name, "__dict__") != 0))) {
if (self->po_state == GHOST) {
self->po_state = CHANGED;
- if (PyPersist_Load(self) == NULL) {
+ if (PyPersist_Load((PyPersistBaseObject *)self) == NULL) {
persist_deactivate(self);
self->po_state = GHOST;
return NULL;
} else
self->po_state = UPTODATE;
}
- PyPersist_SetATime(self);
+ PyPersist_SetATime((PyPersistBaseObject *)self);
}
attr = PyObject_GenericGetAttr((PyObject *)self, name);
@@ -547,15 +547,15 @@
"attempt to modify unrevivable ghost");
return -1;
}
- if (PyPersist_Load(self) == NULL)
+ if (PyPersist_Load((PyPersistBaseObject *)self) == NULL)
return -1;
} else if (self->po_state == UPTODATE && self->po_dm)
- if (PyPersist_RegisterDataManager(self) == NULL)
+ if (!PyPersist_RegisterDataManager((PyPersistBaseObject *)self))
return -1;
if (self->po_dm && self->po_oid) {
self->po_state = CHANGED;
- PyPersist_SetATime(self);
+ PyPersist_SetATime((PyPersistBaseObject *)self);
}
}
=== Zope3/lib/python/Persistence/cPersistence.h 1.1.2.4 => 1.1.2.5 ===
typedef struct {
+ PyPersist_HEAD
+} PyPersistBaseObject;
+
+typedef struct {
PyPersist_INSTANCE_HEAD
} PyPersistObject;
/* XXX need to make these macros in cPersistenceAPI.h */
-extern PyObject *PyPersist_Load(PyPersistObject *);
-extern PyObject *PyPersist_RegisterDataManager(PyPersistObject *);
-extern int PyPersist_RegisterTransaction(PyPersistObject *);
-extern void PyPersist_SetATime(PyPersistObject *);
+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
dynamically load extensions.
@@ -48,8 +52,8 @@
typedef struct {
PyTypeObject *type;
- PyObject *(*load)(PyPersistObject *);
- int (*reg_trans)(PyPersistObject *);
- void (*set_atime)(PyPersistObject *);
+ PyObject *(*load)(PyPersistBaseObject *);
+ int (*reg_trans)(PyPersistBaseObject *);
+ void (*set_atime)(PyPersistBaseObject *);
} PyPersist_C_API_struct;
=== Zope3/lib/python/Persistence/cPersistenceAPI.h 1.1.2.4 => 1.1.2.5 ===
if (((O)->po_state == UPTODATE) \
|| ((O)->po_state == GHOST \
- && PyPersist_C_API->load((PyPersistObject *)(O)))) \
+ && PyPersist_C_API->load((PyPersistBaseObject *)(O)))) \
(O)->po_state = STICKY;
#define PyPersist_DECREF(O) \
@@ -24,25 +24,25 @@
}
/* XXX need to check *either* sticky or changed for now */
-#define PyPersist_IS_STICKY(O) ((O)->po_state == STICKY || \
- (O)->po_state == CHANGED)
+#define PyPersist_IS_STICKY(O) \
+ ((O)->po_state == STICKY || (O)->po_state == CHANGED)
#define PyPersist_CHANGED(O) \
- PyPersist_C_API->reg_trans((PyPersistObject *)(O))
+ PyPersist_C_API->reg_trans((PyPersistBaseObject *)(O))
/* Macros for compatibility with ZODB 3 C extensions. */
#define PER_USE_OR_RETURN(O, R) \
{ \
if (((O)->po_state == GHOST) \
- && (PyPersist_C_API->load((PyPersistObject *)(O)) < 0)) { \
+ && (PyPersist_C_API->load((PyPersistBaseObject *)(O)) < 0)) { \
(O)->po_state = STICKY; \
return (R); \
} else if ((O)->po_state == UPTODATE) \
(O)->po_state = STICKY; \
}
-#define PER_CHANGED(O) PyPersist_C_API->reg_trans((PyPersistObject *)(O))
+#define PER_CHANGED(O) PyPersist_C_API->reg_trans((PyPersistBaseObject *)(O))
#define PER_ALLOW_DEACTIVATION(O) \
{ \
@@ -57,9 +57,9 @@
}
#define PER_USE(O) \
- ((((PyPersistObject *)(O))->po_state != GHOST) \
- || (PyPersist_C_API->load((PyPersistObject *)(O)) >= 0) \
- ? ((((PyPersistObject *)(O))->po_state == UPTODATE) \
- ? (((PyPersistObject *)(O))->po_state = STICKY) : 1) : 0)
+ ((((PyPersistBaseObject *)(O))->po_state != GHOST) \
+ || (PyPersist_C_API->load((PyPersistBaseObject *)(O)) >= 0) \
+ ? ((((PyPersistBaseObject *)(O))->po_state == UPTODATE) \
+ ? (((PyPersistBaseObject *)(O))->po_state = STICKY) : 1) : 0)
-#define PER_ACCESSED(O) PyPersist_C_API->set_atime((PyPersistObject *)O)
+#define PER_ACCESSED(O) PyPersist_C_API->set_atime((PyPersistBaseObject *)O)