Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZEO
Commits
24cc6936
Commit
24cc6936
authored
Mar 11, 1997
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added access-time tracking and special type for efficient access time
management.
parent
ee678d39
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
456 additions
and
105 deletions
+456
-105
src/Persistence/cPersistence.c
src/Persistence/cPersistence.c
+152
-35
src/ZODB/cPersistence.c
src/ZODB/cPersistence.c
+152
-35
src/persistent/cPersistence.c
src/persistent/cPersistence.c
+152
-35
No files found.
src/Persistence/cPersistence.c
View file @
24cc6936
/*
/*
$Id: cPersistence.c,v 1.
2 1997/02/21 20:49:09
jim Exp $
$Id: cPersistence.c,v 1.
3 1997/03/11 20:53:07
jim Exp $
C Persistence Module
C Persistence Module
...
@@ -55,21 +55,8 @@
...
@@ -55,21 +55,8 @@
(540) 371-6909
(540) 371-6909
Full description
*****************************************************************************/
static
char
*
what_string
=
"$Id: cPersistence.c,v 1.3 1997/03/11 20:53:07 jim Exp $"
;
$Log: cPersistence.c,v $
Revision 1.2 1997/02/21 20:49:09 jim
Added logic to treat attributes starting with _v_ as volatile.
Changes in these attributes to not make the object thing it's been
saved and these attributes are not saved by the default __getstate__
method.
Revision 1.1 1997/02/14 20:24:55 jim
*** empty log message ***
*/
static
char
*
what_string
=
"$Id: cPersistence.c,v 1.2 1997/02/21 20:49:09 jim Exp $"
;
#include <time.h>
#include <time.h>
#include "Python.h"
#include "Python.h"
...
@@ -132,7 +119,70 @@ callmethod2(PyObject *self, PyObject *name, PyObject *arg, PyObject *arg2)
...
@@ -132,7 +119,70 @@ callmethod2(PyObject *self, PyObject *name, PyObject *arg, PyObject *arg2)
return
self
;
return
self
;
}
}
/* ----------------------------------------------------- */
static
PyObject
*
#ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS 2 */
PyString_BuildFormat
(
char
*
stringformat
,
char
*
format
,
...)
#else
/* VARARGS */
PyString_BuildFormat
(
va_alist
)
va_dcl
#endif
{
va_list
va
;
PyObject
*
args
=
0
,
*
retval
=
0
,
*
v
=
0
;
#ifdef HAVE_STDARG_PROTOTYPES
va_start
(
va
,
format
);
#else
PyObject
*
ErrType
;
char
*
stringformat
,
*
format
;
va_start
(
va
);
ErrType
=
va_arg
(
va
,
PyObject
*
);
stringformat
=
va_arg
(
va
,
char
*
);
format
=
va_arg
(
va
,
char
*
);
#endif
args
=
Py_VaBuildValue
(
format
,
va
);
va_end
(
va
);
if
(
!
args
)
return
NULL
;
if
(
!
(
retval
=
PyString_FromString
(
stringformat
)))
return
NULL
;
v
=
PyString_Format
(
retval
,
args
);
Py_DECREF
(
retval
);
Py_DECREF
(
args
);
return
v
;
}
/****************************************************************************/
typedef
struct
{
PyObject_HEAD
time_t
value
;
}
PATimeobject
;
static
void
PATime_dealloc
(
PATimeobject
*
self
){
PyMem_DEL
(
self
);}
static
PyObject
*
PATime_repr
(
PATimeobject
*
self
)
{
return
PyString_BuildFormat
(
"<access time: %d>"
,
"i"
,
self
->
value
);
}
static
PyTypeObject
PATimeType
=
{
PyObject_HEAD_INIT
(
NULL
)
0
,
"PersistentATime"
,
/*tp_name*/
sizeof
(
PATimeobject
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
/* methods */
(
destructor
)
PATime_dealloc
,
/*tp_dealloc*/
0L
,
0L
,
0L
,
0L
,
(
reprfunc
)
PATime_repr
,
/*tp_repr*/
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
"Values for holding access times for persistent objects"
};
/****************************************************************************/
/* Declarations for objects of type Persistent */
/* Declarations for objects of type Persistent */
...
@@ -141,7 +191,7 @@ typedef struct {
...
@@ -141,7 +191,7 @@ typedef struct {
PyObject
*
oid
;
PyObject
*
oid
;
PyObject
*
jar
;
PyObject
*
jar
;
PyObject
*
rtime
;
PyObject
*
rtime
;
time_t
atime
;
PATimeobject
*
atime
;
int
state
;
int
state
;
#define GHOST_STATE -1
#define GHOST_STATE -1
#define UPTODATE_STATE 0
#define UPTODATE_STATE 0
...
@@ -250,6 +300,27 @@ Per__p___init__(self, args)
...
@@ -250,6 +300,27 @@ Per__p___init__(self, args)
return
Py_None
;
return
Py_None
;
}
}
static
PyObject
*
Per__p___reinit__
(
Perobject
*
self
,
PyObject
*
args
)
{
PyObject
*
oid
,
*
jar
,
*
copy
;
UNLESS
(
PyArg_Parse
(
args
,
"(OOO)"
,
&
oid
,
&
jar
,
&
copy
))
return
NULL
;
UNLESS
(
self
->
oid
)
{
Py_INCREF
(
oid
);
ASSIGN
(
self
->
oid
,
oid
);
}
if
(
self
->
oid
==
oid
||
PyObject_Compare
(
self
->
oid
,
oid
))
{
UNLESS
(
args
=
PyObject_GetAttr
(
copy
,
py___dict__
))
return
NULL
;
ASSIGN
(
INSTANCE_DICT
(
self
),
args
);
self
->
state
=
GHOST_STATE
;
}
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
static
PyObject
*
Per__getstate__
(
self
,
args
)
Per__getstate__
(
self
,
args
)
Perobject
*
self
;
Perobject
*
self
;
...
@@ -350,6 +421,8 @@ static struct PyMethodDef Per_methods[] = {
...
@@ -350,6 +421,8 @@ static struct PyMethodDef Per_methods[] = {
{
"__inform_commit__"
,
(
PyCFunction
)
Per___save__
,
0
,
Per___inform_commit____doc__
},
{
"__inform_commit__"
,
(
PyCFunction
)
Per___save__
,
0
,
Per___inform_commit____doc__
},
{
"__inform_abort__"
,
(
PyCFunction
)
Per___inform_abort__
,
0
,
Per___inform_abort____doc__
},
{
"__inform_abort__"
,
(
PyCFunction
)
Per___inform_abort__
,
0
,
Per___inform_abort____doc__
},
{
"_p___init__"
,
(
PyCFunction
)
Per__p___init__
,
0
,
Per__p___init____doc__
},
{
"_p___init__"
,
(
PyCFunction
)
Per__p___init__
,
0
,
Per__p___init____doc__
},
{
"_p___reinit__"
,
(
PyCFunction
)
Per__p___reinit__
,
0
,
"_p___reinit__(oid,jar,copy) -- Reinitialize from a newly created copy"
},
{
"__getstate__"
,
(
PyCFunction
)
Per__getstate__
,
0
,
{
"__getstate__"
,
(
PyCFunction
)
Per__getstate__
,
0
,
"__getstate__() -- Return the state of the object"
},
"__getstate__() -- Return the state of the object"
},
{
"__setstate__"
,
(
PyCFunction
)
Per__setstate__
,
0
,
{
"__setstate__"
,
(
PyCFunction
)
Per__setstate__
,
0
,
...
@@ -368,9 +441,29 @@ Per_dealloc(self)
...
@@ -368,9 +441,29 @@ Per_dealloc(self)
Py_XDECREF
(
self
->
jar
);
Py_XDECREF
(
self
->
jar
);
Py_XDECREF
(
self
->
rtime
);
Py_XDECREF
(
self
->
rtime
);
Py_XDECREF
(
self
->
atime
);
PyMem_DEL
(
self
);
PyMem_DEL
(
self
);
}
}
static
void
Per_set_atime
(
Perobject
*
self
)
{
/* Record access times */
UNLESS
(
self
->
atime
)
UNLESS
(
self
->
atime
=
PyObject_NEW
(
PATimeobject
,
&
PATimeType
))
return
;
self
->
atime
->
value
=
time
(
NULL
);
}
static
PyObject
*
Per_atime
(
Perobject
*
self
)
{
UNLESS
(
self
->
atime
)
Per_set_atime
(
self
);
Py_XINCREF
(
self
->
atime
);
return
(
PyObject
*
)
self
->
atime
;
}
static
PyObject
*
static
PyObject
*
Per_getattr
(
Perobject
*
self
,
PyObject
*
oname
,
char
*
name
)
Per_getattr
(
Perobject
*
self
,
PyObject
*
oname
,
char
*
name
)
{
{
...
@@ -414,6 +507,14 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
...
@@ -414,6 +507,14 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
case
'c'
:
case
'c'
:
if
(
strcmp
(
n
,
"hanged"
)
==
0
)
if
(
strcmp
(
n
,
"hanged"
)
==
0
)
return
PyInt_FromLong
(
self
->
state
==
CHANGED_STATE
);
return
PyInt_FromLong
(
self
->
state
==
CHANGED_STATE
);
break
;
case
'a'
:
if
(
strcmp
(
n
,
"time"
)
==
0
)
{
if
(
self
->
state
!=
UPTODATE_STATE
)
Per_set_atime
(
self
);
return
Per_atime
(
self
);
}
break
;
case
'r'
:
case
'r'
:
if
(
strcmp
(
n
,
"ead_time"
)
==
0
)
if
(
strcmp
(
n
,
"ead_time"
)
==
0
)
{
{
...
@@ -442,9 +543,8 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
...
@@ -442,9 +543,8 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
}
}
Py_DECREF
(
r
);
Py_DECREF
(
r
);
}
}
/* Record access times */
Per_set_atime
(
self
);
self
->
atime
=
time
(
NULL
);
}
}
return
Py_FindAttr
((
PyObject
*
)
self
,
oname
);
return
Py_FindAttr
((
PyObject
*
)
self
,
oname
);
...
@@ -511,7 +611,7 @@ Per_setattro(Perobject *self, PyObject *oname, PyObject *v)
...
@@ -511,7 +611,7 @@ Per_setattro(Perobject *self, PyObject *oname, PyObject *v)
}
}
/* Record access times */
/* Record access times */
self
->
atime
=
time
(
NULL
);
Per_set_atime
(
self
);
if
(
!
(
*
name
==
'_'
&&
name
[
1
]
==
'v'
&&
name
[
2
]
==
'_'
)
if
(
!
(
*
name
==
'_'
&&
name
[
1
]
==
'v'
&&
name
[
2
]
==
'_'
)
&&
self
->
state
!=
CHANGED_STATE
&&
self
->
jar
)
&&
self
->
state
!=
CHANGED_STATE
&&
self
->
jar
)
...
@@ -594,22 +694,39 @@ static char cPersistence_module_documentation[] =
...
@@ -594,22 +694,39 @@ static char cPersistence_module_documentation[] =
void
void
initcPersistence
()
initcPersistence
()
{
{
PyObject
*
m
,
*
d
;
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.3 $"
;
/* Create the module and add the functions */
m
=
Py_InitModule4
(
"cPersistence"
,
cP_methods
,
cPersistence_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
init_strings
()
;
PATimeType
.
ob_type
=&
PyType_Type
;
/* Add some symbolic constants to the module */
m
=
Py_InitModule4
(
"cPersistence"
,
cP_methods
,
d
=
PyModule_GetDict
(
m
);
cPersistence_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
/* XXXX Add constants here */
init_strings
();
PyExtensionClass_Export
(
d
,
"Persistent"
,
Pertype
);
/* Check for errors */
d
=
PyModule_GetDict
(
m
);
CHECK_FOR_ERRORS
(
"can't initialize module dt"
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
PyExtensionClass_Export
(
d
,
"Persistent"
,
Pertype
);
PyDict_SetItemString
(
d
,
"atimeType"
,(
PyObject
*
)
&
PATimeType
);
CHECK_FOR_ERRORS
(
"can't initialize module dt"
);
}
}
/****************************************************************************
$Log: cPersistence.c,v $
Revision 1.3 1997/03/11 20:53:07 jim
Added access-time tracking and special type for efficient access time
management.
Revision 1.2 1997/02/21 20:49:09 jim
Added logic to treat attributes starting with _v_ as volatile.
Changes in these attributes to not make the object thing it's been
saved and these attributes are not saved by the default __getstate__
method.
Revision 1.1 1997/02/14 20:24:55 jim
*** empty log message ***
****************************************************************************/
src/ZODB/cPersistence.c
View file @
24cc6936
/*
/*
$Id: cPersistence.c,v 1.
2 1997/02/21 20:49:09
jim Exp $
$Id: cPersistence.c,v 1.
3 1997/03/11 20:53:07
jim Exp $
C Persistence Module
C Persistence Module
...
@@ -55,21 +55,8 @@
...
@@ -55,21 +55,8 @@
(540) 371-6909
(540) 371-6909
Full description
*****************************************************************************/
static
char
*
what_string
=
"$Id: cPersistence.c,v 1.3 1997/03/11 20:53:07 jim Exp $"
;
$Log: cPersistence.c,v $
Revision 1.2 1997/02/21 20:49:09 jim
Added logic to treat attributes starting with _v_ as volatile.
Changes in these attributes to not make the object thing it's been
saved and these attributes are not saved by the default __getstate__
method.
Revision 1.1 1997/02/14 20:24:55 jim
*** empty log message ***
*/
static
char
*
what_string
=
"$Id: cPersistence.c,v 1.2 1997/02/21 20:49:09 jim Exp $"
;
#include <time.h>
#include <time.h>
#include "Python.h"
#include "Python.h"
...
@@ -132,7 +119,70 @@ callmethod2(PyObject *self, PyObject *name, PyObject *arg, PyObject *arg2)
...
@@ -132,7 +119,70 @@ callmethod2(PyObject *self, PyObject *name, PyObject *arg, PyObject *arg2)
return
self
;
return
self
;
}
}
/* ----------------------------------------------------- */
static
PyObject
*
#ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS 2 */
PyString_BuildFormat
(
char
*
stringformat
,
char
*
format
,
...)
#else
/* VARARGS */
PyString_BuildFormat
(
va_alist
)
va_dcl
#endif
{
va_list
va
;
PyObject
*
args
=
0
,
*
retval
=
0
,
*
v
=
0
;
#ifdef HAVE_STDARG_PROTOTYPES
va_start
(
va
,
format
);
#else
PyObject
*
ErrType
;
char
*
stringformat
,
*
format
;
va_start
(
va
);
ErrType
=
va_arg
(
va
,
PyObject
*
);
stringformat
=
va_arg
(
va
,
char
*
);
format
=
va_arg
(
va
,
char
*
);
#endif
args
=
Py_VaBuildValue
(
format
,
va
);
va_end
(
va
);
if
(
!
args
)
return
NULL
;
if
(
!
(
retval
=
PyString_FromString
(
stringformat
)))
return
NULL
;
v
=
PyString_Format
(
retval
,
args
);
Py_DECREF
(
retval
);
Py_DECREF
(
args
);
return
v
;
}
/****************************************************************************/
typedef
struct
{
PyObject_HEAD
time_t
value
;
}
PATimeobject
;
static
void
PATime_dealloc
(
PATimeobject
*
self
){
PyMem_DEL
(
self
);}
static
PyObject
*
PATime_repr
(
PATimeobject
*
self
)
{
return
PyString_BuildFormat
(
"<access time: %d>"
,
"i"
,
self
->
value
);
}
static
PyTypeObject
PATimeType
=
{
PyObject_HEAD_INIT
(
NULL
)
0
,
"PersistentATime"
,
/*tp_name*/
sizeof
(
PATimeobject
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
/* methods */
(
destructor
)
PATime_dealloc
,
/*tp_dealloc*/
0L
,
0L
,
0L
,
0L
,
(
reprfunc
)
PATime_repr
,
/*tp_repr*/
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
"Values for holding access times for persistent objects"
};
/****************************************************************************/
/* Declarations for objects of type Persistent */
/* Declarations for objects of type Persistent */
...
@@ -141,7 +191,7 @@ typedef struct {
...
@@ -141,7 +191,7 @@ typedef struct {
PyObject
*
oid
;
PyObject
*
oid
;
PyObject
*
jar
;
PyObject
*
jar
;
PyObject
*
rtime
;
PyObject
*
rtime
;
time_t
atime
;
PATimeobject
*
atime
;
int
state
;
int
state
;
#define GHOST_STATE -1
#define GHOST_STATE -1
#define UPTODATE_STATE 0
#define UPTODATE_STATE 0
...
@@ -250,6 +300,27 @@ Per__p___init__(self, args)
...
@@ -250,6 +300,27 @@ Per__p___init__(self, args)
return
Py_None
;
return
Py_None
;
}
}
static
PyObject
*
Per__p___reinit__
(
Perobject
*
self
,
PyObject
*
args
)
{
PyObject
*
oid
,
*
jar
,
*
copy
;
UNLESS
(
PyArg_Parse
(
args
,
"(OOO)"
,
&
oid
,
&
jar
,
&
copy
))
return
NULL
;
UNLESS
(
self
->
oid
)
{
Py_INCREF
(
oid
);
ASSIGN
(
self
->
oid
,
oid
);
}
if
(
self
->
oid
==
oid
||
PyObject_Compare
(
self
->
oid
,
oid
))
{
UNLESS
(
args
=
PyObject_GetAttr
(
copy
,
py___dict__
))
return
NULL
;
ASSIGN
(
INSTANCE_DICT
(
self
),
args
);
self
->
state
=
GHOST_STATE
;
}
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
static
PyObject
*
Per__getstate__
(
self
,
args
)
Per__getstate__
(
self
,
args
)
Perobject
*
self
;
Perobject
*
self
;
...
@@ -350,6 +421,8 @@ static struct PyMethodDef Per_methods[] = {
...
@@ -350,6 +421,8 @@ static struct PyMethodDef Per_methods[] = {
{
"__inform_commit__"
,
(
PyCFunction
)
Per___save__
,
0
,
Per___inform_commit____doc__
},
{
"__inform_commit__"
,
(
PyCFunction
)
Per___save__
,
0
,
Per___inform_commit____doc__
},
{
"__inform_abort__"
,
(
PyCFunction
)
Per___inform_abort__
,
0
,
Per___inform_abort____doc__
},
{
"__inform_abort__"
,
(
PyCFunction
)
Per___inform_abort__
,
0
,
Per___inform_abort____doc__
},
{
"_p___init__"
,
(
PyCFunction
)
Per__p___init__
,
0
,
Per__p___init____doc__
},
{
"_p___init__"
,
(
PyCFunction
)
Per__p___init__
,
0
,
Per__p___init____doc__
},
{
"_p___reinit__"
,
(
PyCFunction
)
Per__p___reinit__
,
0
,
"_p___reinit__(oid,jar,copy) -- Reinitialize from a newly created copy"
},
{
"__getstate__"
,
(
PyCFunction
)
Per__getstate__
,
0
,
{
"__getstate__"
,
(
PyCFunction
)
Per__getstate__
,
0
,
"__getstate__() -- Return the state of the object"
},
"__getstate__() -- Return the state of the object"
},
{
"__setstate__"
,
(
PyCFunction
)
Per__setstate__
,
0
,
{
"__setstate__"
,
(
PyCFunction
)
Per__setstate__
,
0
,
...
@@ -368,9 +441,29 @@ Per_dealloc(self)
...
@@ -368,9 +441,29 @@ Per_dealloc(self)
Py_XDECREF
(
self
->
jar
);
Py_XDECREF
(
self
->
jar
);
Py_XDECREF
(
self
->
rtime
);
Py_XDECREF
(
self
->
rtime
);
Py_XDECREF
(
self
->
atime
);
PyMem_DEL
(
self
);
PyMem_DEL
(
self
);
}
}
static
void
Per_set_atime
(
Perobject
*
self
)
{
/* Record access times */
UNLESS
(
self
->
atime
)
UNLESS
(
self
->
atime
=
PyObject_NEW
(
PATimeobject
,
&
PATimeType
))
return
;
self
->
atime
->
value
=
time
(
NULL
);
}
static
PyObject
*
Per_atime
(
Perobject
*
self
)
{
UNLESS
(
self
->
atime
)
Per_set_atime
(
self
);
Py_XINCREF
(
self
->
atime
);
return
(
PyObject
*
)
self
->
atime
;
}
static
PyObject
*
static
PyObject
*
Per_getattr
(
Perobject
*
self
,
PyObject
*
oname
,
char
*
name
)
Per_getattr
(
Perobject
*
self
,
PyObject
*
oname
,
char
*
name
)
{
{
...
@@ -414,6 +507,14 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
...
@@ -414,6 +507,14 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
case
'c'
:
case
'c'
:
if
(
strcmp
(
n
,
"hanged"
)
==
0
)
if
(
strcmp
(
n
,
"hanged"
)
==
0
)
return
PyInt_FromLong
(
self
->
state
==
CHANGED_STATE
);
return
PyInt_FromLong
(
self
->
state
==
CHANGED_STATE
);
break
;
case
'a'
:
if
(
strcmp
(
n
,
"time"
)
==
0
)
{
if
(
self
->
state
!=
UPTODATE_STATE
)
Per_set_atime
(
self
);
return
Per_atime
(
self
);
}
break
;
case
'r'
:
case
'r'
:
if
(
strcmp
(
n
,
"ead_time"
)
==
0
)
if
(
strcmp
(
n
,
"ead_time"
)
==
0
)
{
{
...
@@ -442,9 +543,8 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
...
@@ -442,9 +543,8 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
}
}
Py_DECREF
(
r
);
Py_DECREF
(
r
);
}
}
/* Record access times */
Per_set_atime
(
self
);
self
->
atime
=
time
(
NULL
);
}
}
return
Py_FindAttr
((
PyObject
*
)
self
,
oname
);
return
Py_FindAttr
((
PyObject
*
)
self
,
oname
);
...
@@ -511,7 +611,7 @@ Per_setattro(Perobject *self, PyObject *oname, PyObject *v)
...
@@ -511,7 +611,7 @@ Per_setattro(Perobject *self, PyObject *oname, PyObject *v)
}
}
/* Record access times */
/* Record access times */
self
->
atime
=
time
(
NULL
);
Per_set_atime
(
self
);
if
(
!
(
*
name
==
'_'
&&
name
[
1
]
==
'v'
&&
name
[
2
]
==
'_'
)
if
(
!
(
*
name
==
'_'
&&
name
[
1
]
==
'v'
&&
name
[
2
]
==
'_'
)
&&
self
->
state
!=
CHANGED_STATE
&&
self
->
jar
)
&&
self
->
state
!=
CHANGED_STATE
&&
self
->
jar
)
...
@@ -594,22 +694,39 @@ static char cPersistence_module_documentation[] =
...
@@ -594,22 +694,39 @@ static char cPersistence_module_documentation[] =
void
void
initcPersistence
()
initcPersistence
()
{
{
PyObject
*
m
,
*
d
;
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.3 $"
;
/* Create the module and add the functions */
m
=
Py_InitModule4
(
"cPersistence"
,
cP_methods
,
cPersistence_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
init_strings
()
;
PATimeType
.
ob_type
=&
PyType_Type
;
/* Add some symbolic constants to the module */
m
=
Py_InitModule4
(
"cPersistence"
,
cP_methods
,
d
=
PyModule_GetDict
(
m
);
cPersistence_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
/* XXXX Add constants here */
init_strings
();
PyExtensionClass_Export
(
d
,
"Persistent"
,
Pertype
);
/* Check for errors */
d
=
PyModule_GetDict
(
m
);
CHECK_FOR_ERRORS
(
"can't initialize module dt"
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
PyExtensionClass_Export
(
d
,
"Persistent"
,
Pertype
);
PyDict_SetItemString
(
d
,
"atimeType"
,(
PyObject
*
)
&
PATimeType
);
CHECK_FOR_ERRORS
(
"can't initialize module dt"
);
}
}
/****************************************************************************
$Log: cPersistence.c,v $
Revision 1.3 1997/03/11 20:53:07 jim
Added access-time tracking and special type for efficient access time
management.
Revision 1.2 1997/02/21 20:49:09 jim
Added logic to treat attributes starting with _v_ as volatile.
Changes in these attributes to not make the object thing it's been
saved and these attributes are not saved by the default __getstate__
method.
Revision 1.1 1997/02/14 20:24:55 jim
*** empty log message ***
****************************************************************************/
src/persistent/cPersistence.c
View file @
24cc6936
/*
/*
$Id: cPersistence.c,v 1.
2 1997/02/21 20:49:09
jim Exp $
$Id: cPersistence.c,v 1.
3 1997/03/11 20:53:07
jim Exp $
C Persistence Module
C Persistence Module
...
@@ -55,21 +55,8 @@
...
@@ -55,21 +55,8 @@
(540) 371-6909
(540) 371-6909
Full description
*****************************************************************************/
static
char
*
what_string
=
"$Id: cPersistence.c,v 1.3 1997/03/11 20:53:07 jim Exp $"
;
$Log: cPersistence.c,v $
Revision 1.2 1997/02/21 20:49:09 jim
Added logic to treat attributes starting with _v_ as volatile.
Changes in these attributes to not make the object thing it's been
saved and these attributes are not saved by the default __getstate__
method.
Revision 1.1 1997/02/14 20:24:55 jim
*** empty log message ***
*/
static
char
*
what_string
=
"$Id: cPersistence.c,v 1.2 1997/02/21 20:49:09 jim Exp $"
;
#include <time.h>
#include <time.h>
#include "Python.h"
#include "Python.h"
...
@@ -132,7 +119,70 @@ callmethod2(PyObject *self, PyObject *name, PyObject *arg, PyObject *arg2)
...
@@ -132,7 +119,70 @@ callmethod2(PyObject *self, PyObject *name, PyObject *arg, PyObject *arg2)
return
self
;
return
self
;
}
}
/* ----------------------------------------------------- */
static
PyObject
*
#ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS 2 */
PyString_BuildFormat
(
char
*
stringformat
,
char
*
format
,
...)
#else
/* VARARGS */
PyString_BuildFormat
(
va_alist
)
va_dcl
#endif
{
va_list
va
;
PyObject
*
args
=
0
,
*
retval
=
0
,
*
v
=
0
;
#ifdef HAVE_STDARG_PROTOTYPES
va_start
(
va
,
format
);
#else
PyObject
*
ErrType
;
char
*
stringformat
,
*
format
;
va_start
(
va
);
ErrType
=
va_arg
(
va
,
PyObject
*
);
stringformat
=
va_arg
(
va
,
char
*
);
format
=
va_arg
(
va
,
char
*
);
#endif
args
=
Py_VaBuildValue
(
format
,
va
);
va_end
(
va
);
if
(
!
args
)
return
NULL
;
if
(
!
(
retval
=
PyString_FromString
(
stringformat
)))
return
NULL
;
v
=
PyString_Format
(
retval
,
args
);
Py_DECREF
(
retval
);
Py_DECREF
(
args
);
return
v
;
}
/****************************************************************************/
typedef
struct
{
PyObject_HEAD
time_t
value
;
}
PATimeobject
;
static
void
PATime_dealloc
(
PATimeobject
*
self
){
PyMem_DEL
(
self
);}
static
PyObject
*
PATime_repr
(
PATimeobject
*
self
)
{
return
PyString_BuildFormat
(
"<access time: %d>"
,
"i"
,
self
->
value
);
}
static
PyTypeObject
PATimeType
=
{
PyObject_HEAD_INIT
(
NULL
)
0
,
"PersistentATime"
,
/*tp_name*/
sizeof
(
PATimeobject
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
/* methods */
(
destructor
)
PATime_dealloc
,
/*tp_dealloc*/
0L
,
0L
,
0L
,
0L
,
(
reprfunc
)
PATime_repr
,
/*tp_repr*/
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
0L
,
"Values for holding access times for persistent objects"
};
/****************************************************************************/
/* Declarations for objects of type Persistent */
/* Declarations for objects of type Persistent */
...
@@ -141,7 +191,7 @@ typedef struct {
...
@@ -141,7 +191,7 @@ typedef struct {
PyObject
*
oid
;
PyObject
*
oid
;
PyObject
*
jar
;
PyObject
*
jar
;
PyObject
*
rtime
;
PyObject
*
rtime
;
time_t
atime
;
PATimeobject
*
atime
;
int
state
;
int
state
;
#define GHOST_STATE -1
#define GHOST_STATE -1
#define UPTODATE_STATE 0
#define UPTODATE_STATE 0
...
@@ -250,6 +300,27 @@ Per__p___init__(self, args)
...
@@ -250,6 +300,27 @@ Per__p___init__(self, args)
return
Py_None
;
return
Py_None
;
}
}
static
PyObject
*
Per__p___reinit__
(
Perobject
*
self
,
PyObject
*
args
)
{
PyObject
*
oid
,
*
jar
,
*
copy
;
UNLESS
(
PyArg_Parse
(
args
,
"(OOO)"
,
&
oid
,
&
jar
,
&
copy
))
return
NULL
;
UNLESS
(
self
->
oid
)
{
Py_INCREF
(
oid
);
ASSIGN
(
self
->
oid
,
oid
);
}
if
(
self
->
oid
==
oid
||
PyObject_Compare
(
self
->
oid
,
oid
))
{
UNLESS
(
args
=
PyObject_GetAttr
(
copy
,
py___dict__
))
return
NULL
;
ASSIGN
(
INSTANCE_DICT
(
self
),
args
);
self
->
state
=
GHOST_STATE
;
}
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
static
PyObject
*
Per__getstate__
(
self
,
args
)
Per__getstate__
(
self
,
args
)
Perobject
*
self
;
Perobject
*
self
;
...
@@ -350,6 +421,8 @@ static struct PyMethodDef Per_methods[] = {
...
@@ -350,6 +421,8 @@ static struct PyMethodDef Per_methods[] = {
{
"__inform_commit__"
,
(
PyCFunction
)
Per___save__
,
0
,
Per___inform_commit____doc__
},
{
"__inform_commit__"
,
(
PyCFunction
)
Per___save__
,
0
,
Per___inform_commit____doc__
},
{
"__inform_abort__"
,
(
PyCFunction
)
Per___inform_abort__
,
0
,
Per___inform_abort____doc__
},
{
"__inform_abort__"
,
(
PyCFunction
)
Per___inform_abort__
,
0
,
Per___inform_abort____doc__
},
{
"_p___init__"
,
(
PyCFunction
)
Per__p___init__
,
0
,
Per__p___init____doc__
},
{
"_p___init__"
,
(
PyCFunction
)
Per__p___init__
,
0
,
Per__p___init____doc__
},
{
"_p___reinit__"
,
(
PyCFunction
)
Per__p___reinit__
,
0
,
"_p___reinit__(oid,jar,copy) -- Reinitialize from a newly created copy"
},
{
"__getstate__"
,
(
PyCFunction
)
Per__getstate__
,
0
,
{
"__getstate__"
,
(
PyCFunction
)
Per__getstate__
,
0
,
"__getstate__() -- Return the state of the object"
},
"__getstate__() -- Return the state of the object"
},
{
"__setstate__"
,
(
PyCFunction
)
Per__setstate__
,
0
,
{
"__setstate__"
,
(
PyCFunction
)
Per__setstate__
,
0
,
...
@@ -368,9 +441,29 @@ Per_dealloc(self)
...
@@ -368,9 +441,29 @@ Per_dealloc(self)
Py_XDECREF
(
self
->
jar
);
Py_XDECREF
(
self
->
jar
);
Py_XDECREF
(
self
->
rtime
);
Py_XDECREF
(
self
->
rtime
);
Py_XDECREF
(
self
->
atime
);
PyMem_DEL
(
self
);
PyMem_DEL
(
self
);
}
}
static
void
Per_set_atime
(
Perobject
*
self
)
{
/* Record access times */
UNLESS
(
self
->
atime
)
UNLESS
(
self
->
atime
=
PyObject_NEW
(
PATimeobject
,
&
PATimeType
))
return
;
self
->
atime
->
value
=
time
(
NULL
);
}
static
PyObject
*
Per_atime
(
Perobject
*
self
)
{
UNLESS
(
self
->
atime
)
Per_set_atime
(
self
);
Py_XINCREF
(
self
->
atime
);
return
(
PyObject
*
)
self
->
atime
;
}
static
PyObject
*
static
PyObject
*
Per_getattr
(
Perobject
*
self
,
PyObject
*
oname
,
char
*
name
)
Per_getattr
(
Perobject
*
self
,
PyObject
*
oname
,
char
*
name
)
{
{
...
@@ -414,6 +507,14 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
...
@@ -414,6 +507,14 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
case
'c'
:
case
'c'
:
if
(
strcmp
(
n
,
"hanged"
)
==
0
)
if
(
strcmp
(
n
,
"hanged"
)
==
0
)
return
PyInt_FromLong
(
self
->
state
==
CHANGED_STATE
);
return
PyInt_FromLong
(
self
->
state
==
CHANGED_STATE
);
break
;
case
'a'
:
if
(
strcmp
(
n
,
"time"
)
==
0
)
{
if
(
self
->
state
!=
UPTODATE_STATE
)
Per_set_atime
(
self
);
return
Per_atime
(
self
);
}
break
;
case
'r'
:
case
'r'
:
if
(
strcmp
(
n
,
"ead_time"
)
==
0
)
if
(
strcmp
(
n
,
"ead_time"
)
==
0
)
{
{
...
@@ -442,9 +543,8 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
...
@@ -442,9 +543,8 @@ Per_getattr(Perobject *self, PyObject *oname, char *name)
}
}
Py_DECREF
(
r
);
Py_DECREF
(
r
);
}
}
/* Record access times */
Per_set_atime
(
self
);
self
->
atime
=
time
(
NULL
);
}
}
return
Py_FindAttr
((
PyObject
*
)
self
,
oname
);
return
Py_FindAttr
((
PyObject
*
)
self
,
oname
);
...
@@ -511,7 +611,7 @@ Per_setattro(Perobject *self, PyObject *oname, PyObject *v)
...
@@ -511,7 +611,7 @@ Per_setattro(Perobject *self, PyObject *oname, PyObject *v)
}
}
/* Record access times */
/* Record access times */
self
->
atime
=
time
(
NULL
);
Per_set_atime
(
self
);
if
(
!
(
*
name
==
'_'
&&
name
[
1
]
==
'v'
&&
name
[
2
]
==
'_'
)
if
(
!
(
*
name
==
'_'
&&
name
[
1
]
==
'v'
&&
name
[
2
]
==
'_'
)
&&
self
->
state
!=
CHANGED_STATE
&&
self
->
jar
)
&&
self
->
state
!=
CHANGED_STATE
&&
self
->
jar
)
...
@@ -594,22 +694,39 @@ static char cPersistence_module_documentation[] =
...
@@ -594,22 +694,39 @@ static char cPersistence_module_documentation[] =
void
void
initcPersistence
()
initcPersistence
()
{
{
PyObject
*
m
,
*
d
;
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.3 $"
;
/* Create the module and add the functions */
m
=
Py_InitModule4
(
"cPersistence"
,
cP_methods
,
cPersistence_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
init_strings
()
;
PATimeType
.
ob_type
=&
PyType_Type
;
/* Add some symbolic constants to the module */
m
=
Py_InitModule4
(
"cPersistence"
,
cP_methods
,
d
=
PyModule_GetDict
(
m
);
cPersistence_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
/* XXXX Add constants here */
init_strings
();
PyExtensionClass_Export
(
d
,
"Persistent"
,
Pertype
);
/* Check for errors */
d
=
PyModule_GetDict
(
m
);
CHECK_FOR_ERRORS
(
"can't initialize module dt"
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
PyExtensionClass_Export
(
d
,
"Persistent"
,
Pertype
);
PyDict_SetItemString
(
d
,
"atimeType"
,(
PyObject
*
)
&
PATimeType
);
CHECK_FOR_ERRORS
(
"can't initialize module dt"
);
}
}
/****************************************************************************
$Log: cPersistence.c,v $
Revision 1.3 1997/03/11 20:53:07 jim
Added access-time tracking and special type for efficient access time
management.
Revision 1.2 1997/02/21 20:49:09 jim
Added logic to treat attributes starting with _v_ as volatile.
Changes in these attributes to not make the object thing it's been
saved and these attributes are not saved by the default __getstate__
method.
Revision 1.1 1997/02/14 20:24:55 jim
*** empty log message ***
****************************************************************************/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment