Commit e97494b3 authored by Jeremy Hylton's avatar Jeremy Hylton

Revert previous set of checkins!

The code was intended to be added to the Zope3 branch, not modified on
the trunk.
parent 63970e79
...@@ -12,11 +12,23 @@ ...@@ -12,11 +12,23 @@
****************************************************************************/ ****************************************************************************/
#include "Python.h"
#ifdef PERSISTENT #ifdef PERSISTENT
#include "cPersistence.h" #include "cPersistence.h"
#include "cPersistenceAPI.h"
/***************************************************************
The following are macros that ought to be in cPersistence.h */
#ifndef PER_USE
#define PER_USE(O) \
(((O)->state != cPersistent_GHOST_STATE \
|| (cPersistenceCAPI->setstate((PyObject*)(O)) >= 0)) \
? (((O)->state==cPersistent_UPTODATE_STATE) \
? ((O)->state=cPersistent_STICKY_STATE) : 1) : 0)
#define PER_ACCESSED(O) ((O)->atime=((long)(time(NULL)/3))%65536)
#endif
/***************************************************************/ /***************************************************************/
#else #else
...@@ -58,7 +70,7 @@ typedef struct BTreeItemStruct { ...@@ -58,7 +70,7 @@ typedef struct BTreeItemStruct {
typedef struct Bucket_s { typedef struct Bucket_s {
#ifdef PERSISTENT #ifdef PERSISTENT
PyPersist_HEAD cPersistent_HEAD
#else #else
PyObject_HEAD PyObject_HEAD
#endif #endif
...@@ -76,7 +88,7 @@ static void PyVar_AssignB(Bucket **v, Bucket *e) { Py_XDECREF(*v); *v=e;} ...@@ -76,7 +88,7 @@ static void PyVar_AssignB(Bucket **v, Bucket *e) { Py_XDECREF(*v); *v=e;}
typedef struct { typedef struct {
#ifdef PERSISTENT #ifdef PERSISTENT
PyPersist_HEAD cPersistent_HEAD
#else #else
PyObject_HEAD PyObject_HEAD
#endif #endif
...@@ -85,7 +97,7 @@ typedef struct { ...@@ -85,7 +97,7 @@ typedef struct {
BTreeItem *data; BTreeItem *data;
} BTree; } BTree;
staticforward PyTypeObject BTreeType; staticforward PyExtensionClass BTreeType;
#define BTREE(O) ((BTree*)(O)) #define BTREE(O) ((BTree*)(O))
...@@ -258,7 +270,7 @@ static char BTree_module_documentation[] = ...@@ -258,7 +270,7 @@ static char BTree_module_documentation[] =
"\n" "\n"
MASTER_ID MASTER_ID
BTREEITEMSTEMPLATE_C BTREEITEMSTEMPLATE_C
"$Id: BTreeModuleTemplate.c,v 1.19 2002/02/20 23:59:51 jeremy Exp $\n" "$Id: BTreeModuleTemplate.c,v 1.20 2002/02/21 21:41:17 jeremy Exp $\n"
BTREETEMPLATE_C BTREETEMPLATE_C
BUCKETTEMPLATE_C BUCKETTEMPLATE_C
KEYMACROS_H KEYMACROS_H
...@@ -270,37 +282,44 @@ VALUEMACROS_H ...@@ -270,37 +282,44 @@ VALUEMACROS_H
BTREEITEMSTEMPLATE_C BTREEITEMSTEMPLATE_C
; ;
int
init_persist_type(PyTypeObject *type)
{
type->ob_type = &PyType_Type;
type->tp_getattro = PyPersist_TYPE->tp_getattro;
type->tp_setattro = PyPersist_TYPE->tp_setattro;
/* XXX for now */
type->tp_traverse = PyPersist_TYPE->tp_traverse;
type->tp_clear = PyPersist_TYPE->tp_clear;
return PyType_Ready(type);
}
void void
INITMODULE (void) INITMODULE (void)
{ {
PyObject *m, *d, *c; PyObject *m, *d, *c;
sort_str = PyString_InternFromString("sort"); UNLESS (sort_str=PyString_FromString("sort")) return;
if (!sort_str) UNLESS (reverse_str=PyString_FromString("reverse")) return;
return; UNLESS (items_str=PyString_FromString("items")) return;
reverse_str = PyString_InternFromString("reverse"); UNLESS (__setstate___str=PyString_FromString("__setstate__")) return;
if (!reverse_str)
return; UNLESS (PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI"))
__setstate___str = PyString_InternFromString("__setstate__");
if (!__setstate___str)
return; return;
#ifdef PERSISTENT
if ((cPersistenceCAPI=PyCObject_Import("cPersistence","CAPI")))
{
BucketType.methods.link=cPersistenceCAPI->methods;
BucketType.tp_getattro=cPersistenceCAPI->getattro;
BucketType.tp_setattro=cPersistenceCAPI->setattro;
SetType.methods.link=cPersistenceCAPI->methods;
SetType.tp_getattro=cPersistenceCAPI->getattro;
SetType.tp_setattro=cPersistenceCAPI->setattro;
BTreeType.methods.link=cPersistenceCAPI->methods;
BTreeType.tp_getattro=cPersistenceCAPI->getattro;
BTreeType.tp_setattro=cPersistenceCAPI->setattro;
TreeSetType.methods.link=cPersistenceCAPI->methods;
TreeSetType.tp_getattro=cPersistenceCAPI->getattro;
TreeSetType.tp_setattro=cPersistenceCAPI->setattro;
}
else return;
/* Grab the ConflictError class */ /* Grab the ConflictError class */
m = PyImport_ImportModule("ZODB.POSException"); m = PyImport_ImportModule("ZODB.POSException");
if (m != NULL) { if (m != NULL) {
c = PyObject_GetAttrString(m, "BTreesConflictError"); c = PyObject_GetAttrString(m, "BTreesConflictError");
if (c != NULL) if (c != NULL)
...@@ -313,40 +332,31 @@ INITMODULE (void) ...@@ -313,40 +332,31 @@ INITMODULE (void)
ConflictError=PyExc_ValueError; ConflictError=PyExc_ValueError;
} }
#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;
#ifdef INTSET_H #ifdef INTSET_H
UNLESS(d = PyImport_ImportModule("intSet")) return; UNLESS(d = PyImport_ImportModule("intSet")) return;
UNLESS(intSetType = PyObject_GetAttrString (d, "intSet")) return; UNLESS(intSetType = PyObject_GetAttrString (d, "intSet")) return;
Py_DECREF (d); Py_DECREF (d);
#endif #endif
/* Initialize the PyPersist_C_API and the type objects. */
PyPersist_C_API = PyCObject_Import("Persistence.cPersistence", "C_API");
if (PyPersist_C_API == NULL)
return;
BTreeItemsType.ob_type = &PyType_Type;
init_persist_type(&BucketType);
init_persist_type(&BTreeType);
init_persist_type(&SetType);
init_persist_type(&TreeSetType);
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("_" MOD_NAME_PREFIX "BTree", m = Py_InitModule4("_" MOD_NAME_PREFIX "BTree", module_methods,
module_methods, BTree_module_documentation, BTree_module_documentation,
(PyObject *)NULL, PYTHON_API_VERSION); (PyObject*)NULL,PYTHON_API_VERSION);
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
if (PyDict_SetItemString(d, MOD_NAME_PREFIX "Bucket",
(PyObject *)&BucketType) < 0) PyExtensionClass_Export(d,MOD_NAME_PREFIX "Bucket", BucketType);
return; PyExtensionClass_Export(d,MOD_NAME_PREFIX "BTree", BTreeType);
if (PyDict_SetItemString(d, MOD_NAME_PREFIX "BTree", PyExtensionClass_Export(d,MOD_NAME_PREFIX "Set", SetType);
(PyObject *)&BTreeType) < 0) PyExtensionClass_Export(d,MOD_NAME_PREFIX "TreeSet", TreeSetType);
return;
if (PyDict_SetItemString(d, MOD_NAME_PREFIX "Set",
(PyObject *)&SetType) < 0)
return;
if (PyDict_SetItemString(d, MOD_NAME_PREFIX "TreeSet",
(PyObject *)&TreeSetType) < 0)
return;
} }
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.22 2002/02/20 23:59:51 jeremy Exp $\n" #define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.23 2002/02/21 21:41:17 jeremy Exp $\n"
/* /*
** _BTree_get ** _BTree_get
...@@ -481,7 +481,7 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value, ...@@ -481,7 +481,7 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value,
|| (bchanged /* The bucket changed */ || (bchanged /* The bucket changed */
&& self->len == 1 /* We have only one */ && self->len == 1 /* We have only one */
&& ! SameType_Check(self, self->data->value) /* It's our child */ && ! SameType_Check(self, self->data->value) /* It's our child */
&& BUCKET(self->data->value)->po_oid == NULL /* It's in our record */ && BUCKET(self->data->value)->oid == NULL /* It's in our record */
) )
) )
if (PER_CHANGED(self) < 0) if (PER_CHANGED(self) < 0)
...@@ -570,10 +570,10 @@ _BTree_clear(BTree *self) ...@@ -570,10 +570,10 @@ _BTree_clear(BTree *self)
static PyObject * static PyObject *
BTree__p_deactivate(BTree *self, PyObject *args) BTree__p_deactivate(BTree *self, PyObject *args)
{ {
if (self->po_state == UPTODATE && self->po_dm) if (self->state==cPersistent_UPTODATE_STATE && self->jar)
{ {
if (_BTree_clear(self) < 0) return NULL; if (_BTree_clear(self) < 0) return NULL;
self->po_state = GHOST; self->state=cPersistent_GHOST_STATE;
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -619,7 +619,7 @@ BTree_getstate(BTree *self, PyObject *args) ...@@ -619,7 +619,7 @@ BTree_getstate(BTree *self, PyObject *args)
if (self->len == 1 if (self->len == 1
&& self->data->value->ob_type != self->ob_type && self->data->value->ob_type != self->ob_type
#ifdef PERSISTENT #ifdef PERSISTENT
&& BUCKET(self->data->value)->po_oid == NULL && BUCKET(self->data->value)->oid == NULL
#endif #endif
) )
{ {
...@@ -731,9 +731,9 @@ _BTree_setstate(BTree *self, PyObject *state, int noval) ...@@ -731,9 +731,9 @@ _BTree_setstate(BTree *self, PyObject *state, int noval)
{ {
if (! firstbucket) firstbucket=self->data->value; if (! firstbucket) firstbucket=self->data->value;
/* XXX what is this? */ UNLESS (ExtensionClassSubclassInstance_Check(
if (!PyObject_IsInstance(firstbucket, (PyObject *) firstbucket,
(noval ? &SetType : &BucketType))) noval ? &SetType : &BucketType))
{ {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"No firstbucket in non-empty BTree"); "No firstbucket in non-empty BTree");
...@@ -788,7 +788,7 @@ BTree__p_resolveConflict(BTree *self, PyObject *args) ...@@ -788,7 +788,7 @@ BTree__p_resolveConflict(BTree *self, PyObject *args)
UNLESS (s[i]==Py_None || PyTuple_Check(s[i])) UNLESS (s[i]==Py_None || PyTuple_Check(s[i]))
return merge_error(-100, -100, -100, -100); return merge_error(-100, -100, -100, -100);
if (PyObject_IsInstance((PyObject *)self, (PyObject *)&BTreeType)) if (ExtensionClassSubclassInstance_Check(self, &BTreeType))
r = _bucket__p_resolveConflict(OBJECT(&BucketType), s); r = _bucket__p_resolveConflict(OBJECT(&BucketType), s);
else else
r = _bucket__p_resolveConflict(OBJECT(&SetType), s); r = _bucket__p_resolveConflict(OBJECT(&SetType), s);
...@@ -1238,7 +1238,11 @@ static void ...@@ -1238,7 +1238,11 @@ static void
BTree_dealloc(BTree *self) BTree_dealloc(BTree *self)
{ {
_BTree_clear(self); _BTree_clear(self);
PyPersist_TYPE->tp_dealloc((PyObject *)self);
PER_DEL(self);
Py_DECREF(self->ob_type);
PyMem_DEL(self);
} }
static int static int
...@@ -1297,46 +1301,35 @@ static PyNumberMethods BTree_as_number_for_nonzero = { ...@@ -1297,46 +1301,35 @@ static PyNumberMethods BTree_as_number_for_nonzero = {
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
(inquiry)BTree_nonzero}; (inquiry)BTree_nonzero};
static PyTypeObject BTreeType = { static PyExtensionClass BTreeType = {
PyObject_HEAD_INIT(NULL) /* PyPersist_Type */ PyObject_HEAD_INIT(NULL)
0, /* ob_size */ 0, /*ob_size*/
"Persistence.BTrees.OOBTree." MOD_NAME_PREFIX "BTree", /* tp_name */ MOD_NAME_PREFIX "BTree", /*tp_name*/
sizeof(BTree), /* tp_basicsize */ sizeof(BTree), /*tp_basicsize*/
0, /* tp_itemsize */ 0, /*tp_itemsize*/
(destructor)BTree_dealloc, /* tp_dealloc */ /************* methods ********************/
0, /* tp_print */ (destructor) BTree_dealloc,/*tp_dealloc*/
0, /* tp_getattr */ (printfunc)0, /*tp_print*/
0, /* tp_setattr */ (getattrfunc)0, /*obsolete tp_getattr*/
0, /* tp_compare */ (setattrfunc)0, /*obsolete tp_setattr*/
0, /* tp_repr */ (cmpfunc)0, /*tp_compare*/
&BTree_as_number_for_nonzero, /* tp_as_number */ (reprfunc)0, /*tp_repr*/
0, /* tp_as_sequence */ &BTree_as_number_for_nonzero, /*tp_as_number*/
&BTree_as_mapping, /* tp_as_mapping */ 0, /*tp_as_sequence*/
0, /* tp_hash */ &BTree_as_mapping, /*tp_as_mapping*/
0, /* tp_call */ (hashfunc)0, /*tp_hash*/
0, /* tp_str */ (ternaryfunc)0, /*tp_call*/
0, /* tp_getattro */ (reprfunc)0, /*tp_str*/
0, /* tp_setattro */ (getattrofunc)0,
0, /* tp_as_buffer */ 0, /*tp_setattro*/
/* XXX need to define traverse and clear functions */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | /* Space for future expansion */
Py_TPFLAGS_BASETYPE, /* tp_flags */ 0L,0L,
0, /* tp_doc */ "Mapping type implemented as sorted list of items",
0, /* tp_traverse */ METHOD_CHAIN(BTree_methods),
0, /* tp_clear */ EXTENSIONCLASS_BASICNEW_FLAG
0, /* tp_richcompare */ #ifdef PERSISTENT
0, /* tp_weaklistoffset */ | PERSISTENT_TYPE_FLAG
0, /* tp_iter */ #endif
0, /* tp_iternext */ | EXTENSIONCLASS_NOINSTDICT_FLAG,
BTree_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
}; };
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.26 2002/02/20 23:59:51 jeremy Exp $\n" #define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.27 2002/02/21 21:41:17 jeremy Exp $\n"
/* /*
** _bucket_get ** _bucket_get
...@@ -806,10 +806,10 @@ _bucket_clear(Bucket *self) ...@@ -806,10 +806,10 @@ _bucket_clear(Bucket *self)
static PyObject * static PyObject *
bucket__p_deactivate(Bucket *self, PyObject *args) bucket__p_deactivate(Bucket *self, PyObject *args)
{ {
if (self->po_state == UPTODATE && self->po_dm) if (self->state==cPersistent_UPTODATE_STATE && self->jar)
{ {
if (_bucket_clear(self) < 0) return NULL; if (_bucket_clear(self) < 0) return NULL;
self->po_state = GHOST; self->state=cPersistent_GHOST_STATE;
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -1130,10 +1130,14 @@ static struct PyMethodDef Bucket_methods[] = { ...@@ -1130,10 +1130,14 @@ static struct PyMethodDef Bucket_methods[] = {
}; };
static void static void
bucket_dealloc(Bucket *self) Bucket_dealloc(Bucket *self)
{ {
_bucket_clear(self); _bucket_clear(self);
PyPersist_TYPE->tp_dealloc((PyObject *)self);
PER_DEL(self);
Py_DECREF(self->ob_type);
PyMem_DEL(self);
} }
/* Code to access Bucket objects as mappings */ /* Code to access Bucket objects as mappings */
...@@ -1160,11 +1164,8 @@ bucket_repr(Bucket *self) ...@@ -1160,11 +1164,8 @@ bucket_repr(Bucket *self)
static PyObject *format; static PyObject *format;
PyObject *r, *t; PyObject *r, *t;
if (format == NULL) { UNLESS (format) UNLESS (format=PyString_FromString(MOD_NAME_PREFIX "Bucket(%s)"))
format = PyString_FromString(MOD_NAME_PREFIX "Bucket(%s)"); return NULL;
if (format == NULL)
return NULL;
}
UNLESS (t=PyTuple_New(1)) return NULL; UNLESS (t=PyTuple_New(1)) return NULL;
UNLESS (r=bucket_items(self,NULL)) goto err; UNLESS (r=bucket_items(self,NULL)) goto err;
PyTuple_SET_ITEM(t,0,r); PyTuple_SET_ITEM(t,0,r);
...@@ -1176,50 +1177,40 @@ err: ...@@ -1176,50 +1177,40 @@ err:
return NULL; return NULL;
} }
static PyTypeObject BucketType = { static PyExtensionClass BucketType = {
PyObject_HEAD_INIT(NULL) /* PyPersist_Type */ PyObject_HEAD_INIT(NULL)
0, /* ob_size */ 0, /*ob_size*/
MOD_NAME_PREFIX "Bucket", /* tp_name */ MOD_NAME_PREFIX "Bucket", /*tp_name*/
sizeof(Bucket), /* tp_basicsize */ sizeof(Bucket), /*tp_basicsize*/
0, /* tp_itemsize */ 0, /*tp_itemsize*/
(destructor)bucket_dealloc, /* tp_dealloc */ /*********** methods ***********************/
0, /* tp_print */ (destructor) Bucket_dealloc, /*tp_dealloc*/
0, /* tp_getattr */ (printfunc)0, /*tp_print*/
0, /* tp_setattr */ (getattrfunc)0, /*obsolete tp_getattr*/
0, /* tp_compare */ (setattrfunc)0, /*obsolete tp_setattr*/
(reprfunc)bucket_repr, /* tp_repr */ (cmpfunc)0, /*tp_compare*/
0, /* tp_as_number */ (reprfunc) bucket_repr, /*tp_repr*/
0, /* tp_as_sequence */ 0, /*tp_as_number*/
&Bucket_as_mapping, /* tp_as_mapping */ 0, /*tp_as_sequence*/
0, /* tp_hash */ &Bucket_as_mapping, /*tp_as_mapping*/
0, /* tp_call */ (hashfunc)0, /*tp_hash*/
0, /* tp_str */ (ternaryfunc)0, /*tp_call*/
0, /* tp_getattro */ (reprfunc)0, /*tp_str*/
0, /* tp_setattro */ (getattrofunc)0, /*tp_getattro*/
0, /* tp_as_buffer */ 0, /*tp_setattro*/
/* XXX need to define traverse and clear functions */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | /* Space for future expansion */
Py_TPFLAGS_BASETYPE, /* tp_flags */ 0L,0L,
0, /* tp_doc */ "Mapping type implemented as sorted list of items",
0, /* tp_traverse */ METHOD_CHAIN(Bucket_methods),
0, /* tp_clear */ EXTENSIONCLASS_BASICNEW_FLAG
0, /* tp_richcompare */ #ifdef PERSISTENT
0, /* tp_weaklistoffset */ | PERSISTENT_TYPE_FLAG
0, /* tp_iter */ #endif
0, /* tp_iternext */ | EXTENSIONCLASS_NOINSTDICT_FLAG,
Bucket_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
}; };
static int static int
nextBucket(SetIteration *i) nextBucket(SetIteration *i)
{ {
......
...@@ -17,6 +17,6 @@ from _OIBTree import * ...@@ -17,6 +17,6 @@ from _OIBTree import *
# We don't really want _ names in pickles, so update all of the __module__ # We don't really want _ names in pickles, so update all of the __module__
# references. # references.
##for o in globals().values(): for o in globals().values():
## if hasattr(o, '__module__'): if hasattr(o, '__module__'):
## o.__module__=__name__ o.__module__=__name__
...@@ -17,21 +17,6 @@ from _OOBTree import * ...@@ -17,21 +17,6 @@ from _OOBTree import *
# We don't really want _ names in pickles, so update all of the __module__ # We don't really want _ names in pickles, so update all of the __module__
# references. # references.
##for o in globals().values(): for o in globals().values():
## print o if hasattr(o, '__module__'):
## if hasattr(o, '__module__'): o.__module__=__name__
## o.__module__=__name__
# XXX can't figure out why _reduce() won't call our __getstate__.
import copy_reg
def pickle_OOBTree(t):
return t.__class__, t.__getstate__()
def unpickle_OOBTree(state):
obj = OOBTree.__new__(OOBTree, None)
obj.__setstate__(state)
return obj
copy_reg.pickle(OOBTree, pickle_OOBTree)
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
Set operations Set operations
****************************************************************************/ ****************************************************************************/
#define SETOPTEMPLATE_C "$Id: SetOpTemplate.c,v 1.11 2002/02/20 23:59:51 jeremy Exp $\n" #define SETOPTEMPLATE_C "$Id: SetOpTemplate.c,v 1.12 2002/02/21 21:41:17 jeremy Exp $\n"
#ifdef INTSET_H #ifdef INTSET_H
static int static int
...@@ -67,7 +67,7 @@ initSetIteration(SetIteration *i, PyObject *s, int w, int *merge) ...@@ -67,7 +67,7 @@ initSetIteration(SetIteration *i, PyObject *s, int w, int *merge)
{ {
i->position=0; i->position=0;
if (PyObject_IsInstance(s, (PyObject *)&BucketType)) if (ExtensionClassSubclassInstance_Check(s, &BucketType))
{ {
i->set = s; i->set = s;
Py_INCREF(s); Py_INCREF(s);
...@@ -82,7 +82,7 @@ initSetIteration(SetIteration *i, PyObject *s, int w, int *merge) ...@@ -82,7 +82,7 @@ initSetIteration(SetIteration *i, PyObject *s, int w, int *merge)
i->hasValue=1; i->hasValue=1;
} }
else if (PyObject_IsInstance(s, (PyObject *)&SetType)) else if (ExtensionClassSubclassInstance_Check(s, &SetType))
{ {
i->set = s; i->set = s;
Py_INCREF(s); Py_INCREF(s);
...@@ -90,7 +90,7 @@ initSetIteration(SetIteration *i, PyObject *s, int w, int *merge) ...@@ -90,7 +90,7 @@ initSetIteration(SetIteration *i, PyObject *s, int w, int *merge)
i->next=nextSet; i->next=nextSet;
i->hasValue=0; i->hasValue=0;
} }
else if (PyObject_IsInstance(s, (PyObject *)&BTreeType)) else if (ExtensionClassSubclassInstance_Check(s, &BTreeType))
{ {
i->set=BTree_rangeSearch(BTREE(s), NULL, 'i'); i->set=BTree_rangeSearch(BTREE(s), NULL, 'i');
UNLESS(i->set) return -1; UNLESS(i->set) return -1;
...@@ -104,7 +104,7 @@ initSetIteration(SetIteration *i, PyObject *s, int w, int *merge) ...@@ -104,7 +104,7 @@ initSetIteration(SetIteration *i, PyObject *s, int w, int *merge)
i->next=nextTreeSetItems; i->next=nextTreeSetItems;
i->hasValue=1; i->hasValue=1;
} }
else if (PyObject_IsInstance(s, (PyObject *)&TreeSetType)) else if (ExtensionClassSubclassInstance_Check(s, &TreeSetType))
{ {
i->set=BTree_rangeSearch(BTREE(s), NULL, 'k'); i->set=BTree_rangeSearch(BTREE(s), NULL, 'k');
UNLESS(i->set) return -1; UNLESS(i->set) return -1;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define SETTEMPLATE_C "$Id: SetTemplate.c,v 1.14 2002/02/20 23:59:51 jeremy Exp $\n" #define SETTEMPLATE_C "$Id: SetTemplate.c,v 1.15 2002/02/21 21:41:17 jeremy Exp $\n"
static PyObject * static PyObject *
Set_insert(Bucket *self, PyObject *args) Set_insert(Bucket *self, PyObject *args)
...@@ -236,48 +236,37 @@ static PySequenceMethods set_as_sequence = { ...@@ -236,48 +236,37 @@ static PySequenceMethods set_as_sequence = {
(intintobjargproc)0, /*sq_ass_slice*/ (intintobjargproc)0, /*sq_ass_slice*/
}; };
static PyTypeObject SetType = { static PyExtensionClass SetType = {
PyObject_HEAD_INIT(NULL) /* PyPersist_Type */ PyObject_HEAD_INIT(NULL)
0, /* ob_size */ 0, /*ob_size*/
MOD_NAME_PREFIX "Set", /* tp_name */ MOD_NAME_PREFIX "Set", /*tp_name*/
sizeof(Bucket), /* tp_basicsize */ sizeof(Bucket), /*tp_basicsize*/
0, /* tp_itemsize */ 0, /*tp_itemsize*/
(destructor)bucket_dealloc, /* tp_dealloc */ /*********** methods ***********************/
0, /* tp_print */ (destructor) Bucket_dealloc, /*tp_dealloc*/
0, /* tp_getattr */ (printfunc)0, /*tp_print*/
0, /* tp_setattr */ (getattrfunc)0, /*obsolete tp_getattr*/
0, /* tp_compare */ (setattrfunc)0, /*obsolete tp_setattr*/
(reprfunc)set_repr, /* tp_repr */ (cmpfunc)0, /*tp_compare*/
0, /* tp_as_number */ (reprfunc) set_repr, /*tp_repr*/
&set_as_sequence, /* tp_as_sequence */ 0, /*tp_as_number*/
0, /* tp_as_mapping */ &set_as_sequence, /*tp_as_sequence*/
0, /* tp_hash */ 0, /*tp_as_mapping*/
0, /* tp_call */ (hashfunc)0, /*tp_hash*/
0, /* tp_str */ (ternaryfunc)0, /*tp_call*/
0, /* tp_getattro */ (reprfunc)0, /*tp_str*/
0, /* tp_setattro */ (getattrofunc)0, /*tp_getattro*/
0, /* tp_as_buffer */ 0, /*tp_setattro*/
/* XXX need to define traverse and clear functions */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | /* Space for future expansion */
Py_TPFLAGS_BASETYPE, /* tp_flags */ 0L,0L,
0, /* tp_doc */ "Set implemented as sorted keys",
0, /* tp_traverse */ METHOD_CHAIN(Set_methods),
0, /* tp_clear */ EXTENSIONCLASS_BASICNEW_FLAG
0, /* tp_richcompare */ #ifdef PERSISTENT
0, /* tp_weaklistoffset */ | PERSISTENT_TYPE_FLAG
0, /* tp_iter */ #endif
0, /* tp_iternext */ | EXTENSIONCLASS_NOINSTDICT_FLAG,
Set_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
}; };
static int static int
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define TREESETTEMPLATE_C "$Id: TreeSetTemplate.c,v 1.12 2002/02/20 23:59:51 jeremy Exp $\n" #define TREESETTEMPLATE_C "$Id: TreeSetTemplate.c,v 1.13 2002/02/21 21:41:17 jeremy Exp $\n"
static PyObject * static PyObject *
TreeSet_insert(BTree *self, PyObject *args) TreeSet_insert(BTree *self, PyObject *args)
...@@ -127,46 +127,35 @@ static PyMappingMethods TreeSet_as_mapping = { ...@@ -127,46 +127,35 @@ static PyMappingMethods TreeSet_as_mapping = {
(inquiry)BTree_length, /*mp_length*/ (inquiry)BTree_length, /*mp_length*/
}; };
static PyTypeObject TreeSetType = { static PyExtensionClass TreeSetType = {
PyObject_HEAD_INIT(NULL) /* PyPersist_Type */ PyObject_HEAD_INIT(NULL)
0, /* ob_size */ 0, /*ob_size*/
MOD_NAME_PREFIX "TreeSet", /* tp_name */ MOD_NAME_PREFIX "TreeSet", /*tp_name*/
sizeof(BTree), /* tp_basicsize */ sizeof(BTree), /*tp_basicsize*/
0, /* tp_itemsize */ 0, /*tp_itemsize*/
(destructor)BTree_dealloc, /* tp_dealloc */ /************* methods ********************/
0, /* tp_print */ (destructor) BTree_dealloc, /*tp_dealloc*/
0, /* tp_getattr */ (printfunc)0, /*tp_print*/
0, /* tp_setattr */ (getattrfunc)0, /*obsolete tp_getattr*/
0, /* tp_compare */ (setattrfunc)0, /*obsolete tp_setattr*/
0, /* tp_repr */ (cmpfunc)0, /*tp_compare*/
&BTree_as_number_for_nonzero, /* tp_as_number */ (reprfunc)0, /*tp_repr*/
0, /* tp_as_sequence */ &BTree_as_number_for_nonzero, /*tp_as_number*/
&TreeSet_as_mapping, /* tp_as_mapping */ 0, /*tp_as_sequence*/
0, /* tp_hash */ &TreeSet_as_mapping, /*tp_as_mapping*/
0, /* tp_call */ (hashfunc)0, /*tp_hash*/
0, /* tp_str */ (ternaryfunc)0, /*tp_call*/
0, /* tp_getattro */ (reprfunc)0, /*tp_str*/
0, /* tp_setattro */ (getattrofunc)0,
0, /* tp_as_buffer */ 0, /*tp_setattro*/
/* XXX need to define traverse and clear functions */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | /* Space for future expansion */
Py_TPFLAGS_BASETYPE, /* tp_flags */ 0L,0L,
0, /* tp_doc */ "Set implemented as sorted tree of items",
0, /* tp_traverse */ METHOD_CHAIN(TreeSet_methods),
0, /* tp_clear */ EXTENSIONCLASS_BASICNEW_FLAG
0, /* tp_richcompare */ #ifdef PERSISTENT
0, /* tp_weaklistoffset */ | PERSISTENT_TYPE_FLAG
0, /* tp_iter */ #endif
0, /* tp_iternext */ | EXTENSIONCLASS_NOINSTDICT_FLAG,
TreeSet_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
}; };
/* Setup template macros */ /* Setup template macros */
#define MASTER_ID "$Id: _IIBTree.c,v 1.4 2002/02/20 23:59:51 jeremy Exp $\n" #define MASTER_ID "$Id: _IIBTree.c,v 1.5 2002/02/21 21:41:17 jeremy Exp $\n"
#define PERSISTENT #define PERSISTENT
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "intkeymacros.h" #include "intkeymacros.h"
#include "intvaluemacros.h" #include "intvaluemacros.h"
#include "cPersistence.h"
#ifndef EXCLUDE_INTSET_SUPPORT #ifndef EXCLUDE_INTSET_SUPPORT
#include "BTree/intSet.h" #include "BTree/intSet.h"
#endif #endif
......
#define MASTER_ID "$Id: _IOBTree.c,v 1.4 2002/02/20 23:59:51 jeremy Exp $\n" #define MASTER_ID "$Id: _IOBTree.c,v 1.5 2002/02/21 21:41:17 jeremy Exp $\n"
#define PERSISTENT #define PERSISTENT
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "intkeymacros.h" #include "intkeymacros.h"
#include "objectvaluemacros.h" #include "objectvaluemacros.h"
#include "cPersistence.h"
#ifndef EXCLUDE_INTSET_SUPPORT #ifndef EXCLUDE_INTSET_SUPPORT
#include "BTree/intSet.h" #include "BTree/intSet.h"
#endif #endif
......
##import ZODB import ZODB
##try: import intSet try: import intSet
##except: pass except: pass
##else: del intSet else: del intSet
### Register interfaces # Register interfaces
##try: import Interface try: import Interface
##except ImportError: pass # Don't register interfaces if no scarecrow except ImportError: pass # Don't register interfaces if no scarecrow
##else: else:
## import Interfaces import Interfaces
## del Interfaces del Interfaces
## del Interface del Interface
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