Commit 5cf0f1a3 authored by Jim Fulton's avatar Jim Fulton

Added code to be more conservative about GCing.

Fixed setattr bugs.
parent 37130a76
/* /*
$Id: cPickleCache.c,v 1.3 1997/03/28 20:18:34 jim Exp $ $Id: cPickleCache.c,v 1.4 1997/04/11 19:13:21 jim Exp $
C implementation of a pickle jar cache. C implementation of a pickle jar cache.
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
(540) 371-6909 (540) 371-6909
***************************************************************************/ ***************************************************************************/
static char *what_string = "$Id: cPickleCache.c,v 1.3 1997/03/28 20:18:34 jim Exp $"; static char *what_string = "$Id: cPickleCache.c,v 1.4 1997/04/11 19:13:21 jim Exp $";
#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))
...@@ -159,7 +159,7 @@ reallyfullgc(ccobject *self) ...@@ -159,7 +159,7 @@ reallyfullgc(ccobject *self)
} }
static int static int
maybegc(ccobject *self) maybegc(ccobject *self, PyObject *thisv)
{ {
int n, s; int n, s;
time_t now,dt; time_t now,dt;
...@@ -177,7 +177,7 @@ maybegc(ccobject *self) ...@@ -177,7 +177,7 @@ maybegc(ccobject *self)
{ {
if(PyDict_Next(self->data, &(self->position), &key, &v)) if(PyDict_Next(self->data, &(self->position), &key, &v))
{ {
if(gc_item(self,key,v,now,dt) < 0) return -1; if(v != thisv && gc_item(self,key,v,now,dt) < 0) return -1;
} }
else else
self->position=0; self->position=0;
...@@ -245,6 +245,15 @@ static PyObject * ...@@ -245,6 +245,15 @@ static PyObject *
cc_getattr(ccobject *self, char *name) cc_getattr(ccobject *self, char *name)
{ {
PyObject *r; PyObject *r;
if(*name=='c')
{
if(strcmp(name,"cache_age")==0)
return PyInt_FromLong(self->cache_age);
if(strcmp(name,"cache_size")==0)
return PyInt_FromLong(self->cache_size);
}
if(r=Py_FindMethod(cc_methods, (PyObject *)self, name)) if(r=Py_FindMethod(cc_methods, (PyObject *)self, name))
return r; return r;
PyErr_Clear(); PyErr_Clear();
...@@ -260,16 +269,16 @@ cc_setattr(ccobject *self, char *name, PyObject *value) ...@@ -260,16 +269,16 @@ cc_setattr(ccobject *self, char *name, PyObject *value)
if(strcmp(name,"cache_age")==0) if(strcmp(name,"cache_age")==0)
{ {
if(PyArg_Parse(value,"i",&v)) return 0; UNLESS(PyArg_Parse(value,"i",&v)) return -1;
else return -1;
if(v > 0)self->cache_age=v; if(v > 0)self->cache_age=v;
return 0;
} }
if(strcmp(name,"cache_size")==0) if(strcmp(name,"cache_size")==0)
{ {
if(PyArg_Parse(value,"i",&v)) return 0; UNLESS(PyArg_Parse(value,"i",&v)) return -1;
else return -1;
if(v > 0)self->cache_size=v; if(v > 0)self->cache_size=v;
return 0;
} }
} }
PyErr_SetString(PyExc_AttributeError, name); PyErr_SetString(PyExc_AttributeError, name);
...@@ -308,7 +317,7 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -308,7 +317,7 @@ cc_subscript(ccobject *self, PyObject *key)
PyErr_SetObject(PyExc_KeyError, key); PyErr_SetObject(PyExc_KeyError, key);
return NULL; return NULL;
} }
UNLESS(-1 != maybegc(self)) UNLESS(-1 != maybegc(self,r))
{ {
Py_DECREF(r); Py_DECREF(r);
return NULL; return NULL;
...@@ -343,13 +352,14 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v) ...@@ -343,13 +352,14 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v)
PyErr_Clear(); PyErr_Clear();
UNLESS(-1 != PyDict_SetItem(self->data,key,t)) return -1; UNLESS(-1 != PyDict_SetItem(self->data,key,t)) return -1;
return maybegc(self, t);
Py_DECREF(t); Py_DECREF(t);
} }
else else
{ {
UNLESS(-1 != PyDict_DelItem(self->data,key)) return -1; UNLESS(-1 != PyDict_DelItem(self->data,key)) return -1;
return maybegc(self, NULL);
} }
return maybegc(self);
} }
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
...@@ -426,7 +436,7 @@ void ...@@ -426,7 +436,7 @@ void
initcPickleCache() initcPickleCache()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.3 $"; char *rev="$Revision: 1.4 $";
Cctype.ob_type=&PyType_Type; Cctype.ob_type=&PyType_Type;
...@@ -454,6 +464,10 @@ initcPickleCache() ...@@ -454,6 +464,10 @@ initcPickleCache()
/****************************************************************************** /******************************************************************************
$Log: cPickleCache.c,v $ $Log: cPickleCache.c,v $
Revision 1.4 1997/04/11 19:13:21 jim
Added code to be more conservative about GCing.
Fixed setattr bugs.
Revision 1.3 1997/03/28 20:18:34 jim Revision 1.3 1997/03/28 20:18:34 jim
Simplified reinit logic. Simplified reinit logic.
......
/* /*
$Id: cPickleCache.c,v 1.3 1997/03/28 20:18:34 jim Exp $ $Id: cPickleCache.c,v 1.4 1997/04/11 19:13:21 jim Exp $
C implementation of a pickle jar cache. C implementation of a pickle jar cache.
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
(540) 371-6909 (540) 371-6909
***************************************************************************/ ***************************************************************************/
static char *what_string = "$Id: cPickleCache.c,v 1.3 1997/03/28 20:18:34 jim Exp $"; static char *what_string = "$Id: cPickleCache.c,v 1.4 1997/04/11 19:13:21 jim Exp $";
#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))
...@@ -159,7 +159,7 @@ reallyfullgc(ccobject *self) ...@@ -159,7 +159,7 @@ reallyfullgc(ccobject *self)
} }
static int static int
maybegc(ccobject *self) maybegc(ccobject *self, PyObject *thisv)
{ {
int n, s; int n, s;
time_t now,dt; time_t now,dt;
...@@ -177,7 +177,7 @@ maybegc(ccobject *self) ...@@ -177,7 +177,7 @@ maybegc(ccobject *self)
{ {
if(PyDict_Next(self->data, &(self->position), &key, &v)) if(PyDict_Next(self->data, &(self->position), &key, &v))
{ {
if(gc_item(self,key,v,now,dt) < 0) return -1; if(v != thisv && gc_item(self,key,v,now,dt) < 0) return -1;
} }
else else
self->position=0; self->position=0;
...@@ -245,6 +245,15 @@ static PyObject * ...@@ -245,6 +245,15 @@ static PyObject *
cc_getattr(ccobject *self, char *name) cc_getattr(ccobject *self, char *name)
{ {
PyObject *r; PyObject *r;
if(*name=='c')
{
if(strcmp(name,"cache_age")==0)
return PyInt_FromLong(self->cache_age);
if(strcmp(name,"cache_size")==0)
return PyInt_FromLong(self->cache_size);
}
if(r=Py_FindMethod(cc_methods, (PyObject *)self, name)) if(r=Py_FindMethod(cc_methods, (PyObject *)self, name))
return r; return r;
PyErr_Clear(); PyErr_Clear();
...@@ -260,16 +269,16 @@ cc_setattr(ccobject *self, char *name, PyObject *value) ...@@ -260,16 +269,16 @@ cc_setattr(ccobject *self, char *name, PyObject *value)
if(strcmp(name,"cache_age")==0) if(strcmp(name,"cache_age")==0)
{ {
if(PyArg_Parse(value,"i",&v)) return 0; UNLESS(PyArg_Parse(value,"i",&v)) return -1;
else return -1;
if(v > 0)self->cache_age=v; if(v > 0)self->cache_age=v;
return 0;
} }
if(strcmp(name,"cache_size")==0) if(strcmp(name,"cache_size")==0)
{ {
if(PyArg_Parse(value,"i",&v)) return 0; UNLESS(PyArg_Parse(value,"i",&v)) return -1;
else return -1;
if(v > 0)self->cache_size=v; if(v > 0)self->cache_size=v;
return 0;
} }
} }
PyErr_SetString(PyExc_AttributeError, name); PyErr_SetString(PyExc_AttributeError, name);
...@@ -308,7 +317,7 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -308,7 +317,7 @@ cc_subscript(ccobject *self, PyObject *key)
PyErr_SetObject(PyExc_KeyError, key); PyErr_SetObject(PyExc_KeyError, key);
return NULL; return NULL;
} }
UNLESS(-1 != maybegc(self)) UNLESS(-1 != maybegc(self,r))
{ {
Py_DECREF(r); Py_DECREF(r);
return NULL; return NULL;
...@@ -343,13 +352,14 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v) ...@@ -343,13 +352,14 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v)
PyErr_Clear(); PyErr_Clear();
UNLESS(-1 != PyDict_SetItem(self->data,key,t)) return -1; UNLESS(-1 != PyDict_SetItem(self->data,key,t)) return -1;
return maybegc(self, t);
Py_DECREF(t); Py_DECREF(t);
} }
else else
{ {
UNLESS(-1 != PyDict_DelItem(self->data,key)) return -1; UNLESS(-1 != PyDict_DelItem(self->data,key)) return -1;
return maybegc(self, NULL);
} }
return maybegc(self);
} }
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
...@@ -426,7 +436,7 @@ void ...@@ -426,7 +436,7 @@ void
initcPickleCache() initcPickleCache()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.3 $"; char *rev="$Revision: 1.4 $";
Cctype.ob_type=&PyType_Type; Cctype.ob_type=&PyType_Type;
...@@ -454,6 +464,10 @@ initcPickleCache() ...@@ -454,6 +464,10 @@ initcPickleCache()
/****************************************************************************** /******************************************************************************
$Log: cPickleCache.c,v $ $Log: cPickleCache.c,v $
Revision 1.4 1997/04/11 19:13:21 jim
Added code to be more conservative about GCing.
Fixed setattr bugs.
Revision 1.3 1997/03/28 20:18:34 jim Revision 1.3 1997/03/28 20:18:34 jim
Simplified reinit logic. Simplified reinit logic.
......
/* /*
$Id: cPickleCache.c,v 1.3 1997/03/28 20:18:34 jim Exp $ $Id: cPickleCache.c,v 1.4 1997/04/11 19:13:21 jim Exp $
C implementation of a pickle jar cache. C implementation of a pickle jar cache.
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
(540) 371-6909 (540) 371-6909
***************************************************************************/ ***************************************************************************/
static char *what_string = "$Id: cPickleCache.c,v 1.3 1997/03/28 20:18:34 jim Exp $"; static char *what_string = "$Id: cPickleCache.c,v 1.4 1997/04/11 19:13:21 jim Exp $";
#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))
...@@ -159,7 +159,7 @@ reallyfullgc(ccobject *self) ...@@ -159,7 +159,7 @@ reallyfullgc(ccobject *self)
} }
static int static int
maybegc(ccobject *self) maybegc(ccobject *self, PyObject *thisv)
{ {
int n, s; int n, s;
time_t now,dt; time_t now,dt;
...@@ -177,7 +177,7 @@ maybegc(ccobject *self) ...@@ -177,7 +177,7 @@ maybegc(ccobject *self)
{ {
if(PyDict_Next(self->data, &(self->position), &key, &v)) if(PyDict_Next(self->data, &(self->position), &key, &v))
{ {
if(gc_item(self,key,v,now,dt) < 0) return -1; if(v != thisv && gc_item(self,key,v,now,dt) < 0) return -1;
} }
else else
self->position=0; self->position=0;
...@@ -245,6 +245,15 @@ static PyObject * ...@@ -245,6 +245,15 @@ static PyObject *
cc_getattr(ccobject *self, char *name) cc_getattr(ccobject *self, char *name)
{ {
PyObject *r; PyObject *r;
if(*name=='c')
{
if(strcmp(name,"cache_age")==0)
return PyInt_FromLong(self->cache_age);
if(strcmp(name,"cache_size")==0)
return PyInt_FromLong(self->cache_size);
}
if(r=Py_FindMethod(cc_methods, (PyObject *)self, name)) if(r=Py_FindMethod(cc_methods, (PyObject *)self, name))
return r; return r;
PyErr_Clear(); PyErr_Clear();
...@@ -260,16 +269,16 @@ cc_setattr(ccobject *self, char *name, PyObject *value) ...@@ -260,16 +269,16 @@ cc_setattr(ccobject *self, char *name, PyObject *value)
if(strcmp(name,"cache_age")==0) if(strcmp(name,"cache_age")==0)
{ {
if(PyArg_Parse(value,"i",&v)) return 0; UNLESS(PyArg_Parse(value,"i",&v)) return -1;
else return -1;
if(v > 0)self->cache_age=v; if(v > 0)self->cache_age=v;
return 0;
} }
if(strcmp(name,"cache_size")==0) if(strcmp(name,"cache_size")==0)
{ {
if(PyArg_Parse(value,"i",&v)) return 0; UNLESS(PyArg_Parse(value,"i",&v)) return -1;
else return -1;
if(v > 0)self->cache_size=v; if(v > 0)self->cache_size=v;
return 0;
} }
} }
PyErr_SetString(PyExc_AttributeError, name); PyErr_SetString(PyExc_AttributeError, name);
...@@ -308,7 +317,7 @@ cc_subscript(ccobject *self, PyObject *key) ...@@ -308,7 +317,7 @@ cc_subscript(ccobject *self, PyObject *key)
PyErr_SetObject(PyExc_KeyError, key); PyErr_SetObject(PyExc_KeyError, key);
return NULL; return NULL;
} }
UNLESS(-1 != maybegc(self)) UNLESS(-1 != maybegc(self,r))
{ {
Py_DECREF(r); Py_DECREF(r);
return NULL; return NULL;
...@@ -343,13 +352,14 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v) ...@@ -343,13 +352,14 @@ cc_ass_sub(ccobject *self, PyObject *key, PyObject *v)
PyErr_Clear(); PyErr_Clear();
UNLESS(-1 != PyDict_SetItem(self->data,key,t)) return -1; UNLESS(-1 != PyDict_SetItem(self->data,key,t)) return -1;
return maybegc(self, t);
Py_DECREF(t); Py_DECREF(t);
} }
else else
{ {
UNLESS(-1 != PyDict_DelItem(self->data,key)) return -1; UNLESS(-1 != PyDict_DelItem(self->data,key)) return -1;
return maybegc(self, NULL);
} }
return maybegc(self);
} }
static PyMappingMethods cc_as_mapping = { static PyMappingMethods cc_as_mapping = {
...@@ -426,7 +436,7 @@ void ...@@ -426,7 +436,7 @@ void
initcPickleCache() initcPickleCache()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.3 $"; char *rev="$Revision: 1.4 $";
Cctype.ob_type=&PyType_Type; Cctype.ob_type=&PyType_Type;
...@@ -454,6 +464,10 @@ initcPickleCache() ...@@ -454,6 +464,10 @@ initcPickleCache()
/****************************************************************************** /******************************************************************************
$Log: cPickleCache.c,v $ $Log: cPickleCache.c,v $
Revision 1.4 1997/04/11 19:13:21 jim
Added code to be more conservative about GCing.
Fixed setattr bugs.
Revision 1.3 1997/03/28 20:18:34 jim Revision 1.3 1997/03/28 20:18:34 jim
Simplified reinit logic. Simplified reinit logic.
......
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