[Zodb-checkins] CVS: Zope3/lib/python/Persistence - cPersistenceAPI.h:1.1.2.3

Jeremy Hylton jeremy@zope.com
Sat, 2 Mar 2002 01:32:46 -0500


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

Modified Files:
      Tag: Zope-3x-branch
	cPersistenceAPI.h 
Log Message:
Fix PER_USE_OR_RETURN() macro.
Add some PyPersist_XXX macros that correspond roughtly to PER_XXX macros.

The PyPersist_Load() function does *not* set the object's state to
STICKY, which the Zope2 sestate() function did do.  So the macro needs
to assign state to STICKY.

Add PyPersist_INCREF() / PyPersist_DECREF() macros, which control the
sticky state.  INCREF() will load a ghost.  Expect future modification
to have actual refcount instead of single STICKY state.

Add PyPersist_IS_STICKY() to test sticky state.

Programs should use PyPersist_INCREF() + PyPersist_IS_STICKY() in
place of PER_USE_OR_RETURN().



=== Zope3/lib/python/Persistence/cPersistenceAPI.h 1.1.2.2 => 1.1.2.3 ===
 #define PyPersist_TYPE PyPersist_C_API->type
 
+#define PyPersist_INCREF(O) \
+    if (((O)->po_state == UPTODATE) \
+	|| ((O)->po_state == GHOST \
+	    && PyPersist_C_API->load((PyPersistObject *)(O)))) \
+	(O)->po_state = STICKY;
+
+#define PyPersist_DECREF(O) \
+    { \
+        if ((O)->po_state == STICKY) \
+	    (O)->po_state = UPTODATE; \
+    }
+
+/* XXX perhaps this is a bad name */
+#define PyPersist_IS_STICKY(O) ((O)->po_state == STICKY)
+
+#define PyPersist_CHANGED(O) \
+    PyPersist_C_API->reg_trans((PyPersistObject *)(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((PyPersistObject *)(O)) < 0)) { \
+        (O)->po_state = STICKY; \
 	return (R); \
-    else if ((O)->po_state == UPTODATE) \
+    } else if ((O)->po_state == UPTODATE) \
 	(O)->po_state = STICKY; \
 }