Commit 4506c7a9 authored by Jim Fulton's avatar Jim Fulton

Made persistence optional.

parent f0bb8517
...@@ -85,9 +85,10 @@ ...@@ -85,9 +85,10 @@
static char BTree_module_documentation[] = static char BTree_module_documentation[] =
"" ""
"\n$Id: BTreeModuleTemplate.c,v 1.1 2001/02/19 00:09:45 jim Exp $" "\n$Id: BTreeModuleTemplate.c,v 1.2 2001/02/19 00:38:41 jim Exp $"
; ;
#ifdef PERSISTENT
#include "cPersistence.h" #include "cPersistence.h"
/*************************************************************** /***************************************************************
...@@ -100,9 +101,17 @@ static char BTree_module_documentation[] = ...@@ -100,9 +101,17 @@ static char BTree_module_documentation[] =
? (((O)->state==cPersistent_UPTODATE_STATE) \ ? (((O)->state==cPersistent_UPTODATE_STATE) \
? ((O)->state=cPersistent_STICKY_STATE) : 1) : 0) ? ((O)->state=cPersistent_STICKY_STATE) : 1) : 0)
#define Ghost_Test(O) ((O)->state == cPersistent_GHOST_STATE)
#endif #endif
/***************************************************************/ /***************************************************************/
#else
#include "ExtensionClass.h"
#define PER_USE_OR_RETURN(self, NULL)
#define PER_ALLOW_DEACTIVATION(self)
#define PER_PREVENT_DEACTIVATION(self)
#define PER_DEL(self)
#define PER_USE(O) 1
#define PER_CHANGED(O) 0
#endif
PyObject *sort_str, *reverse_str; PyObject *sort_str, *reverse_str;
...@@ -126,7 +135,11 @@ typedef struct BTreeItemStruct { ...@@ -126,7 +135,11 @@ typedef struct BTreeItemStruct {
} BTreeItem; } BTreeItem;
typedef struct Bucket_s { typedef struct Bucket_s {
#ifdef PERSISTENT
cPersistent_HEAD cPersistent_HEAD
#else
PyObject_HEAD
#endif
int size, len; int size, len;
struct Bucket_s *next; struct Bucket_s *next;
KEY_TYPE *keys; KEY_TYPE *keys;
...@@ -140,7 +153,11 @@ static void PyVar_AssignB(Bucket **v, Bucket *e) { Py_XDECREF(*v); *v=e;} ...@@ -140,7 +153,11 @@ static void PyVar_AssignB(Bucket **v, Bucket *e) { Py_XDECREF(*v); *v=e;}
#define ASSIGNBC(V,E) (Py_INCREF((E)), PyVar_AssignB(&(V),(E))) #define ASSIGNBC(V,E) (Py_INCREF((E)), PyVar_AssignB(&(V),(E)))
typedef struct { typedef struct {
#ifdef PERSISTENT
cPersistent_HEAD cPersistent_HEAD
#else
PyObject_HEAD
#endif
int size, len; int size, len;
Bucket *firstbucket; Bucket *firstbucket;
BTreeItem *data; BTreeItem *data;
...@@ -311,6 +328,7 @@ INITMODULE () ...@@ -311,6 +328,7 @@ INITMODULE ()
UNLESS (PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI")) UNLESS (PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI"))
return; return;
#ifdef PERSISTENT
if (cPersistenceCAPI=PyCObject_Import("cPersistence","CAPI")) if (cPersistenceCAPI=PyCObject_Import("cPersistence","CAPI"))
{ {
BucketType.methods.link=cPersistenceCAPI->methods; BucketType.methods.link=cPersistenceCAPI->methods;
...@@ -330,6 +348,12 @@ INITMODULE () ...@@ -330,6 +348,12 @@ INITMODULE ()
TreeSetType.tp_setattro=cPersistenceCAPI->setattro; TreeSetType.tp_setattro=cPersistenceCAPI->setattro;
} }
else return; else return;
#else
BTreeType.tp_getattro=PyExtensionClassCAPI->getattro;
BucketType.tp_getattro=PyExtensionClassCAPI->getattro;
SetType.tp_getattro=PyExtensionClassCAPI->getattro;
TreeSetType.tp_getattro=PyExtensionClassCAPI->getattro;
#endif
BTreeItemsType.ob_type=&PyType_Type; BTreeItemsType.ob_type=&PyType_Type;
...@@ -342,7 +366,7 @@ INITMODULE () ...@@ -342,7 +366,7 @@ INITMODULE ()
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
PyDict_SetItemString(d, "__version__", PyDict_SetItemString(d, "__version__",
PyString_FromString("$Revision: 1.1 $")); PyString_FromString("$Revision: 1.2 $"));
PyExtensionClass_Export(d,PREFIX "Bucket", BucketType); PyExtensionClass_Export(d,PREFIX "Bucket", BucketType);
PyExtensionClass_Export(d,PREFIX "BTree", BTreeType); PyExtensionClass_Export(d,PREFIX "BTree", BTreeType);
......
...@@ -555,17 +555,7 @@ _BTree_clear(BTree *self) ...@@ -555,17 +555,7 @@ _BTree_clear(BTree *self)
return 0; return 0;
} }
/* #ifdef PERSISTENT
** BTree__p_deactivate
**
** Persistance machinery support to turn the object into a ghost
**
** Arguments: self The BTree
** args (unused)
**
** Returns: None on success
** NULL on failure
*/
static PyObject * static PyObject *
BTree__p_deactivate(BTree *self, PyObject *args) BTree__p_deactivate(BTree *self, PyObject *args)
{ {
...@@ -578,6 +568,7 @@ BTree__p_deactivate(BTree *self, PyObject *args) ...@@ -578,6 +568,7 @@ BTree__p_deactivate(BTree *self, PyObject *args)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
#endif
/* /*
** BTree_clear ** BTree_clear
...@@ -1111,8 +1102,10 @@ static struct PyMethodDef BTree_methods[] = { ...@@ -1111,8 +1102,10 @@ static struct PyMethodDef BTree_methods[] = {
"insert(key, value) -- Add an item if the key is not already used.\n\n" "insert(key, value) -- Add an item if the key is not already used.\n\n"
"Return 1 if the item was added, or 0 otherwise" "Return 1 if the item was added, or 0 otherwise"
}, },
#ifdef PERSISTENT
{"_p_deactivate", (PyCFunction) BTree__p_deactivate, METH_VARARGS, {"_p_deactivate", (PyCFunction) BTree__p_deactivate, METH_VARARGS,
"_p_deactivate() -- Reinitialize from a newly created copy"}, "_p_deactivate() -- Reinitialize from a newly created copy"},
#endif
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
...@@ -1215,6 +1208,9 @@ static PyExtensionClass BTreeType = { ...@@ -1215,6 +1208,9 @@ static PyExtensionClass BTreeType = {
0L,0L, 0L,0L,
"Mapping type implemented as sorted list of items", "Mapping type implemented as sorted list of items",
METHOD_CHAIN(BTree_methods), METHOD_CHAIN(BTree_methods),
EXTENSIONCLASS_BASICNEW_FLAG | PERSISTENT_TYPE_FLAG EXTENSIONCLASS_BASICNEW_FLAG
#ifdef PERSISTENT
| PERSISTENT_TYPE_FLAG
#endif
| EXTENSIONCLASS_NOINSTDICT_FLAG, | EXTENSIONCLASS_NOINSTDICT_FLAG,
}; };
...@@ -726,17 +726,7 @@ bucket_byValue(Bucket *self, PyObject *args) ...@@ -726,17 +726,7 @@ bucket_byValue(Bucket *self, PyObject *args)
return NULL; return NULL;
} }
/* #ifdef PERSISTENT
** bucket__p_deactivate
**
** Reinitialization function for persistence machinery; turns this
** bucket into a ghost (releases contained data)
**
** Arguments: self The Bucket
** args (unused)
**
** Returns: None
*/
static PyObject * static PyObject *
bucket__p_deactivate(Bucket *self, PyObject *args) bucket__p_deactivate(Bucket *self, PyObject *args)
{ {
...@@ -757,6 +747,7 @@ bucket__p_deactivate(Bucket *self, PyObject *args) ...@@ -757,6 +747,7 @@ bucket__p_deactivate(Bucket *self, PyObject *args)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
#endif
/* /*
** bucket_clear ** bucket_clear
...@@ -980,8 +971,10 @@ static struct PyMethodDef Bucket_methods[] = { ...@@ -980,8 +971,10 @@ static struct PyMethodDef Bucket_methods[] = {
"get(key[,default]) -- Look up a value\n\n" "get(key[,default]) -- Look up a value\n\n"
"Return the default (or None) if the key is not found." "Return the default (or None) if the key is not found."
}, },
#ifdef PERSISTENT
{"_p_deactivate", (PyCFunction) bucket__p_deactivate, METH_VARARGS, {"_p_deactivate", (PyCFunction) bucket__p_deactivate, METH_VARARGS,
"_p_deactivate() -- Reinitialize from a newly created copy"}, "_p_deactivate() -- Reinitialize from a newly created copy"},
#endif
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
...@@ -1065,7 +1058,10 @@ static PyExtensionClass BucketType = { ...@@ -1065,7 +1058,10 @@ static PyExtensionClass BucketType = {
0L,0L, 0L,0L,
"Mapping type implemented as sorted list of items", "Mapping type implemented as sorted list of items",
METHOD_CHAIN(Bucket_methods), METHOD_CHAIN(Bucket_methods),
EXTENSIONCLASS_BASICNEW_FLAG | PERSISTENT_TYPE_FLAG EXTENSIONCLASS_BASICNEW_FLAG
#ifdef PERSISTENT
| PERSISTENT_TYPE_FLAG
#endif
| EXTENSIONCLASS_NOINSTDICT_FLAG, | EXTENSIONCLASS_NOINSTDICT_FLAG,
}; };
......
/* Setup template macros */ /* Setup template macros */
#define PERSISTENT
#define PREFIX "II" #define PREFIX "II"
#define INITMODULE initIIBTree #define INITMODULE initIIBTree
#define DEFAULT_MAX_BUCKET_SIZE 100 #define DEFAULT_MAX_BUCKET_SIZE 100
......
#define PERSISTENT
#define PREFIX "IO" #define PREFIX "IO"
#define DEFAULT_MAX_BUCKET_SIZE 32 #define DEFAULT_MAX_BUCKET_SIZE 32
#define INITMODULE initIOBTree #define INITMODULE initIOBTree
......
#define PERSISTENT
#define PREFIX "OI" #define PREFIX "OI"
#define INITMODULE initOIBTree #define INITMODULE initOIBTree
#define DEFAULT_MAX_BUCKET_SIZE 64 #define DEFAULT_MAX_BUCKET_SIZE 64
......
#define PERSISTENT
#define PREFIX "OO" #define PREFIX "OO"
#define INITMODULE initOOBTree #define INITMODULE initOOBTree
#define DEFAULT_MAX_BUCKET_SIZE 32 #define DEFAULT_MAX_BUCKET_SIZE 32
......
...@@ -215,9 +215,10 @@ static struct PyMethodDef Set_methods[] = { ...@@ -215,9 +215,10 @@ static struct PyMethodDef Set_methods[] = {
{"minKey", (PyCFunction) Bucket_minKey, METH_VARARGS, {"minKey", (PyCFunction) Bucket_minKey, METH_VARARGS,
"minKey([key]) -- Fine the minimum key\n\n" "minKey([key]) -- Fine the minimum key\n\n"
"If an argument is given, find the minimum >= the argument"}, "If an argument is given, find the minimum >= the argument"},
#ifdef PERSISTENT
{"_p_deactivate", (PyCFunction) bucket__p_deactivate, METH_VARARGS, {"_p_deactivate", (PyCFunction) bucket__p_deactivate, METH_VARARGS,
"_p_deactivate() -- Reinitialize from a newly created copy"}, "_p_deactivate() -- Reinitialize from a newly created copy"},
#endif
{"insert", (PyCFunction)Set_insert, METH_VARARGS, {"insert", (PyCFunction)Set_insert, METH_VARARGS,
"insert(id,[ignored]) -- Add a key to the set"}, "insert(id,[ignored]) -- Add a key to the set"},
{"remove", (PyCFunction)Set_remove, METH_VARARGS, {"remove", (PyCFunction)Set_remove, METH_VARARGS,
...@@ -311,7 +312,10 @@ static PyExtensionClass SetType = { ...@@ -311,7 +312,10 @@ static PyExtensionClass SetType = {
0L,0L, 0L,0L,
"Set implemented as sorted keys", "Set implemented as sorted keys",
METHOD_CHAIN(Set_methods), METHOD_CHAIN(Set_methods),
EXTENSIONCLASS_BASICNEW_FLAG | PERSISTENT_TYPE_FLAG EXTENSIONCLASS_BASICNEW_FLAG
#ifdef PERSISTENT
| PERSISTENT_TYPE_FLAG
#endif
| EXTENSIONCLASS_NOINSTDICT_FLAG, | EXTENSIONCLASS_NOINSTDICT_FLAG,
}; };
......
...@@ -126,8 +126,10 @@ static struct PyMethodDef TreeSet_methods[] = { ...@@ -126,8 +126,10 @@ static struct PyMethodDef TreeSet_methods[] = {
"insert(id,[ignored]) -- Add an id to the set"}, "insert(id,[ignored]) -- Add an id to the set"},
{"remove", (PyCFunction)TreeSet_remove, METH_VARARGS, {"remove", (PyCFunction)TreeSet_remove, METH_VARARGS,
"remove(id) -- Remove a key from the set"}, "remove(id) -- Remove a key from the set"},
#ifdef PERSISTENT
{"_p_deactivate", (PyCFunction) BTree__p_deactivate, METH_VARARGS, {"_p_deactivate", (PyCFunction) BTree__p_deactivate, METH_VARARGS,
"_p_deactivate() -- Reinitialize from a newly created copy"}, "_p_deactivate() -- Reinitialize from a newly created copy"},
#endif
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
...@@ -157,6 +159,9 @@ static PyExtensionClass TreeSetType = { ...@@ -157,6 +159,9 @@ static PyExtensionClass TreeSetType = {
0L,0L, 0L,0L,
"Set implemented as sorted tree of items", "Set implemented as sorted tree of items",
METHOD_CHAIN(TreeSet_methods), METHOD_CHAIN(TreeSet_methods),
EXTENSIONCLASS_BASICNEW_FLAG | PERSISTENT_TYPE_FLAG EXTENSIONCLASS_BASICNEW_FLAG
#ifdef PERSISTENT
| PERSISTENT_TYPE_FLAG
#endif
| EXTENSIONCLASS_NOINSTDICT_FLAG, | EXTENSIONCLASS_NOINSTDICT_FLAG,
}; };
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