Commit bbd033c3 authored by Jeremy Hylton's avatar Jeremy Hylton

More reformatting to match Python C style.

parent 32968b3e
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
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.47 2002/04/02 14:35:36 gvanrossum Exp $\n"; "$Id: cPickleCache.c,v 1.48 2002/04/02 19:47:19 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))
...@@ -641,10 +641,11 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -641,10 +641,11 @@ cc_subscript(ccobject *self, PyObject *key)
{ {
PyObject *r; PyObject *r;
if(check_ring(self,"__getitem__")) return NULL; if (check_ring(self, "__getitem__"))
return NULL;
UNLESS (r=(PyObject *)object_from_oid(self, key)) r = (PyObject *)object_from_oid(self, key);
{ if (r == NULL) {
PyErr_SetObject(PyExc_KeyError, key); PyErr_SetObject(PyExc_KeyError, key);
return NULL; return NULL;
} }
...@@ -815,10 +816,10 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v) ...@@ -815,10 +816,10 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v)
} }
static int static int
_check_ring(ccobject *self,const char *context) _check_ring(ccobject *self, const char *context)
{ {
CPersistentRing *here = &(self->ring_home); CPersistentRing *here = &(self->ring_home);
int expected = 1+self->non_ghost_count; int expected = 1 + self->non_ghost_count;
int total = 0; int total = 0;
do { do {
if (++total > (expected + 10)) if (++total > (expected + 10))
...@@ -835,31 +836,28 @@ _check_ring(ccobject *self,const char *context) ...@@ -835,31 +836,28 @@ _check_ring(ccobject *self,const char *context)
return 9; return 9;
if (here->next->prev != here) if (here->next->prev != here)
return 10; return 10;
if (!self->ring_lock) if (!self->ring_lock) {
{
/* if the ring must be locked then it only contains object other than persistent instances */ /* if the ring must be locked then it only contains object other than persistent instances */
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) return 12; if (!object)
if (object->state==cPersistent_GHOST_STATE) return 12;
if (object->state == cPersistent_GHOST_STATE)
return 13; return 13;
} }
} }
here = here->next; here = here->next;
} } while (here != &self->ring_home);
while(here!=&self->ring_home);
if (self->ring_lock) if (self->ring_lock) {
{ if (total < expected)
if (total<expected) return 6; /* ring too small; too big is ok when locked */ return 6; /* ring too small; too big is ok when locked */
} } else {
else if (total != expected)
{ return 14; /* ring size wrong, or bad ghost accounting */
if (total!=expected) return 14; /* ring size wrong, or bad ghost accounting */
} }
return 0; return 0;
} }
...@@ -889,22 +887,15 @@ static int ...@@ -889,22 +887,15 @@ static int
present_in_ring(ccobject *self,CPersistentRing *target) present_in_ring(ccobject *self,CPersistentRing *target)
{ {
CPersistentRing *here = self->ring_home.next; CPersistentRing *here = self->ring_home.next;
while(1) while (1) {
{ if (here == target)
if (here==target)
{
return 1; return 1;
} if (here == &self->ring_home)
if (here==&self->ring_home) return 0; /* back to the home position, and we didnt find it */
{
/* back to the home position, and we didnt find it */
return 0;
}
here = here->next; here = here->next;
} }
} }
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
(inquiry)cc_length, /*mp_length*/ (inquiry)cc_length, /*mp_length*/
(binaryfunc)cc_subscript, /*mp_subscript*/ (binaryfunc)cc_subscript, /*mp_subscript*/
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
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.47 2002/04/02 14:35:36 gvanrossum Exp $\n"; "$Id: cPickleCache.c,v 1.48 2002/04/02 19:47:19 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))
...@@ -641,10 +641,11 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -641,10 +641,11 @@ cc_subscript(ccobject *self, PyObject *key)
{ {
PyObject *r; PyObject *r;
if(check_ring(self,"__getitem__")) return NULL; if (check_ring(self, "__getitem__"))
return NULL;
UNLESS (r=(PyObject *)object_from_oid(self, key)) r = (PyObject *)object_from_oid(self, key);
{ if (r == NULL) {
PyErr_SetObject(PyExc_KeyError, key); PyErr_SetObject(PyExc_KeyError, key);
return NULL; return NULL;
} }
...@@ -815,10 +816,10 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v) ...@@ -815,10 +816,10 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v)
} }
static int static int
_check_ring(ccobject *self,const char *context) _check_ring(ccobject *self, const char *context)
{ {
CPersistentRing *here = &(self->ring_home); CPersistentRing *here = &(self->ring_home);
int expected = 1+self->non_ghost_count; int expected = 1 + self->non_ghost_count;
int total = 0; int total = 0;
do { do {
if (++total > (expected + 10)) if (++total > (expected + 10))
...@@ -835,31 +836,28 @@ _check_ring(ccobject *self,const char *context) ...@@ -835,31 +836,28 @@ _check_ring(ccobject *self,const char *context)
return 9; return 9;
if (here->next->prev != here) if (here->next->prev != here)
return 10; return 10;
if (!self->ring_lock) if (!self->ring_lock) {
{
/* if the ring must be locked then it only contains object other than persistent instances */ /* if the ring must be locked then it only contains object other than persistent instances */
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) return 12; if (!object)
if (object->state==cPersistent_GHOST_STATE) return 12;
if (object->state == cPersistent_GHOST_STATE)
return 13; return 13;
} }
} }
here = here->next; here = here->next;
} } while (here != &self->ring_home);
while(here!=&self->ring_home);
if (self->ring_lock) if (self->ring_lock) {
{ if (total < expected)
if (total<expected) return 6; /* ring too small; too big is ok when locked */ return 6; /* ring too small; too big is ok when locked */
} } else {
else if (total != expected)
{ return 14; /* ring size wrong, or bad ghost accounting */
if (total!=expected) return 14; /* ring size wrong, or bad ghost accounting */
} }
return 0; return 0;
} }
...@@ -889,22 +887,15 @@ static int ...@@ -889,22 +887,15 @@ static int
present_in_ring(ccobject *self,CPersistentRing *target) present_in_ring(ccobject *self,CPersistentRing *target)
{ {
CPersistentRing *here = self->ring_home.next; CPersistentRing *here = self->ring_home.next;
while(1) while (1) {
{ if (here == target)
if (here==target)
{
return 1; return 1;
} if (here == &self->ring_home)
if (here==&self->ring_home) return 0; /* back to the home position, and we didnt find it */
{
/* back to the home position, and we didnt find it */
return 0;
}
here = here->next; here = here->next;
} }
} }
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
(inquiry)cc_length, /*mp_length*/ (inquiry)cc_length, /*mp_length*/
(binaryfunc)cc_subscript, /*mp_subscript*/ (binaryfunc)cc_subscript, /*mp_subscript*/
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
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.47 2002/04/02 14:35:36 gvanrossum Exp $\n"; "$Id: cPickleCache.c,v 1.48 2002/04/02 19:47:19 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))
...@@ -641,10 +641,11 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -641,10 +641,11 @@ cc_subscript(ccobject *self, PyObject *key)
{ {
PyObject *r; PyObject *r;
if(check_ring(self,"__getitem__")) return NULL; if (check_ring(self, "__getitem__"))
return NULL;
UNLESS (r=(PyObject *)object_from_oid(self, key)) r = (PyObject *)object_from_oid(self, key);
{ if (r == NULL) {
PyErr_SetObject(PyExc_KeyError, key); PyErr_SetObject(PyExc_KeyError, key);
return NULL; return NULL;
} }
...@@ -815,10 +816,10 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v) ...@@ -815,10 +816,10 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v)
} }
static int static int
_check_ring(ccobject *self,const char *context) _check_ring(ccobject *self, const char *context)
{ {
CPersistentRing *here = &(self->ring_home); CPersistentRing *here = &(self->ring_home);
int expected = 1+self->non_ghost_count; int expected = 1 + self->non_ghost_count;
int total = 0; int total = 0;
do { do {
if (++total > (expected + 10)) if (++total > (expected + 10))
...@@ -835,31 +836,28 @@ _check_ring(ccobject *self,const char *context) ...@@ -835,31 +836,28 @@ _check_ring(ccobject *self,const char *context)
return 9; return 9;
if (here->next->prev != here) if (here->next->prev != here)
return 10; return 10;
if (!self->ring_lock) if (!self->ring_lock) {
{
/* if the ring must be locked then it only contains object other than persistent instances */ /* if the ring must be locked then it only contains object other than persistent instances */
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) return 12; if (!object)
if (object->state==cPersistent_GHOST_STATE) return 12;
if (object->state == cPersistent_GHOST_STATE)
return 13; return 13;
} }
} }
here = here->next; here = here->next;
} } while (here != &self->ring_home);
while(here!=&self->ring_home);
if (self->ring_lock) if (self->ring_lock) {
{ if (total < expected)
if (total<expected) return 6; /* ring too small; too big is ok when locked */ return 6; /* ring too small; too big is ok when locked */
} } else {
else if (total != expected)
{ return 14; /* ring size wrong, or bad ghost accounting */
if (total!=expected) return 14; /* ring size wrong, or bad ghost accounting */
} }
return 0; return 0;
} }
...@@ -889,22 +887,15 @@ static int ...@@ -889,22 +887,15 @@ static int
present_in_ring(ccobject *self,CPersistentRing *target) present_in_ring(ccobject *self,CPersistentRing *target)
{ {
CPersistentRing *here = self->ring_home.next; CPersistentRing *here = self->ring_home.next;
while(1) while (1) {
{ if (here == target)
if (here==target)
{
return 1; return 1;
} if (here == &self->ring_home)
if (here==&self->ring_home) return 0; /* back to the home position, and we didnt find it */
{
/* back to the home position, and we didnt find it */
return 0;
}
here = here->next; here = here->next;
} }
} }
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
(inquiry)cc_length, /*mp_length*/ (inquiry)cc_length, /*mp_length*/
(binaryfunc)cc_subscript, /*mp_subscript*/ (binaryfunc)cc_subscript, /*mp_subscript*/
......
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