Commit d27670f8 authored by Jim Fulton's avatar Jim Fulton

Changed object header layout and added sticky feature.

parent 226f3bb6
/* /*
$Id: cPersistence.c,v 1.9 1997/04/03 17:34:14 jim Exp $ $Id: cPersistence.c,v 1.10 1997/04/22 02:40:03 jim Exp $
C Persistence Module C Persistence Module
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
*****************************************************************************/ *****************************************************************************/
static char *what_string = "$Id: cPersistence.c,v 1.9 1997/04/03 17:34:14 jim Exp $"; static char *what_string = "$Id: cPersistence.c,v 1.10 1997/04/22 02:40:03 jim Exp $";
#include <time.h> #include <time.h>
#include "cPersistence.h" #include "cPersistence.h"
...@@ -175,12 +175,17 @@ PyString_BuildFormat(va_alist) va_dcl ...@@ -175,12 +175,17 @@ PyString_BuildFormat(va_alist) va_dcl
/****************************************************************************/ /****************************************************************************/
static void static void
PATime_dealloc(PATimeobject *self){ PyMem_DEL(self);} PATime_dealloc(PATimeobject *self)
{
/*printf("D");*/
Py_DECREF(self->object);
PyMem_DEL(self);}
static PyObject * static PyObject *
PATime_repr(PATimeobject *self) PATime_repr(PATimeobject *self)
{ {
return PyString_BuildFormat("<access time: %d>","i",self->value); return PyString_BuildFormat("<access time: %d>","i",self->object->atime);
} }
static PyTypeObject static PyTypeObject
...@@ -365,12 +370,12 @@ Per__p___init__(self, args) ...@@ -365,12 +370,12 @@ Per__p___init__(self, args)
cPersistentObject *self; cPersistentObject *self;
PyObject *args; PyObject *args;
{ {
PyObject *oid, *jar; int oid;
PyObject *jar;
UNLESS(PyArg_Parse(args, "(OO)", &oid, &jar)) return NULL; UNLESS(PyArg_Parse(args, "(iO)", &oid, &jar)) return NULL;
Py_INCREF(oid);
Py_INCREF(jar); Py_INCREF(jar);
ASSIGN(self->oid, oid); self->oid=oid;
ASSIGN(self->jar, jar); ASSIGN(self->jar, jar);
self->state=GHOST_STATE; self->state=GHOST_STATE;
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -380,10 +385,20 @@ Per__p___init__(self, args) ...@@ -380,10 +385,20 @@ Per__p___init__(self, args)
static PyObject * static PyObject *
Per__p___reinit__(cPersistentObject *self, PyObject *args) Per__p___reinit__(cPersistentObject *self, PyObject *args)
{ {
PyObject *oid, *jar=0, *copy; int oid;
PyObject *jar=0, *copy, *dict;
if(PyArg_Parse(args,"")) if(PyArg_Parse(args,""))
{ {
/*
if(0
|| strcmp(self->ob_type->tp_name,"Classified")==0
)
{
Py_INCREF(Py_None);
return Py_None;
}
*/
if(self->state==cPersistent_UPTODATE_STATE) if(self->state==cPersistent_UPTODATE_STATE)
if(jar=PyObject_GetAttr((PyObject*)self,py___init__)) if(jar=PyObject_GetAttr((PyObject*)self,py___init__))
{ {
...@@ -400,7 +415,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -400,7 +415,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
} }
else copy=NULL; else copy=NULL;
if((oid=INSTANCE_DICT(self))) PyDict_Clear(oid); if((dict=INSTANCE_DICT(self))) PyDict_Clear(dict);
ASSIGN(copy,PyObject_CallObject(jar,copy)); ASSIGN(copy,PyObject_CallObject(jar,copy));
self->state=cPersistent_GHOST_STATE; self->state=cPersistent_GHOST_STATE;
...@@ -408,9 +423,9 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -408,9 +423,9 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
Py_DECREF(copy); Py_DECREF(copy);
Py_DECREF(jar); Py_DECREF(jar);
} }
else if((oid=INSTANCE_DICT(self))) else if((dict=INSTANCE_DICT(self)))
{ {
PyDict_Clear(oid); PyDict_Clear(dict);
self->state=cPersistent_GHOST_STATE; self->state=cPersistent_GHOST_STATE;
} }
} }
...@@ -418,14 +433,8 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -418,14 +433,8 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
{ {
PyErr_Clear(); PyErr_Clear();
UNLESS(PyArg_Parse(args, "(OOO)", &oid, &jar, &copy)) return NULL; UNLESS(PyArg_Parse(args, "O", &copy)) return NULL;
UNLESS(self->oid) if(self->state==cPersistent_UPTODATE_STATE)
{
Py_INCREF(oid);
ASSIGN(self->oid, oid);
}
if((self->oid==oid || PyObject_Compare(self->oid, oid)==0)
&& self->state==cPersistent_UPTODATE_STATE)
{ {
UNLESS(args=PyObject_GetAttr(copy,py___dict__)) return NULL; UNLESS(args=PyObject_GetAttr(copy,py___dict__)) return NULL;
ASSIGN(INSTANCE_DICT(self),args); ASSIGN(INSTANCE_DICT(self),args);
...@@ -434,7 +443,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -434,7 +443,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
err: err:
Py_XDECREF(jar); Py_XDECREF(jar);
return NULL; return NULL;
} }
...@@ -519,6 +528,8 @@ Per__setstate__(self,args) ...@@ -519,6 +528,8 @@ Per__setstate__(self,args)
PyObject *__dict__, *v, *keys=0, *key=0, *e=0; PyObject *__dict__, *v, *keys=0, *key=0, *e=0;
int l, i; int l, i;
printf("%s(%d) ", self->ob_type->tp_name,self->oid);
UNLESS(PyArg_Parse(args, "O", &v)) return NULL; UNLESS(PyArg_Parse(args, "O", &v)) return NULL;
self->state=UPTODATE_STATE; self->state=UPTODATE_STATE;
if(v!=Py_None) if(v!=Py_None)
...@@ -579,29 +590,27 @@ static void ...@@ -579,29 +590,27 @@ static void
Per_dealloc(self) Per_dealloc(self)
cPersistentObject *self; cPersistentObject *self;
{ {
Py_XDECREF(self->oid);
Py_XDECREF(self->jar); Py_XDECREF(self->jar);
Py_XDECREF(self->atime); /*Py_XDECREF(self->atime);*/
PyMem_DEL(self); PyMem_DEL(self);
} }
static void static void
Per_set_atime(cPersistentObject *self) Per_set_atime(cPersistentObject *self)
{ {
/* Record access times */ if(self->atime == (time_t)1) return;
UNLESS(self->atime) self->atime = time(NULL);
UNLESS(self->atime=PyObject_NEW(PATimeobject,
&PATimeType))
return;
self->atime->value=time(NULL);
} }
static PyObject * static PyObject *
Per_atime(cPersistentObject *self) Per_atime(cPersistentObject *self)
{ {
UNLESS(self->atime) Per_set_atime(self); PATimeobject *r;
Py_XINCREF(self->atime);
return (PyObject*)self->atime; UNLESS(r=PyObject_NEW(PATimeobject,&PATimeType)) return NULL;
Py_INCREF(self);
r->object=self;
return (PyObject*)r;
} }
static PyObject * static PyObject *
...@@ -619,8 +628,7 @@ Per_getattr(cPersistentObject *self, PyObject *oname, char *name) ...@@ -619,8 +628,7 @@ Per_getattr(cPersistentObject *self, PyObject *oname, char *name)
{ {
if(self->oid) if(self->oid)
{ {
Py_INCREF(self->oid); return PyInt_FromLong(self->oid);
return self->oid;
} }
else else
{ {
...@@ -720,8 +728,8 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v) ...@@ -720,8 +728,8 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v)
{ {
if(name[3]=='o' && name[4]=='i' && name[5]=='d' && ! name[6]) if(name[3]=='o' && name[4]=='i' && name[5]=='d' && ! name[6])
{ {
ASSIGN(self->oid, v); if(PyInt_Check(v)) self->oid=PyInt_AsLong(v);
Py_INCREF(self->oid); else self->oid=0;
return 0; return 0;
} }
if(name[3]=='j' && name[4]=='a' && name[5]=='r' && ! name[6]) if(name[3]=='j' && name[4]=='a' && name[5]=='r' && ! name[6])
...@@ -735,6 +743,11 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v) ...@@ -735,6 +743,11 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v)
self->state=PyObject_IsTrue(v); self->state=PyObject_IsTrue(v);
return 0; return 0;
} }
if(strcmp(name+3,"atime")==0)
{
self->atime=(time_t)1;
return 0;
}
} }
else else
{ {
...@@ -841,7 +854,7 @@ void ...@@ -841,7 +854,7 @@ void
initcPersistence() initcPersistence()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.9 $"; char *rev="$Revision: 1.10 $";
PATimeType.ob_type=&PyType_Type; PATimeType.ob_type=&PyType_Type;
...@@ -868,6 +881,9 @@ initcPersistence() ...@@ -868,6 +881,9 @@ initcPersistence()
/**************************************************************************** /****************************************************************************
$Log: cPersistence.c,v $ $Log: cPersistence.c,v $
Revision 1.10 1997/04/22 02:40:03 jim
Changed object header layout and added sticky feature.
Revision 1.9 1997/04/03 17:34:14 jim Revision 1.9 1997/04/03 17:34:14 jim
Changed to pass transaction to jar store method during commit. Changed to pass transaction to jar store method during commit.
......
/* /*
$Id: cPersistence.c,v 1.9 1997/04/03 17:34:14 jim Exp $ $Id: cPersistence.c,v 1.10 1997/04/22 02:40:03 jim Exp $
C Persistence Module C Persistence Module
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
*****************************************************************************/ *****************************************************************************/
static char *what_string = "$Id: cPersistence.c,v 1.9 1997/04/03 17:34:14 jim Exp $"; static char *what_string = "$Id: cPersistence.c,v 1.10 1997/04/22 02:40:03 jim Exp $";
#include <time.h> #include <time.h>
#include "cPersistence.h" #include "cPersistence.h"
...@@ -175,12 +175,17 @@ PyString_BuildFormat(va_alist) va_dcl ...@@ -175,12 +175,17 @@ PyString_BuildFormat(va_alist) va_dcl
/****************************************************************************/ /****************************************************************************/
static void static void
PATime_dealloc(PATimeobject *self){ PyMem_DEL(self);} PATime_dealloc(PATimeobject *self)
{
/*printf("D");*/
Py_DECREF(self->object);
PyMem_DEL(self);}
static PyObject * static PyObject *
PATime_repr(PATimeobject *self) PATime_repr(PATimeobject *self)
{ {
return PyString_BuildFormat("<access time: %d>","i",self->value); return PyString_BuildFormat("<access time: %d>","i",self->object->atime);
} }
static PyTypeObject static PyTypeObject
...@@ -365,12 +370,12 @@ Per__p___init__(self, args) ...@@ -365,12 +370,12 @@ Per__p___init__(self, args)
cPersistentObject *self; cPersistentObject *self;
PyObject *args; PyObject *args;
{ {
PyObject *oid, *jar; int oid;
PyObject *jar;
UNLESS(PyArg_Parse(args, "(OO)", &oid, &jar)) return NULL; UNLESS(PyArg_Parse(args, "(iO)", &oid, &jar)) return NULL;
Py_INCREF(oid);
Py_INCREF(jar); Py_INCREF(jar);
ASSIGN(self->oid, oid); self->oid=oid;
ASSIGN(self->jar, jar); ASSIGN(self->jar, jar);
self->state=GHOST_STATE; self->state=GHOST_STATE;
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -380,10 +385,20 @@ Per__p___init__(self, args) ...@@ -380,10 +385,20 @@ Per__p___init__(self, args)
static PyObject * static PyObject *
Per__p___reinit__(cPersistentObject *self, PyObject *args) Per__p___reinit__(cPersistentObject *self, PyObject *args)
{ {
PyObject *oid, *jar=0, *copy; int oid;
PyObject *jar=0, *copy, *dict;
if(PyArg_Parse(args,"")) if(PyArg_Parse(args,""))
{ {
/*
if(0
|| strcmp(self->ob_type->tp_name,"Classified")==0
)
{
Py_INCREF(Py_None);
return Py_None;
}
*/
if(self->state==cPersistent_UPTODATE_STATE) if(self->state==cPersistent_UPTODATE_STATE)
if(jar=PyObject_GetAttr((PyObject*)self,py___init__)) if(jar=PyObject_GetAttr((PyObject*)self,py___init__))
{ {
...@@ -400,7 +415,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -400,7 +415,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
} }
else copy=NULL; else copy=NULL;
if((oid=INSTANCE_DICT(self))) PyDict_Clear(oid); if((dict=INSTANCE_DICT(self))) PyDict_Clear(dict);
ASSIGN(copy,PyObject_CallObject(jar,copy)); ASSIGN(copy,PyObject_CallObject(jar,copy));
self->state=cPersistent_GHOST_STATE; self->state=cPersistent_GHOST_STATE;
...@@ -408,9 +423,9 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -408,9 +423,9 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
Py_DECREF(copy); Py_DECREF(copy);
Py_DECREF(jar); Py_DECREF(jar);
} }
else if((oid=INSTANCE_DICT(self))) else if((dict=INSTANCE_DICT(self)))
{ {
PyDict_Clear(oid); PyDict_Clear(dict);
self->state=cPersistent_GHOST_STATE; self->state=cPersistent_GHOST_STATE;
} }
} }
...@@ -418,14 +433,8 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -418,14 +433,8 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
{ {
PyErr_Clear(); PyErr_Clear();
UNLESS(PyArg_Parse(args, "(OOO)", &oid, &jar, &copy)) return NULL; UNLESS(PyArg_Parse(args, "O", &copy)) return NULL;
UNLESS(self->oid) if(self->state==cPersistent_UPTODATE_STATE)
{
Py_INCREF(oid);
ASSIGN(self->oid, oid);
}
if((self->oid==oid || PyObject_Compare(self->oid, oid)==0)
&& self->state==cPersistent_UPTODATE_STATE)
{ {
UNLESS(args=PyObject_GetAttr(copy,py___dict__)) return NULL; UNLESS(args=PyObject_GetAttr(copy,py___dict__)) return NULL;
ASSIGN(INSTANCE_DICT(self),args); ASSIGN(INSTANCE_DICT(self),args);
...@@ -434,7 +443,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -434,7 +443,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
err: err:
Py_XDECREF(jar); Py_XDECREF(jar);
return NULL; return NULL;
} }
...@@ -519,6 +528,8 @@ Per__setstate__(self,args) ...@@ -519,6 +528,8 @@ Per__setstate__(self,args)
PyObject *__dict__, *v, *keys=0, *key=0, *e=0; PyObject *__dict__, *v, *keys=0, *key=0, *e=0;
int l, i; int l, i;
printf("%s(%d) ", self->ob_type->tp_name,self->oid);
UNLESS(PyArg_Parse(args, "O", &v)) return NULL; UNLESS(PyArg_Parse(args, "O", &v)) return NULL;
self->state=UPTODATE_STATE; self->state=UPTODATE_STATE;
if(v!=Py_None) if(v!=Py_None)
...@@ -579,29 +590,27 @@ static void ...@@ -579,29 +590,27 @@ static void
Per_dealloc(self) Per_dealloc(self)
cPersistentObject *self; cPersistentObject *self;
{ {
Py_XDECREF(self->oid);
Py_XDECREF(self->jar); Py_XDECREF(self->jar);
Py_XDECREF(self->atime); /*Py_XDECREF(self->atime);*/
PyMem_DEL(self); PyMem_DEL(self);
} }
static void static void
Per_set_atime(cPersistentObject *self) Per_set_atime(cPersistentObject *self)
{ {
/* Record access times */ if(self->atime == (time_t)1) return;
UNLESS(self->atime) self->atime = time(NULL);
UNLESS(self->atime=PyObject_NEW(PATimeobject,
&PATimeType))
return;
self->atime->value=time(NULL);
} }
static PyObject * static PyObject *
Per_atime(cPersistentObject *self) Per_atime(cPersistentObject *self)
{ {
UNLESS(self->atime) Per_set_atime(self); PATimeobject *r;
Py_XINCREF(self->atime);
return (PyObject*)self->atime; UNLESS(r=PyObject_NEW(PATimeobject,&PATimeType)) return NULL;
Py_INCREF(self);
r->object=self;
return (PyObject*)r;
} }
static PyObject * static PyObject *
...@@ -619,8 +628,7 @@ Per_getattr(cPersistentObject *self, PyObject *oname, char *name) ...@@ -619,8 +628,7 @@ Per_getattr(cPersistentObject *self, PyObject *oname, char *name)
{ {
if(self->oid) if(self->oid)
{ {
Py_INCREF(self->oid); return PyInt_FromLong(self->oid);
return self->oid;
} }
else else
{ {
...@@ -720,8 +728,8 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v) ...@@ -720,8 +728,8 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v)
{ {
if(name[3]=='o' && name[4]=='i' && name[5]=='d' && ! name[6]) if(name[3]=='o' && name[4]=='i' && name[5]=='d' && ! name[6])
{ {
ASSIGN(self->oid, v); if(PyInt_Check(v)) self->oid=PyInt_AsLong(v);
Py_INCREF(self->oid); else self->oid=0;
return 0; return 0;
} }
if(name[3]=='j' && name[4]=='a' && name[5]=='r' && ! name[6]) if(name[3]=='j' && name[4]=='a' && name[5]=='r' && ! name[6])
...@@ -735,6 +743,11 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v) ...@@ -735,6 +743,11 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v)
self->state=PyObject_IsTrue(v); self->state=PyObject_IsTrue(v);
return 0; return 0;
} }
if(strcmp(name+3,"atime")==0)
{
self->atime=(time_t)1;
return 0;
}
} }
else else
{ {
...@@ -841,7 +854,7 @@ void ...@@ -841,7 +854,7 @@ void
initcPersistence() initcPersistence()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.9 $"; char *rev="$Revision: 1.10 $";
PATimeType.ob_type=&PyType_Type; PATimeType.ob_type=&PyType_Type;
...@@ -868,6 +881,9 @@ initcPersistence() ...@@ -868,6 +881,9 @@ initcPersistence()
/**************************************************************************** /****************************************************************************
$Log: cPersistence.c,v $ $Log: cPersistence.c,v $
Revision 1.10 1997/04/22 02:40:03 jim
Changed object header layout and added sticky feature.
Revision 1.9 1997/04/03 17:34:14 jim Revision 1.9 1997/04/03 17:34:14 jim
Changed to pass transaction to jar store method during commit. Changed to pass transaction to jar store method during commit.
......
/* /*
$Id: cPersistence.c,v 1.9 1997/04/03 17:34:14 jim Exp $ $Id: cPersistence.c,v 1.10 1997/04/22 02:40:03 jim Exp $
C Persistence Module C Persistence Module
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
*****************************************************************************/ *****************************************************************************/
static char *what_string = "$Id: cPersistence.c,v 1.9 1997/04/03 17:34:14 jim Exp $"; static char *what_string = "$Id: cPersistence.c,v 1.10 1997/04/22 02:40:03 jim Exp $";
#include <time.h> #include <time.h>
#include "cPersistence.h" #include "cPersistence.h"
...@@ -175,12 +175,17 @@ PyString_BuildFormat(va_alist) va_dcl ...@@ -175,12 +175,17 @@ PyString_BuildFormat(va_alist) va_dcl
/****************************************************************************/ /****************************************************************************/
static void static void
PATime_dealloc(PATimeobject *self){ PyMem_DEL(self);} PATime_dealloc(PATimeobject *self)
{
/*printf("D");*/
Py_DECREF(self->object);
PyMem_DEL(self);}
static PyObject * static PyObject *
PATime_repr(PATimeobject *self) PATime_repr(PATimeobject *self)
{ {
return PyString_BuildFormat("<access time: %d>","i",self->value); return PyString_BuildFormat("<access time: %d>","i",self->object->atime);
} }
static PyTypeObject static PyTypeObject
...@@ -365,12 +370,12 @@ Per__p___init__(self, args) ...@@ -365,12 +370,12 @@ Per__p___init__(self, args)
cPersistentObject *self; cPersistentObject *self;
PyObject *args; PyObject *args;
{ {
PyObject *oid, *jar; int oid;
PyObject *jar;
UNLESS(PyArg_Parse(args, "(OO)", &oid, &jar)) return NULL; UNLESS(PyArg_Parse(args, "(iO)", &oid, &jar)) return NULL;
Py_INCREF(oid);
Py_INCREF(jar); Py_INCREF(jar);
ASSIGN(self->oid, oid); self->oid=oid;
ASSIGN(self->jar, jar); ASSIGN(self->jar, jar);
self->state=GHOST_STATE; self->state=GHOST_STATE;
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -380,10 +385,20 @@ Per__p___init__(self, args) ...@@ -380,10 +385,20 @@ Per__p___init__(self, args)
static PyObject * static PyObject *
Per__p___reinit__(cPersistentObject *self, PyObject *args) Per__p___reinit__(cPersistentObject *self, PyObject *args)
{ {
PyObject *oid, *jar=0, *copy; int oid;
PyObject *jar=0, *copy, *dict;
if(PyArg_Parse(args,"")) if(PyArg_Parse(args,""))
{ {
/*
if(0
|| strcmp(self->ob_type->tp_name,"Classified")==0
)
{
Py_INCREF(Py_None);
return Py_None;
}
*/
if(self->state==cPersistent_UPTODATE_STATE) if(self->state==cPersistent_UPTODATE_STATE)
if(jar=PyObject_GetAttr((PyObject*)self,py___init__)) if(jar=PyObject_GetAttr((PyObject*)self,py___init__))
{ {
...@@ -400,7 +415,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -400,7 +415,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
} }
else copy=NULL; else copy=NULL;
if((oid=INSTANCE_DICT(self))) PyDict_Clear(oid); if((dict=INSTANCE_DICT(self))) PyDict_Clear(dict);
ASSIGN(copy,PyObject_CallObject(jar,copy)); ASSIGN(copy,PyObject_CallObject(jar,copy));
self->state=cPersistent_GHOST_STATE; self->state=cPersistent_GHOST_STATE;
...@@ -408,9 +423,9 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -408,9 +423,9 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
Py_DECREF(copy); Py_DECREF(copy);
Py_DECREF(jar); Py_DECREF(jar);
} }
else if((oid=INSTANCE_DICT(self))) else if((dict=INSTANCE_DICT(self)))
{ {
PyDict_Clear(oid); PyDict_Clear(dict);
self->state=cPersistent_GHOST_STATE; self->state=cPersistent_GHOST_STATE;
} }
} }
...@@ -418,14 +433,8 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -418,14 +433,8 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
{ {
PyErr_Clear(); PyErr_Clear();
UNLESS(PyArg_Parse(args, "(OOO)", &oid, &jar, &copy)) return NULL; UNLESS(PyArg_Parse(args, "O", &copy)) return NULL;
UNLESS(self->oid) if(self->state==cPersistent_UPTODATE_STATE)
{
Py_INCREF(oid);
ASSIGN(self->oid, oid);
}
if((self->oid==oid || PyObject_Compare(self->oid, oid)==0)
&& self->state==cPersistent_UPTODATE_STATE)
{ {
UNLESS(args=PyObject_GetAttr(copy,py___dict__)) return NULL; UNLESS(args=PyObject_GetAttr(copy,py___dict__)) return NULL;
ASSIGN(INSTANCE_DICT(self),args); ASSIGN(INSTANCE_DICT(self),args);
...@@ -434,7 +443,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args) ...@@ -434,7 +443,7 @@ Per__p___reinit__(cPersistentObject *self, PyObject *args)
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
err: err:
Py_XDECREF(jar); Py_XDECREF(jar);
return NULL; return NULL;
} }
...@@ -519,6 +528,8 @@ Per__setstate__(self,args) ...@@ -519,6 +528,8 @@ Per__setstate__(self,args)
PyObject *__dict__, *v, *keys=0, *key=0, *e=0; PyObject *__dict__, *v, *keys=0, *key=0, *e=0;
int l, i; int l, i;
printf("%s(%d) ", self->ob_type->tp_name,self->oid);
UNLESS(PyArg_Parse(args, "O", &v)) return NULL; UNLESS(PyArg_Parse(args, "O", &v)) return NULL;
self->state=UPTODATE_STATE; self->state=UPTODATE_STATE;
if(v!=Py_None) if(v!=Py_None)
...@@ -579,29 +590,27 @@ static void ...@@ -579,29 +590,27 @@ static void
Per_dealloc(self) Per_dealloc(self)
cPersistentObject *self; cPersistentObject *self;
{ {
Py_XDECREF(self->oid);
Py_XDECREF(self->jar); Py_XDECREF(self->jar);
Py_XDECREF(self->atime); /*Py_XDECREF(self->atime);*/
PyMem_DEL(self); PyMem_DEL(self);
} }
static void static void
Per_set_atime(cPersistentObject *self) Per_set_atime(cPersistentObject *self)
{ {
/* Record access times */ if(self->atime == (time_t)1) return;
UNLESS(self->atime) self->atime = time(NULL);
UNLESS(self->atime=PyObject_NEW(PATimeobject,
&PATimeType))
return;
self->atime->value=time(NULL);
} }
static PyObject * static PyObject *
Per_atime(cPersistentObject *self) Per_atime(cPersistentObject *self)
{ {
UNLESS(self->atime) Per_set_atime(self); PATimeobject *r;
Py_XINCREF(self->atime);
return (PyObject*)self->atime; UNLESS(r=PyObject_NEW(PATimeobject,&PATimeType)) return NULL;
Py_INCREF(self);
r->object=self;
return (PyObject*)r;
} }
static PyObject * static PyObject *
...@@ -619,8 +628,7 @@ Per_getattr(cPersistentObject *self, PyObject *oname, char *name) ...@@ -619,8 +628,7 @@ Per_getattr(cPersistentObject *self, PyObject *oname, char *name)
{ {
if(self->oid) if(self->oid)
{ {
Py_INCREF(self->oid); return PyInt_FromLong(self->oid);
return self->oid;
} }
else else
{ {
...@@ -720,8 +728,8 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v) ...@@ -720,8 +728,8 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v)
{ {
if(name[3]=='o' && name[4]=='i' && name[5]=='d' && ! name[6]) if(name[3]=='o' && name[4]=='i' && name[5]=='d' && ! name[6])
{ {
ASSIGN(self->oid, v); if(PyInt_Check(v)) self->oid=PyInt_AsLong(v);
Py_INCREF(self->oid); else self->oid=0;
return 0; return 0;
} }
if(name[3]=='j' && name[4]=='a' && name[5]=='r' && ! name[6]) if(name[3]=='j' && name[4]=='a' && name[5]=='r' && ! name[6])
...@@ -735,6 +743,11 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v) ...@@ -735,6 +743,11 @@ Per_setattro(cPersistentObject *self, PyObject *oname, PyObject *v)
self->state=PyObject_IsTrue(v); self->state=PyObject_IsTrue(v);
return 0; return 0;
} }
if(strcmp(name+3,"atime")==0)
{
self->atime=(time_t)1;
return 0;
}
} }
else else
{ {
...@@ -841,7 +854,7 @@ void ...@@ -841,7 +854,7 @@ void
initcPersistence() initcPersistence()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.9 $"; char *rev="$Revision: 1.10 $";
PATimeType.ob_type=&PyType_Type; PATimeType.ob_type=&PyType_Type;
...@@ -868,6 +881,9 @@ initcPersistence() ...@@ -868,6 +881,9 @@ initcPersistence()
/**************************************************************************** /****************************************************************************
$Log: cPersistence.c,v $ $Log: cPersistence.c,v $
Revision 1.10 1997/04/22 02:40:03 jim
Changed object header layout and added sticky feature.
Revision 1.9 1997/04/03 17:34:14 jim Revision 1.9 1997/04/03 17:34:14 jim
Changed to pass transaction to jar store method during commit. Changed to pass transaction to jar store method during commit.
......
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