Commit 6c535ede authored by Jeremy Hylton's avatar Jeremy Hylton

Consolidate the MUCH_RING_CHECKING code.

If MUCH_RING_CHECKING is not defined (the default), then:
  - use a macro for OBJECT_FROM_RING() instead of a function call, and
  - define IS_RING_CORRUPT() to be constant 0.

XXX Sometime before Zope 2.6 final we should probably remove the
MUCH_RING_CHECKING and ENGINE_NOISE code entirely.
parent 0ac40f39
...@@ -88,7 +88,7 @@ process must skip such objects, rather than deactivating them. ...@@ -88,7 +88,7 @@ process must skip such objects, rather than deactivating them.
static char cPickleCache_doc_string[] = static char cPickleCache_doc_string[] =
"Defines the PickleCache used by ZODB Connection objects.\n" "Defines the PickleCache used by ZODB Connection objects.\n"
"\n" "\n"
"$Id: cPickleCache.c,v 1.67 2002/06/10 22:49:41 jeremy Exp $\n"; "$Id: cPickleCache.c,v 1.68 2002/06/11 02:34:22 jeremy Exp $\n";
#define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;} #define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;}
#define UNLESS(E) if(!(E)) #define UNLESS(E) if(!(E))
...@@ -103,14 +103,6 @@ static char cPickleCache_doc_string[] = ...@@ -103,14 +103,6 @@ static char cPickleCache_doc_string[] =
static PyObject *py__p_oid, *py_reload, *py__p_jar, *py__p_changed; static PyObject *py__p_oid, *py_reload, *py__p_jar, *py__p_changed;
/* define this for extra debugging checks, and lousy performance.
Not really necessary in production code... disable this before
release, providing noone has been reporting and RuntimeErrors
that it uses to report problems.
*/
/* #define MUCH_RING_CHECKING 1 */
/* Do we want 'engine noise'.... abstract debugging output useful for /* Do we want 'engine noise'.... abstract debugging output useful for
visualizing cache behavior */ visualizing cache behavior */
#if 0 #if 0
...@@ -151,10 +143,6 @@ typedef struct { ...@@ -151,10 +143,6 @@ typedef struct {
} ccobject; } ccobject;
#ifdef MUCH_RING_CHECKING
static int present_in_ring(ccobject *self, CPersistentRing *target);
#endif
static int ring_corrupt(ccobject *self, const char *context);
static int cc_ass_sub(ccobject *self, PyObject *key, PyObject *v); static int cc_ass_sub(ccobject *self, PyObject *key, PyObject *v);
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
...@@ -171,6 +159,22 @@ object_from_oid(ccobject *self, PyObject *key) ...@@ -171,6 +159,22 @@ object_from_oid(ccobject *self, PyObject *key)
return v; return v;
} }
/* define this for extra debugging checks, and lousy performance.
Not really necessary in production code... disable this before
release, providing noone has been reporting and RuntimeErrors
that it uses to report problems.
*/
/* #define MUCH_RING_CHECKING */
#ifdef MUCH_RING_CHECKING
static int present_in_ring(ccobject *self, CPersistentRing *target);
static int ring_corrupt(ccobject *self, const char *context);
#define IS_RING_CORRUPT(OBJ, CTX) ring_corrupt((OBJ), (CTX))
#define OBJECT_FROM_RING(SELF, HERE, CTX) \
object_from_ring((SELF), (HERE), (CTX))
static cPersistentObject * static cPersistentObject *
object_from_ring(ccobject *self, CPersistentRing *here, const char *context) object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
{ {
...@@ -187,7 +191,6 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context) ...@@ -187,7 +191,6 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
*/ */
object = (PyObject *)(((char *)here) - offsetof(cPersistentObject, ring)); object = (PyObject *)(((char *)here) - offsetof(cPersistentObject, ring));
#ifdef MUCH_RING_CHECKING
if (!PyExtensionInstance_Check(object)) { if (!PyExtensionInstance_Check(object)) {
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"Unexpectedly encountered non-ExtensionClass object in %s", "Unexpectedly encountered non-ExtensionClass object in %s",
...@@ -210,10 +213,19 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context) ...@@ -210,10 +213,19 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
"Unexpectedly encountered broken ring in %s", context); "Unexpectedly encountered broken ring in %s", context);
return NULL; return NULL;
} }
#endif
return (cPersistentObject *)object; return (cPersistentObject *)object;
} }
#else /* MUCH_RING_CHECKING */
#define IS_RING_CORRUPT(OBJ, CTX) 0
#define OBJECT_FROM_RING(SELF, HERE, CTX) \
((cPersistentObject *)(((char *)here) - offsetof(cPersistentObject, ring)))
#endif
static int static int
scan_gc_items(ccobject *self,int target) scan_gc_items(ccobject *self,int target)
{ {
...@@ -237,7 +249,7 @@ scan_gc_items(ccobject *self,int target) ...@@ -237,7 +249,7 @@ scan_gc_items(ccobject *self,int target)
* size. * size.
*/ */
while (1) { while (1) {
if (ring_corrupt(self, "mid-gc")) if (IS_RING_CORRUPT(self, "mid-gc"))
return -1; return -1;
#ifdef MUCH_RING_CHECKING #ifdef MUCH_RING_CHECKING
...@@ -273,7 +285,7 @@ scan_gc_items(ccobject *self,int target) ...@@ -273,7 +285,7 @@ scan_gc_items(ccobject *self,int target)
this because the ring lock is held. We can safely assume this because the ring lock is held. We can safely assume
the current ring node is a persistent object now we know it the current ring node is a persistent object now we know it
is not the home */ is not the home */
object = object_from_ring(self, here, "scan_gc_items"); object = OBJECT_FROM_RING(self, here, "scan_gc_items");
if (!object) if (!object)
return -1; return -1;
...@@ -333,7 +345,7 @@ lockgc(ccobject *self, int target_size) ...@@ -333,7 +345,7 @@ lockgc(ccobject *self, int target_size)
return Py_None; return Py_None;
} }
if (ring_corrupt(self, "pre-gc")) if (IS_RING_CORRUPT(self, "pre-gc"))
return NULL; return NULL;
ENGINE_NOISE("<"); ENGINE_NOISE("<");
self->ring_lock = 1; self->ring_lock = 1;
...@@ -343,7 +355,7 @@ lockgc(ccobject *self, int target_size) ...@@ -343,7 +355,7 @@ lockgc(ccobject *self, int target_size)
} }
self->ring_lock = 0; self->ring_lock = 0;
ENGINE_NOISE(">\n"); ENGINE_NOISE(">\n");
if (ring_corrupt(self, "post-gc")) if (IS_RING_CORRUPT(self, "post-gc"))
return NULL; return NULL;
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -537,7 +549,7 @@ cc_lru_items(ccobject *self, PyObject *args) ...@@ -537,7 +549,7 @@ cc_lru_items(ccobject *self, PyObject *args)
return NULL; return NULL;
} }
if (ring_corrupt(self, "pre-cc_items")) if (IS_RING_CORRUPT(self, "pre-cc_items"))
return NULL; return NULL;
l = PyList_New(0); l = PyList_New(0);
...@@ -547,7 +559,7 @@ cc_lru_items(ccobject *self, PyObject *args) ...@@ -547,7 +559,7 @@ cc_lru_items(ccobject *self, PyObject *args)
here = self->ring_home.next; here = self->ring_home.next;
while (here != &self->ring_home) { while (here != &self->ring_home) {
PyObject *v; PyObject *v;
cPersistentObject *object = object_from_ring(self, here, "cc_items"); cPersistentObject *object = OBJECT_FROM_RING(self, here, "cc_items");
if (object == NULL) { if (object == NULL) {
Py_DECREF(l); Py_DECREF(l);
...@@ -689,7 +701,7 @@ cc_getattr(ccobject *self, char *name) ...@@ -689,7 +701,7 @@ cc_getattr(ccobject *self, char *name)
{ {
PyObject *r; PyObject *r;
if (ring_corrupt(self, "getattr")) if (IS_RING_CORRUPT(self, "getattr"))
return NULL; return NULL;
if(*name=='c') if(*name=='c')
...@@ -764,7 +776,7 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -764,7 +776,7 @@ cc_subscript(ccobject *self, PyObject *key)
{ {
PyObject *r; PyObject *r;
if (ring_corrupt(self, "__getitem__")) if (IS_RING_CORRUPT(self, "__getitem__"))
return NULL; return NULL;
r = (PyObject *)object_from_oid(self, key); r = (PyObject *)object_from_oid(self, key);
...@@ -872,7 +884,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v) ...@@ -872,7 +884,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v)
*/ */
} }
if (ring_corrupt(self, "pre-setitem")) if (IS_RING_CORRUPT(self, "pre-setitem"))
return -1; return -1;
if (PyDict_SetItem(self->data, key, v) < 0) if (PyDict_SetItem(self->data, key, v) < 0)
return -1; return -1;
...@@ -894,7 +906,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v) ...@@ -894,7 +906,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v)
Py_DECREF(v); Py_DECREF(v);
} }
if (ring_corrupt(self, "post-setitem")) if (IS_RING_CORRUPT(self, "post-setitem"))
return -1; return -1;
else else
return 0; return 0;
...@@ -907,7 +919,7 @@ cc_del_item(ccobject *self, PyObject *key) ...@@ -907,7 +919,7 @@ cc_del_item(ccobject *self, PyObject *key)
cPersistentObject *p; cPersistentObject *p;
/* unlink this item from the ring */ /* unlink this item from the ring */
if (ring_corrupt(self, "pre-delitem")) if (IS_RING_CORRUPT(self, "pre-delitem"))
return -1; return -1;
v = (PyObject *)object_from_oid(self, key); v = (PyObject *)object_from_oid(self, key);
...@@ -945,7 +957,7 @@ cc_del_item(ccobject *self, PyObject *key) ...@@ -945,7 +957,7 @@ cc_del_item(ccobject *self, PyObject *key)
return -1; return -1;
} }
if (ring_corrupt(self, "post-delitem")) if (IS_RING_CORRUPT(self, "post-delitem"))
return -1; return -1;
return 0; return 0;
...@@ -1004,7 +1016,7 @@ _ring_corrupt(ccobject *self, const char *context) ...@@ -1004,7 +1016,7 @@ _ring_corrupt(ccobject *self, const char *context)
/* If the ring is unlocked, then it must not contain /* If the ring is unlocked, then it must not contain
* objects other than persistent instances (and the home) */ * objects other than persistent instances (and the home) */
if (here != &self->ring_home) { if (here != &self->ring_home) {
cPersistentObject *object = object_from_ring(self, here, cPersistentObject *object = OBJECT_FROM_RING(self, here,
context); context);
if (!object) if (!object)
return 12; return 12;
...@@ -1032,12 +1044,10 @@ _ring_corrupt(ccobject *self, const char *context) ...@@ -1032,12 +1044,10 @@ _ring_corrupt(ccobject *self, const char *context)
return 0; return 0;
} }
#endif /* MUCH_RING_CHECKING */
static int static int
ring_corrupt(ccobject *self, const char *context) ring_corrupt(ccobject *self, const char *context)
{ {
#ifdef MUCH_RING_CHECKING
int code = _ring_corrupt(self, context); int code = _ring_corrupt(self, context);
if (code) { if (code) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
...@@ -1046,11 +1056,9 @@ ring_corrupt(ccobject *self, const char *context) ...@@ -1046,11 +1056,9 @@ ring_corrupt(ccobject *self, const char *context)
code, context, PyDict_Size(self->data)); code, context, PyDict_Size(self->data));
return code; return code;
} }
#endif
return 0; return 0;
} }
#ifdef MUCH_RING_CHECKING
static int static int
present_in_ring(ccobject *self,CPersistentRing *target) present_in_ring(ccobject *self,CPersistentRing *target)
{ {
...@@ -1063,7 +1071,7 @@ present_in_ring(ccobject *self,CPersistentRing *target) ...@@ -1063,7 +1071,7 @@ present_in_ring(ccobject *self,CPersistentRing *target)
here = here->next; here = here->next;
} }
} }
#endif #endif /* MUCH_RING_CHECKING */
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
(inquiry)cc_length, /*mp_length*/ (inquiry)cc_length, /*mp_length*/
......
...@@ -88,7 +88,7 @@ process must skip such objects, rather than deactivating them. ...@@ -88,7 +88,7 @@ process must skip such objects, rather than deactivating them.
static char cPickleCache_doc_string[] = static char cPickleCache_doc_string[] =
"Defines the PickleCache used by ZODB Connection objects.\n" "Defines the PickleCache used by ZODB Connection objects.\n"
"\n" "\n"
"$Id: cPickleCache.c,v 1.67 2002/06/10 22:49:41 jeremy Exp $\n"; "$Id: cPickleCache.c,v 1.68 2002/06/11 02:34:22 jeremy Exp $\n";
#define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;} #define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;}
#define UNLESS(E) if(!(E)) #define UNLESS(E) if(!(E))
...@@ -103,14 +103,6 @@ static char cPickleCache_doc_string[] = ...@@ -103,14 +103,6 @@ static char cPickleCache_doc_string[] =
static PyObject *py__p_oid, *py_reload, *py__p_jar, *py__p_changed; static PyObject *py__p_oid, *py_reload, *py__p_jar, *py__p_changed;
/* define this for extra debugging checks, and lousy performance.
Not really necessary in production code... disable this before
release, providing noone has been reporting and RuntimeErrors
that it uses to report problems.
*/
/* #define MUCH_RING_CHECKING 1 */
/* Do we want 'engine noise'.... abstract debugging output useful for /* Do we want 'engine noise'.... abstract debugging output useful for
visualizing cache behavior */ visualizing cache behavior */
#if 0 #if 0
...@@ -151,10 +143,6 @@ typedef struct { ...@@ -151,10 +143,6 @@ typedef struct {
} ccobject; } ccobject;
#ifdef MUCH_RING_CHECKING
static int present_in_ring(ccobject *self, CPersistentRing *target);
#endif
static int ring_corrupt(ccobject *self, const char *context);
static int cc_ass_sub(ccobject *self, PyObject *key, PyObject *v); static int cc_ass_sub(ccobject *self, PyObject *key, PyObject *v);
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
...@@ -171,6 +159,22 @@ object_from_oid(ccobject *self, PyObject *key) ...@@ -171,6 +159,22 @@ object_from_oid(ccobject *self, PyObject *key)
return v; return v;
} }
/* define this for extra debugging checks, and lousy performance.
Not really necessary in production code... disable this before
release, providing noone has been reporting and RuntimeErrors
that it uses to report problems.
*/
/* #define MUCH_RING_CHECKING */
#ifdef MUCH_RING_CHECKING
static int present_in_ring(ccobject *self, CPersistentRing *target);
static int ring_corrupt(ccobject *self, const char *context);
#define IS_RING_CORRUPT(OBJ, CTX) ring_corrupt((OBJ), (CTX))
#define OBJECT_FROM_RING(SELF, HERE, CTX) \
object_from_ring((SELF), (HERE), (CTX))
static cPersistentObject * static cPersistentObject *
object_from_ring(ccobject *self, CPersistentRing *here, const char *context) object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
{ {
...@@ -187,7 +191,6 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context) ...@@ -187,7 +191,6 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
*/ */
object = (PyObject *)(((char *)here) - offsetof(cPersistentObject, ring)); object = (PyObject *)(((char *)here) - offsetof(cPersistentObject, ring));
#ifdef MUCH_RING_CHECKING
if (!PyExtensionInstance_Check(object)) { if (!PyExtensionInstance_Check(object)) {
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"Unexpectedly encountered non-ExtensionClass object in %s", "Unexpectedly encountered non-ExtensionClass object in %s",
...@@ -210,10 +213,19 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context) ...@@ -210,10 +213,19 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
"Unexpectedly encountered broken ring in %s", context); "Unexpectedly encountered broken ring in %s", context);
return NULL; return NULL;
} }
#endif
return (cPersistentObject *)object; return (cPersistentObject *)object;
} }
#else /* MUCH_RING_CHECKING */
#define IS_RING_CORRUPT(OBJ, CTX) 0
#define OBJECT_FROM_RING(SELF, HERE, CTX) \
((cPersistentObject *)(((char *)here) - offsetof(cPersistentObject, ring)))
#endif
static int static int
scan_gc_items(ccobject *self,int target) scan_gc_items(ccobject *self,int target)
{ {
...@@ -237,7 +249,7 @@ scan_gc_items(ccobject *self,int target) ...@@ -237,7 +249,7 @@ scan_gc_items(ccobject *self,int target)
* size. * size.
*/ */
while (1) { while (1) {
if (ring_corrupt(self, "mid-gc")) if (IS_RING_CORRUPT(self, "mid-gc"))
return -1; return -1;
#ifdef MUCH_RING_CHECKING #ifdef MUCH_RING_CHECKING
...@@ -273,7 +285,7 @@ scan_gc_items(ccobject *self,int target) ...@@ -273,7 +285,7 @@ scan_gc_items(ccobject *self,int target)
this because the ring lock is held. We can safely assume this because the ring lock is held. We can safely assume
the current ring node is a persistent object now we know it the current ring node is a persistent object now we know it
is not the home */ is not the home */
object = object_from_ring(self, here, "scan_gc_items"); object = OBJECT_FROM_RING(self, here, "scan_gc_items");
if (!object) if (!object)
return -1; return -1;
...@@ -333,7 +345,7 @@ lockgc(ccobject *self, int target_size) ...@@ -333,7 +345,7 @@ lockgc(ccobject *self, int target_size)
return Py_None; return Py_None;
} }
if (ring_corrupt(self, "pre-gc")) if (IS_RING_CORRUPT(self, "pre-gc"))
return NULL; return NULL;
ENGINE_NOISE("<"); ENGINE_NOISE("<");
self->ring_lock = 1; self->ring_lock = 1;
...@@ -343,7 +355,7 @@ lockgc(ccobject *self, int target_size) ...@@ -343,7 +355,7 @@ lockgc(ccobject *self, int target_size)
} }
self->ring_lock = 0; self->ring_lock = 0;
ENGINE_NOISE(">\n"); ENGINE_NOISE(">\n");
if (ring_corrupt(self, "post-gc")) if (IS_RING_CORRUPT(self, "post-gc"))
return NULL; return NULL;
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -537,7 +549,7 @@ cc_lru_items(ccobject *self, PyObject *args) ...@@ -537,7 +549,7 @@ cc_lru_items(ccobject *self, PyObject *args)
return NULL; return NULL;
} }
if (ring_corrupt(self, "pre-cc_items")) if (IS_RING_CORRUPT(self, "pre-cc_items"))
return NULL; return NULL;
l = PyList_New(0); l = PyList_New(0);
...@@ -547,7 +559,7 @@ cc_lru_items(ccobject *self, PyObject *args) ...@@ -547,7 +559,7 @@ cc_lru_items(ccobject *self, PyObject *args)
here = self->ring_home.next; here = self->ring_home.next;
while (here != &self->ring_home) { while (here != &self->ring_home) {
PyObject *v; PyObject *v;
cPersistentObject *object = object_from_ring(self, here, "cc_items"); cPersistentObject *object = OBJECT_FROM_RING(self, here, "cc_items");
if (object == NULL) { if (object == NULL) {
Py_DECREF(l); Py_DECREF(l);
...@@ -689,7 +701,7 @@ cc_getattr(ccobject *self, char *name) ...@@ -689,7 +701,7 @@ cc_getattr(ccobject *self, char *name)
{ {
PyObject *r; PyObject *r;
if (ring_corrupt(self, "getattr")) if (IS_RING_CORRUPT(self, "getattr"))
return NULL; return NULL;
if(*name=='c') if(*name=='c')
...@@ -764,7 +776,7 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -764,7 +776,7 @@ cc_subscript(ccobject *self, PyObject *key)
{ {
PyObject *r; PyObject *r;
if (ring_corrupt(self, "__getitem__")) if (IS_RING_CORRUPT(self, "__getitem__"))
return NULL; return NULL;
r = (PyObject *)object_from_oid(self, key); r = (PyObject *)object_from_oid(self, key);
...@@ -872,7 +884,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v) ...@@ -872,7 +884,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v)
*/ */
} }
if (ring_corrupt(self, "pre-setitem")) if (IS_RING_CORRUPT(self, "pre-setitem"))
return -1; return -1;
if (PyDict_SetItem(self->data, key, v) < 0) if (PyDict_SetItem(self->data, key, v) < 0)
return -1; return -1;
...@@ -894,7 +906,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v) ...@@ -894,7 +906,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v)
Py_DECREF(v); Py_DECREF(v);
} }
if (ring_corrupt(self, "post-setitem")) if (IS_RING_CORRUPT(self, "post-setitem"))
return -1; return -1;
else else
return 0; return 0;
...@@ -907,7 +919,7 @@ cc_del_item(ccobject *self, PyObject *key) ...@@ -907,7 +919,7 @@ cc_del_item(ccobject *self, PyObject *key)
cPersistentObject *p; cPersistentObject *p;
/* unlink this item from the ring */ /* unlink this item from the ring */
if (ring_corrupt(self, "pre-delitem")) if (IS_RING_CORRUPT(self, "pre-delitem"))
return -1; return -1;
v = (PyObject *)object_from_oid(self, key); v = (PyObject *)object_from_oid(self, key);
...@@ -945,7 +957,7 @@ cc_del_item(ccobject *self, PyObject *key) ...@@ -945,7 +957,7 @@ cc_del_item(ccobject *self, PyObject *key)
return -1; return -1;
} }
if (ring_corrupt(self, "post-delitem")) if (IS_RING_CORRUPT(self, "post-delitem"))
return -1; return -1;
return 0; return 0;
...@@ -1004,7 +1016,7 @@ _ring_corrupt(ccobject *self, const char *context) ...@@ -1004,7 +1016,7 @@ _ring_corrupt(ccobject *self, const char *context)
/* If the ring is unlocked, then it must not contain /* If the ring is unlocked, then it must not contain
* objects other than persistent instances (and the home) */ * objects other than persistent instances (and the home) */
if (here != &self->ring_home) { if (here != &self->ring_home) {
cPersistentObject *object = object_from_ring(self, here, cPersistentObject *object = OBJECT_FROM_RING(self, here,
context); context);
if (!object) if (!object)
return 12; return 12;
...@@ -1032,12 +1044,10 @@ _ring_corrupt(ccobject *self, const char *context) ...@@ -1032,12 +1044,10 @@ _ring_corrupt(ccobject *self, const char *context)
return 0; return 0;
} }
#endif /* MUCH_RING_CHECKING */
static int static int
ring_corrupt(ccobject *self, const char *context) ring_corrupt(ccobject *self, const char *context)
{ {
#ifdef MUCH_RING_CHECKING
int code = _ring_corrupt(self, context); int code = _ring_corrupt(self, context);
if (code) { if (code) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
...@@ -1046,11 +1056,9 @@ ring_corrupt(ccobject *self, const char *context) ...@@ -1046,11 +1056,9 @@ ring_corrupt(ccobject *self, const char *context)
code, context, PyDict_Size(self->data)); code, context, PyDict_Size(self->data));
return code; return code;
} }
#endif
return 0; return 0;
} }
#ifdef MUCH_RING_CHECKING
static int static int
present_in_ring(ccobject *self,CPersistentRing *target) present_in_ring(ccobject *self,CPersistentRing *target)
{ {
...@@ -1063,7 +1071,7 @@ present_in_ring(ccobject *self,CPersistentRing *target) ...@@ -1063,7 +1071,7 @@ present_in_ring(ccobject *self,CPersistentRing *target)
here = here->next; here = here->next;
} }
} }
#endif #endif /* MUCH_RING_CHECKING */
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
(inquiry)cc_length, /*mp_length*/ (inquiry)cc_length, /*mp_length*/
......
...@@ -88,7 +88,7 @@ process must skip such objects, rather than deactivating them. ...@@ -88,7 +88,7 @@ process must skip such objects, rather than deactivating them.
static char cPickleCache_doc_string[] = static char cPickleCache_doc_string[] =
"Defines the PickleCache used by ZODB Connection objects.\n" "Defines the PickleCache used by ZODB Connection objects.\n"
"\n" "\n"
"$Id: cPickleCache.c,v 1.67 2002/06/10 22:49:41 jeremy Exp $\n"; "$Id: cPickleCache.c,v 1.68 2002/06/11 02:34:22 jeremy Exp $\n";
#define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;} #define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;}
#define UNLESS(E) if(!(E)) #define UNLESS(E) if(!(E))
...@@ -103,14 +103,6 @@ static char cPickleCache_doc_string[] = ...@@ -103,14 +103,6 @@ static char cPickleCache_doc_string[] =
static PyObject *py__p_oid, *py_reload, *py__p_jar, *py__p_changed; static PyObject *py__p_oid, *py_reload, *py__p_jar, *py__p_changed;
/* define this for extra debugging checks, and lousy performance.
Not really necessary in production code... disable this before
release, providing noone has been reporting and RuntimeErrors
that it uses to report problems.
*/
/* #define MUCH_RING_CHECKING 1 */
/* Do we want 'engine noise'.... abstract debugging output useful for /* Do we want 'engine noise'.... abstract debugging output useful for
visualizing cache behavior */ visualizing cache behavior */
#if 0 #if 0
...@@ -151,10 +143,6 @@ typedef struct { ...@@ -151,10 +143,6 @@ typedef struct {
} ccobject; } ccobject;
#ifdef MUCH_RING_CHECKING
static int present_in_ring(ccobject *self, CPersistentRing *target);
#endif
static int ring_corrupt(ccobject *self, const char *context);
static int cc_ass_sub(ccobject *self, PyObject *key, PyObject *v); static int cc_ass_sub(ccobject *self, PyObject *key, PyObject *v);
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
...@@ -171,6 +159,22 @@ object_from_oid(ccobject *self, PyObject *key) ...@@ -171,6 +159,22 @@ object_from_oid(ccobject *self, PyObject *key)
return v; return v;
} }
/* define this for extra debugging checks, and lousy performance.
Not really necessary in production code... disable this before
release, providing noone has been reporting and RuntimeErrors
that it uses to report problems.
*/
/* #define MUCH_RING_CHECKING */
#ifdef MUCH_RING_CHECKING
static int present_in_ring(ccobject *self, CPersistentRing *target);
static int ring_corrupt(ccobject *self, const char *context);
#define IS_RING_CORRUPT(OBJ, CTX) ring_corrupt((OBJ), (CTX))
#define OBJECT_FROM_RING(SELF, HERE, CTX) \
object_from_ring((SELF), (HERE), (CTX))
static cPersistentObject * static cPersistentObject *
object_from_ring(ccobject *self, CPersistentRing *here, const char *context) object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
{ {
...@@ -187,7 +191,6 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context) ...@@ -187,7 +191,6 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
*/ */
object = (PyObject *)(((char *)here) - offsetof(cPersistentObject, ring)); object = (PyObject *)(((char *)here) - offsetof(cPersistentObject, ring));
#ifdef MUCH_RING_CHECKING
if (!PyExtensionInstance_Check(object)) { if (!PyExtensionInstance_Check(object)) {
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"Unexpectedly encountered non-ExtensionClass object in %s", "Unexpectedly encountered non-ExtensionClass object in %s",
...@@ -210,10 +213,19 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context) ...@@ -210,10 +213,19 @@ object_from_ring(ccobject *self, CPersistentRing *here, const char *context)
"Unexpectedly encountered broken ring in %s", context); "Unexpectedly encountered broken ring in %s", context);
return NULL; return NULL;
} }
#endif
return (cPersistentObject *)object; return (cPersistentObject *)object;
} }
#else /* MUCH_RING_CHECKING */
#define IS_RING_CORRUPT(OBJ, CTX) 0
#define OBJECT_FROM_RING(SELF, HERE, CTX) \
((cPersistentObject *)(((char *)here) - offsetof(cPersistentObject, ring)))
#endif
static int static int
scan_gc_items(ccobject *self,int target) scan_gc_items(ccobject *self,int target)
{ {
...@@ -237,7 +249,7 @@ scan_gc_items(ccobject *self,int target) ...@@ -237,7 +249,7 @@ scan_gc_items(ccobject *self,int target)
* size. * size.
*/ */
while (1) { while (1) {
if (ring_corrupt(self, "mid-gc")) if (IS_RING_CORRUPT(self, "mid-gc"))
return -1; return -1;
#ifdef MUCH_RING_CHECKING #ifdef MUCH_RING_CHECKING
...@@ -273,7 +285,7 @@ scan_gc_items(ccobject *self,int target) ...@@ -273,7 +285,7 @@ scan_gc_items(ccobject *self,int target)
this because the ring lock is held. We can safely assume this because the ring lock is held. We can safely assume
the current ring node is a persistent object now we know it the current ring node is a persistent object now we know it
is not the home */ is not the home */
object = object_from_ring(self, here, "scan_gc_items"); object = OBJECT_FROM_RING(self, here, "scan_gc_items");
if (!object) if (!object)
return -1; return -1;
...@@ -333,7 +345,7 @@ lockgc(ccobject *self, int target_size) ...@@ -333,7 +345,7 @@ lockgc(ccobject *self, int target_size)
return Py_None; return Py_None;
} }
if (ring_corrupt(self, "pre-gc")) if (IS_RING_CORRUPT(self, "pre-gc"))
return NULL; return NULL;
ENGINE_NOISE("<"); ENGINE_NOISE("<");
self->ring_lock = 1; self->ring_lock = 1;
...@@ -343,7 +355,7 @@ lockgc(ccobject *self, int target_size) ...@@ -343,7 +355,7 @@ lockgc(ccobject *self, int target_size)
} }
self->ring_lock = 0; self->ring_lock = 0;
ENGINE_NOISE(">\n"); ENGINE_NOISE(">\n");
if (ring_corrupt(self, "post-gc")) if (IS_RING_CORRUPT(self, "post-gc"))
return NULL; return NULL;
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -537,7 +549,7 @@ cc_lru_items(ccobject *self, PyObject *args) ...@@ -537,7 +549,7 @@ cc_lru_items(ccobject *self, PyObject *args)
return NULL; return NULL;
} }
if (ring_corrupt(self, "pre-cc_items")) if (IS_RING_CORRUPT(self, "pre-cc_items"))
return NULL; return NULL;
l = PyList_New(0); l = PyList_New(0);
...@@ -547,7 +559,7 @@ cc_lru_items(ccobject *self, PyObject *args) ...@@ -547,7 +559,7 @@ cc_lru_items(ccobject *self, PyObject *args)
here = self->ring_home.next; here = self->ring_home.next;
while (here != &self->ring_home) { while (here != &self->ring_home) {
PyObject *v; PyObject *v;
cPersistentObject *object = object_from_ring(self, here, "cc_items"); cPersistentObject *object = OBJECT_FROM_RING(self, here, "cc_items");
if (object == NULL) { if (object == NULL) {
Py_DECREF(l); Py_DECREF(l);
...@@ -689,7 +701,7 @@ cc_getattr(ccobject *self, char *name) ...@@ -689,7 +701,7 @@ cc_getattr(ccobject *self, char *name)
{ {
PyObject *r; PyObject *r;
if (ring_corrupt(self, "getattr")) if (IS_RING_CORRUPT(self, "getattr"))
return NULL; return NULL;
if(*name=='c') if(*name=='c')
...@@ -764,7 +776,7 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -764,7 +776,7 @@ cc_subscript(ccobject *self, PyObject *key)
{ {
PyObject *r; PyObject *r;
if (ring_corrupt(self, "__getitem__")) if (IS_RING_CORRUPT(self, "__getitem__"))
return NULL; return NULL;
r = (PyObject *)object_from_oid(self, key); r = (PyObject *)object_from_oid(self, key);
...@@ -872,7 +884,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v) ...@@ -872,7 +884,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v)
*/ */
} }
if (ring_corrupt(self, "pre-setitem")) if (IS_RING_CORRUPT(self, "pre-setitem"))
return -1; return -1;
if (PyDict_SetItem(self->data, key, v) < 0) if (PyDict_SetItem(self->data, key, v) < 0)
return -1; return -1;
...@@ -894,7 +906,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v) ...@@ -894,7 +906,7 @@ cc_add_item(ccobject *self, PyObject *key, PyObject *v)
Py_DECREF(v); Py_DECREF(v);
} }
if (ring_corrupt(self, "post-setitem")) if (IS_RING_CORRUPT(self, "post-setitem"))
return -1; return -1;
else else
return 0; return 0;
...@@ -907,7 +919,7 @@ cc_del_item(ccobject *self, PyObject *key) ...@@ -907,7 +919,7 @@ cc_del_item(ccobject *self, PyObject *key)
cPersistentObject *p; cPersistentObject *p;
/* unlink this item from the ring */ /* unlink this item from the ring */
if (ring_corrupt(self, "pre-delitem")) if (IS_RING_CORRUPT(self, "pre-delitem"))
return -1; return -1;
v = (PyObject *)object_from_oid(self, key); v = (PyObject *)object_from_oid(self, key);
...@@ -945,7 +957,7 @@ cc_del_item(ccobject *self, PyObject *key) ...@@ -945,7 +957,7 @@ cc_del_item(ccobject *self, PyObject *key)
return -1; return -1;
} }
if (ring_corrupt(self, "post-delitem")) if (IS_RING_CORRUPT(self, "post-delitem"))
return -1; return -1;
return 0; return 0;
...@@ -1004,7 +1016,7 @@ _ring_corrupt(ccobject *self, const char *context) ...@@ -1004,7 +1016,7 @@ _ring_corrupt(ccobject *self, const char *context)
/* If the ring is unlocked, then it must not contain /* If the ring is unlocked, then it must not contain
* objects other than persistent instances (and the home) */ * objects other than persistent instances (and the home) */
if (here != &self->ring_home) { if (here != &self->ring_home) {
cPersistentObject *object = object_from_ring(self, here, cPersistentObject *object = OBJECT_FROM_RING(self, here,
context); context);
if (!object) if (!object)
return 12; return 12;
...@@ -1032,12 +1044,10 @@ _ring_corrupt(ccobject *self, const char *context) ...@@ -1032,12 +1044,10 @@ _ring_corrupt(ccobject *self, const char *context)
return 0; return 0;
} }
#endif /* MUCH_RING_CHECKING */
static int static int
ring_corrupt(ccobject *self, const char *context) ring_corrupt(ccobject *self, const char *context)
{ {
#ifdef MUCH_RING_CHECKING
int code = _ring_corrupt(self, context); int code = _ring_corrupt(self, context);
if (code) { if (code) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
...@@ -1046,11 +1056,9 @@ ring_corrupt(ccobject *self, const char *context) ...@@ -1046,11 +1056,9 @@ ring_corrupt(ccobject *self, const char *context)
code, context, PyDict_Size(self->data)); code, context, PyDict_Size(self->data));
return code; return code;
} }
#endif
return 0; return 0;
} }
#ifdef MUCH_RING_CHECKING
static int static int
present_in_ring(ccobject *self,CPersistentRing *target) present_in_ring(ccobject *self,CPersistentRing *target)
{ {
...@@ -1063,7 +1071,7 @@ present_in_ring(ccobject *self,CPersistentRing *target) ...@@ -1063,7 +1071,7 @@ present_in_ring(ccobject *self,CPersistentRing *target)
here = here->next; here = here->next;
} }
} }
#endif #endif /* MUCH_RING_CHECKING */
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
(inquiry)cc_length, /*mp_length*/ (inquiry)cc_length, /*mp_length*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment