Commit 16da5f56 authored by Jim Fulton's avatar Jim Fulton

Merged Jeremy and Tim's changes from the zodb33-devel-branch.

parent 1b7d62c3
This diff is collapsed.
...@@ -12,34 +12,20 @@ ...@@ -12,34 +12,20 @@
****************************************************************************/ ****************************************************************************/
#include "Python.h"
/* include structmember.h for offsetof */
#include "structmember.h"
#ifdef PERSISTENT #ifdef PERSISTENT
#include "cPersistence.h" #include "cPersistence.h"
//#include "persistence/persistenceAPI.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
#include "ExtensionClass.h"
#define PER_USE_OR_RETURN(self, NULL) #define PER_USE_OR_RETURN(self, NULL)
#define PER_ALLOW_DEACTIVATION(self) #define PER_ALLOW_DEACTIVATION(self)
#define PER_PREVENT_DEACTIVATION(self) #define PER_PREVENT_DEACTIVATION(self)
#define PER_DEL(self) #define PER_DEL(self)
#define PER_USE(O) 1 #define PER_USE(O) 1
#define PER_ACCESSED(O) 1 #define PER_ACCESSED(O) 1
#define PER_CHANGED(O) 0
#endif #endif
/* So sue me. This pair gets used all over the place, so much so that it /* So sue me. This pair gets used all over the place, so much so that it
...@@ -53,15 +39,23 @@ ...@@ -53,15 +39,23 @@
PER_ACCESSED(OBJ); \ PER_ACCESSED(OBJ); \
} while (0) } while (0)
static PyObject *sort_str, *reverse_str, *items_str, *__setstate___str; /*
The tp_name slots of the various BTree types contain the fully
qualified names of the types, e.g. zodb.btrees.OOBTree.OOBTree.
The full name is usd to support pickling and because it is not
possible to modify the __module__ slot of a type dynamically. (This
may be a bug in Python 2.2).
*/
#define MODULE_NAME "BTrees._" MOD_NAME_PREFIX "BTree."
static PyObject *sort_str, *reverse_str, *__setstate___str,
*_bucket_type_str;
static PyObject *ConflictError = NULL; static PyObject *ConflictError = NULL;
static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;} static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
#define ASSIGN(V,E) PyVar_Assign(&(V),(E)) #define ASSIGN(V,E) PyVar_Assign(&(V),(E))
#define ASSIGNC(V,E) (Py_INCREF((E)), PyVar_Assign(&(V),(E)))
#define UNLESS(E) if (!(E)) #define UNLESS(E) if (!(E))
#define UNLESS_ASSIGN(V,E) ASSIGN(V,E); UNLESS(V)
#define LIST(O) ((PyListObject*)(O))
#define OBJECT(O) ((PyObject*)(O)) #define OBJECT(O) ((PyObject*)(O))
#define MIN_BUCKET_ALLOC 16 #define MIN_BUCKET_ALLOC 16
...@@ -150,7 +144,8 @@ typedef struct BTree_s { ...@@ -150,7 +144,8 @@ typedef struct BTree_s {
BTreeItem *data; BTreeItem *data;
} BTree; } BTree;
staticforward PyExtensionClass BTreeType; static PyTypeObject BTreeType;
static PyTypeObject BucketType;
#define BTREE(O) ((BTree*)(O)) #define BTREE(O) ((BTree*)(O))
...@@ -252,16 +247,16 @@ finiSetIteration(SetIteration *i) ...@@ -252,16 +247,16 @@ finiSetIteration(SetIteration *i)
static PyObject * static PyObject *
IndexError(int i) IndexError(int i)
{ {
PyObject *v; PyObject *v;
v=PyInt_FromLong(i); v = PyInt_FromLong(i);
UNLESS (v) { if (!v) {
v=Py_None; v = Py_None;
Py_INCREF(v); Py_INCREF(v);
} }
PyErr_SetObject(PyExc_IndexError, v); PyErr_SetObject(PyExc_IndexError, v);
Py_DECREF(v); Py_DECREF(v);
return NULL; return NULL;
} }
/* Search for the bucket immediately preceding *current, in the bucket chain /* Search for the bucket immediately preceding *current, in the bucket chain
...@@ -286,8 +281,7 @@ PreviousBucket(Bucket **current, Bucket *first) ...@@ -286,8 +281,7 @@ PreviousBucket(Bucket **current, Bucket *first)
trailing = first; trailing = first;
PER_USE_OR_RETURN(first, -1); PER_USE_OR_RETURN(first, -1);
first = first->next; first = first->next;
PER_ALLOW_DEACTIVATION(trailing); PER_UNUSE(trailing);
PER_ACCESSED(trailing);
if (first == *current) { if (first == *current) {
*current = trailing; *current = trailing;
...@@ -300,33 +294,45 @@ PreviousBucket(Bucket **current, Bucket *first) ...@@ -300,33 +294,45 @@ PreviousBucket(Bucket **current, Bucket *first)
} }
static void * static void *
PyMalloc(size_t sz) BTree_Malloc(size_t sz)
{ {
void *r; void *r;
ASSERT(sz > 0, "non-positive size malloc", NULL); ASSERT(sz > 0, "non-positive size malloc", NULL);
if ((r = malloc(sz))) return r; r = malloc(sz);
if (r)
return r;
PyErr_NoMemory(); PyErr_NoMemory();
return NULL; return NULL;
} }
static void * static void *
PyRealloc(void *p, size_t sz) BTree_Realloc(void *p, size_t sz)
{ {
void *r; void *r;
ASSERT(sz > 0, "non-positive size realloc", NULL); ASSERT(sz > 0, "non-positive size realloc", NULL);
if (p) r = realloc(p,sz); if (p)
else r = malloc(sz); r = realloc(p, sz);
else
r = malloc(sz);
UNLESS (r) PyErr_NoMemory(); UNLESS (r)
PyErr_NoMemory();
return r; return r;
} }
/* Shared keyword-argument list for BTree/Bucket
* (iter)?(keys|values|items)
*/
static char *search_keywords[] = {"min", "max",
"excludemin", "excludemax",
0};
#include "BTreeItemsTemplate.c" #include "BTreeItemsTemplate.c"
#include "BucketTemplate.c" #include "BucketTemplate.c"
#include "SetTemplate.c" #include "SetTemplate.c"
...@@ -373,7 +379,7 @@ static char BTree_module_documentation[] = ...@@ -373,7 +379,7 @@ static char BTree_module_documentation[] =
"\n" "\n"
MASTER_ID MASTER_ID
BTREEITEMSTEMPLATE_C BTREEITEMSTEMPLATE_C
"$Id: BTreeModuleTemplate.c,v 1.37 2002/06/25 22:02:27 tim_one Exp $\n" "$Id: BTreeModuleTemplate.c,v 1.38 2003/11/28 16:44:44 jim Exp $\n"
BTREETEMPLATE_C BTREETEMPLATE_C
BUCKETTEMPLATE_C BUCKETTEMPLATE_C
KEYMACROS_H KEYMACROS_H
...@@ -385,81 +391,99 @@ VALUEMACROS_H ...@@ -385,81 +391,99 @@ VALUEMACROS_H
BTREEITEMSTEMPLATE_C BTREEITEMSTEMPLATE_C
; ;
void int
INITMODULE (void) init_persist_type(PyTypeObject *type)
{ {
PyObject *m, *d, *c; type->ob_type = &PyType_Type;
type->tp_base = cPersistenceCAPI->pertype;
UNLESS (sort_str=PyString_FromString("sort")) return;
UNLESS (reverse_str=PyString_FromString("reverse")) return;
UNLESS (items_str=PyString_FromString("items")) return;
UNLESS (__setstate___str=PyString_FromString("__setstate__")) return;
UNLESS (PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI"))
return;
#ifdef PERSISTENT if (PyType_Ready(type) < 0)
if ((cPersistenceCAPI=PyCObject_Import("cPersistence","CAPI"))) return 0;
{
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 */
m = PyImport_ImportModule("ZODB.POSException"); return 1;
}
if (m != NULL) { void
INITMODULE (void)
{
PyObject *m, *d, *c;
sort_str = PyString_InternFromString("sort");
if (!sort_str)
return;
reverse_str = PyString_InternFromString("reverse");
if (!reverse_str)
return;
__setstate___str = PyString_InternFromString("__setstate__");
if (!__setstate___str)
return;
_bucket_type_str = PyString_InternFromString("_bucket_type");
if (!_bucket_type_str)
return;
/* Grab the ConflictError class */
m = PyImport_ImportModule("ZODB.POSException");
if (m != NULL) {
c = PyObject_GetAttrString(m, "BTreesConflictError"); c = PyObject_GetAttrString(m, "BTreesConflictError");
if (c != NULL) if (c != NULL)
ConflictError = c; ConflictError = c;
Py_DECREF(m); Py_DECREF(m);
} }
if (ConflictError == NULL) { if (ConflictError == NULL) {
Py_INCREF(PyExc_ValueError); Py_INCREF(PyExc_ValueError);
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
UNLESS(d = PyImport_ImportModule("intSet")) return;
UNLESS(intSetType = PyObject_GetAttrString (d, "intSet")) return;
Py_DECREF (d);
#endif
/* Create the module and add the functions */
m = Py_InitModule4("_" MOD_NAME_PREFIX "BTree", module_methods,
BTree_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
/* Add some symbolic constants to the module */ /* Initialize the PyPersist_C_API and the type objects. */
d = PyModule_GetDict(m); cPersistenceCAPI = PyCObject_Import("persistent.cPersistence", "CAPI");
if (cPersistenceCAPI == NULL)
return;
BTreeItemsType.ob_type = &PyType_Type;
BTreeIter_Type.ob_type = &PyType_Type;
BTreeIter_Type.tp_getattro = PyObject_GenericGetAttr;
BucketType.tp_new = PyType_GenericNew;
SetType.tp_new = PyType_GenericNew;
BTreeType.tp_new = PyType_GenericNew;
TreeSetType.tp_new = PyType_GenericNew;
if (!init_persist_type(&BucketType))
return;
if (!init_persist_type(&BTreeType))
return;
if (!init_persist_type(&SetType))
return;
if (!init_persist_type(&TreeSetType))
return;
if (PyDict_SetItem(BTreeType.tp_dict, _bucket_type_str,
(PyObject *)&BucketType) < 0) {
fprintf(stderr, "btree failed\n");
return;
}
if (PyDict_SetItem(TreeSetType.tp_dict, _bucket_type_str,
(PyObject *)&SetType) < 0) {
fprintf(stderr, "bucket failed\n");
return;
}
PyExtensionClass_Export(d,MOD_NAME_PREFIX "Bucket", BucketType); /* Create the module and add the functions */
PyExtensionClass_Export(d,MOD_NAME_PREFIX "BTree", BTreeType); m = Py_InitModule4("_" MOD_NAME_PREFIX "BTree",
PyExtensionClass_Export(d,MOD_NAME_PREFIX "Set", SetType); module_methods, BTree_module_documentation,
PyExtensionClass_Export(d,MOD_NAME_PREFIX "TreeSet", TreeSetType); (PyObject *)NULL, PYTHON_API_VERSION);
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
if (PyDict_SetItemString(d, MOD_NAME_PREFIX "Bucket",
(PyObject *)&BucketType) < 0)
return;
if (PyDict_SetItemString(d, MOD_NAME_PREFIX "BTree",
(PyObject *)&BTreeType) < 0)
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;
} }
This diff is collapsed.
This diff is collapsed.
...@@ -14,8 +14,3 @@ ...@@ -14,8 +14,3 @@
# hack to overcome dynamic-linking headache. # hack to overcome dynamic-linking headache.
from _IIBTree import * from _IIBTree import *
# We don't really want _ names in pickles, so update all of the __module__
# references.
for obj in IIBucket, IIBTree, IISet, IITreeSet:
obj.__module__ = __name__
...@@ -14,8 +14,3 @@ ...@@ -14,8 +14,3 @@
# hack to overcome dynamic-linking headache. # hack to overcome dynamic-linking headache.
from _IOBTree import * from _IOBTree import *
# We don't really want _ names in pickles, so update all of the __module__
# references.
for obj in IOBucket, IOBTree, IOSet, IOTreeSet:
obj.__module__ = __name__
...@@ -348,6 +348,38 @@ class IIMerge(IMerge): ...@@ -348,6 +348,38 @@ class IIMerge(IMerge):
Note that c1 and c2 must be collections. Note that c1 and c2 must be collections.
""" """
class IMergeIntegerKey(IMerge):
"""IMerge-able objects with integer keys.
Concretely, this means the types in IOBTree and IIBTree.
"""
def multiunion(seq):
"""Return union of (zero or more) integer sets, as an integer set.
seq is a sequence of objects each convertible to an integer set.
These objects are convertible to an integer set:
+ An integer, which is added to the union.
+ A Set or TreeSet from the same module (for example, an
IIBTree.TreeSet for IIBTree.multiunion()). The elements of the
set are added to the union.
+ A Bucket or BTree from the same module (for example, an
IOBTree.IOBTree for IOBTree.multiunion()). The keys of the
mapping are added to the union.
The union is returned as a Set from the same module (for example,
IIBTree.multiunion() returns an IIBTree.IISet).
The point to this method is that it can run much faster than
doing a sequence of two-input union() calls. Under the covers,
all the integers in all the inputs are sorted via a single
linear-time radix sort, then duplicates are removed in a second
linear-time pass.
"""
############################################################### ###############################################################
# IMPORTANT NOTE # IMPORTANT NOTE
# #
...@@ -359,7 +391,10 @@ class IIMerge(IMerge): ...@@ -359,7 +391,10 @@ class IIMerge(IMerge):
# #
################################################################ ################################################################
OOBTree.OOSet.__implements__=ISet # XXX Need to use the new declaration syntax once it is available
OOBTree.OOTreeSet.__implements__=ITreeSet # for Zope 2.
OOBTree.OOBucket.__implements__=IDictionaryIsh
OOBTree.OOBTree.__implements__=IBTree ## OOBTree.OOSet.__implements__=ISet
## OOBTree.OOTreeSet.__implements__=ITreeSet
## OOBTree.OOBucket.__implements__=IDictionaryIsh
## OOBTree.OOBTree.__implements__=IBTree
...@@ -12,32 +12,47 @@ ...@@ -12,32 +12,47 @@
# #
############################################################################## ##############################################################################
import Persistence import persistent
class Length(Persistence.Persistent): class Length(persistent.Persistent):
"""BTree lengths are too expensive to compute """BTree lengths are too expensive to compute
Objects that use BTrees need to keep track of lengths themselves. Objects that use BTrees need to keep track of lengths themselves.
This class provides an object for doing this. This class provides an object for doing this.
As a bonus, the object support application-level conflict resolution. As a bonus, the object support application-level conflict
resolution.
It is tempting to to assign length objects to __len__ attributes
to provide instance-specific __len__ methods. However, this no
longer works as expected, because new-style classes cache
class-defined slot methods (like __len__) in C type slots. Thus,
instance-define slot fillers are ignores.
""" """
def __init__(self, v=0): self.value=v def __init__(self, v=0):
self.value = v
def __getstate__(self): return self.value def __getstate__(self):
return self.value
def __setstate__(self, v): self.value=v def __setstate__(self, v):
self.value = v
def set(self, v): self.value=v def set(self, v):
self.value = v
def _p_resolveConflict(self, old, s1, s2): return s1 + s2 - old def _p_resolveConflict(self, old, s1, s2):
return s1 + s2 - old
def _p_independent(self): def _p_independent(self):
# My state doesn't depend on or materially effect the state of # My state doesn't depend on or materially effect the state of
# other objects. # other objects.
return 1 return 1
def change(self, delta): self.value = self.value + delta def change(self, delta):
self.value += delta
def __call__(self, *args): return self.value def __call__(self, *args):
return self.value
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define MERGETEMPLATE_C "$Id: MergeTemplate.c,v 1.16 2003/01/17 17:20:49 tim_one Exp $\n" #define MERGETEMPLATE_C "$Id: MergeTemplate.c,v 1.17 2003/11/28 16:44:44 jim Exp $\n"
/**************************************************************************** /****************************************************************************
Set operations Set operations
...@@ -21,18 +21,22 @@ ...@@ -21,18 +21,22 @@
static int static int
merge_output(Bucket *r, SetIteration *i, int mapping) merge_output(Bucket *r, SetIteration *i, int mapping)
{ {
if(r->len >= r->size && Bucket_grow(r, -1, ! mapping) < 0) return -1; if (r->len >= r->size && Bucket_grow(r, -1, !mapping) < 0)
COPY_KEY(r->keys[r->len], i->key); return -1;
INCREF_KEY(r->keys[r->len]); COPY_KEY(r->keys[r->len], i->key);
if (mapping) INCREF_KEY(r->keys[r->len]);
{ if (mapping) {
COPY_VALUE(r->values[r->len], i->value); COPY_VALUE(r->values[r->len], i->value);
INCREF_VALUE(r->values[r->len]); INCREF_VALUE(r->values[r->len]);
} }
r->len++; r->len++;
return 0; return 0;
} }
/* The "reason" argument is a little integer giving "a reason" for the
* error. In the Zope3 codebase, these are mapped to explanatory strings
* via zodb/btrees/interfaces.py.
*/
static PyObject * static PyObject *
merge_error(int p1, int p2, int p3, int reason) merge_error(int p1, int p2, int p3, int reason)
{ {
...@@ -40,7 +44,7 @@ merge_error(int p1, int p2, int p3, int reason) ...@@ -40,7 +44,7 @@ merge_error(int p1, int p2, int p3, int reason)
UNLESS (r=Py_BuildValue("iiii", p1, p2, p3, reason)) r=Py_None; UNLESS (r=Py_BuildValue("iiii", p1, p2, p3, reason)) r=Py_None;
if (ConflictError == NULL) { if (ConflictError == NULL) {
ConflictError=PyExc_ValueError; ConflictError = PyExc_ValueError;
Py_INCREF(ConflictError); Py_INCREF(ConflictError);
} }
PyErr_SetObject(ConflictError, r); PyErr_SetObject(ConflictError, r);
...@@ -52,6 +56,33 @@ merge_error(int p1, int p2, int p3, int reason) ...@@ -52,6 +56,33 @@ merge_error(int p1, int p2, int p3, int reason)
return NULL; return NULL;
} }
/* It's hard to explain "the rules" for bucket_merge, in large part because
* any automatic conflict-resolution scheme is going to be incorrect for
* some endcases of *some* app. The scheme here is pretty conservative,
* and should be OK for most apps. It's easier to explain what the code
* allows than what it forbids:
*
* Leaving things alone: it's OK if both s2 and s3 leave a piece of s1
* alone (don't delete the key, and don't change the value).
*
* Key deletion: a transaction (s2 or s3) can delete a key (from s1), but
* only if the other transaction (of s2 and s3) doesn't delete the same key.
* However, it's not OK for s2 and s3 to, between them, end up deleting all
* the keys. This is a higher-level constraint, due to that the caller of
* bucket_merge() doesn't have enough info to unlink the resulting empty
* bucket from its BTree correctly.
*
* Key insertion: s2 or s3 can add a new key, provided the other transaction
* doesn't insert the same key. It's not OK even if they insert the same
* <key, value> pair.
*
* Mapping value modification: s2 or s3 can modify the value associated
* with a key in s1, provided the other transaction doesn't make a
* modification of the same key to a different value. It's OK if s2 and s3
* both give the same new value to the key (XXX while it's hard to be
* precise about why, this doesn't seem consistent with that it's *not* OK
* for both to add a new key mapping to the same value).
*/
static PyObject * static PyObject *
bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
{ {
...@@ -60,28 +91,34 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -60,28 +91,34 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
SetIteration i1 = {0,0,0}, i2 = {0,0,0}, i3 = {0,0,0}; SetIteration i1 = {0,0,0}, i2 = {0,0,0}, i3 = {0,0,0};
int cmp12, cmp13, cmp23, mapping, set; int cmp12, cmp13, cmp23, mapping, set;
if (initSetIteration(&i1, OBJECT(s1), 1) < 0) goto err; if (initSetIteration(&i1, OBJECT(s1), 1) < 0)
if (initSetIteration(&i2, OBJECT(s2), 1) < 0) goto err; goto err;
if (initSetIteration(&i3, OBJECT(s3), 1) < 0) goto err; if (initSetIteration(&i2, OBJECT(s2), 1) < 0)
goto err;
if (initSetIteration(&i3, OBJECT(s3), 1) < 0)
goto err;
mapping = i1.usesValue | i2.usesValue | i3.usesValue; mapping = i1.usesValue | i2.usesValue | i3.usesValue;
set = ! mapping; set = !mapping;
if (mapping) if (mapping)
{ r = (Bucket *)PyObject_CallObject((PyObject *)&BucketType, NULL);
UNLESS(r=BUCKET(PyObject_CallObject(OBJECT(&BucketType), NULL)))
goto err;
}
else else
{ r = (Bucket *)PyObject_CallObject((PyObject *)&SetType, NULL);
UNLESS(r=BUCKET(PyObject_CallObject(OBJECT(&SetType), NULL))) if (r == NULL)
goto err; goto err;
}
if (i1.next(&i1) < 0) goto err; if (i1.next(&i1) < 0)
if (i2.next(&i2) < 0) goto err; goto err;
if (i3.next(&i3) < 0) goto err; if (i2.next(&i2) < 0)
goto err;
if (i3.next(&i3) < 0)
goto err;
/* Consult zodb/btrees/interfaces.py for the meaning of the last
* argument passed to merge_error().
*/
/* XXX This isn't passing on errors raised by value comparisons. */
while (i1.position >= 0 && i2.position >= 0 && i3.position >= 0) while (i1.position >= 0 && i2.position >= 0 && i3.position >= 0)
{ {
TEST_KEY_SET_OR(cmp12, i1.key, i2.key) goto err; TEST_KEY_SET_OR(cmp12, i1.key, i2.key) goto err;
...@@ -91,15 +128,15 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -91,15 +128,15 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
if (cmp13==0) if (cmp13==0)
{ {
if (set || (TEST_VALUE(i1.value, i2.value) == 0)) if (set || (TEST_VALUE(i1.value, i2.value) == 0))
{ /* change in i3 or all same */ { /* change in i3 value or all same */
if (merge_output(r, &i3, mapping) < 0) goto err; if (merge_output(r, &i3, mapping) < 0) goto err;
} }
else if (set || (TEST_VALUE(i1.value, i3.value) == 0)) else if (set || (TEST_VALUE(i1.value, i3.value) == 0))
{ /* change in i2 */ { /* change in i2 value */
if (merge_output(r, &i2, mapping) < 0) goto err; if (merge_output(r, &i2, mapping) < 0) goto err;
} }
else else
{ /* conflicting changes in i2 and i3 */ { /* conflicting value changes in i2 and i3 */
merge_error(i1.position, i2.position, i3.position, 1); merge_error(i1.position, i2.position, i3.position, 1);
goto err; goto err;
} }
...@@ -113,7 +150,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -113,7 +150,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
if (i3.next(&i3) < 0) goto err; if (i3.next(&i3) < 0) goto err;
} }
else if (set || (TEST_VALUE(i1.value, i2.value) == 0)) else if (set || (TEST_VALUE(i1.value, i2.value) == 0))
{ /* delete i3 */ { /* deleted in i3 */
if (i1.next(&i1) < 0) goto err; if (i1.next(&i1) < 0) goto err;
if (i2.next(&i2) < 0) goto err; if (i2.next(&i2) < 0) goto err;
} }
...@@ -131,7 +168,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -131,7 +168,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
if (i2.next(&i2) < 0) goto err; if (i2.next(&i2) < 0) goto err;
} }
else if (set || (TEST_VALUE(i1.value, i3.value) == 0)) else if (set || (TEST_VALUE(i1.value, i3.value) == 0))
{ /* delete i2 */ { /* deleted in i2 */
if (i1.next(&i1) < 0) goto err; if (i1.next(&i1) < 0) goto err;
if (i3.next(&i3) < 0) goto err; if (i3.next(&i3) < 0) goto err;
} }
...@@ -145,7 +182,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -145,7 +182,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
{ /* Both keys changed */ { /* Both keys changed */
TEST_KEY_SET_OR(cmp23, i2.key, i3.key) goto err; TEST_KEY_SET_OR(cmp23, i2.key, i3.key) goto err;
if (cmp23==0) if (cmp23==0)
{ /* dualing inserts or deletes */ { /* dueling inserts or deletes */
merge_error(i1.position, i2.position, i3.position, 4); merge_error(i1.position, i2.position, i3.position, 4);
goto err; goto err;
} }
...@@ -168,8 +205,8 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -168,8 +205,8 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
if (i3.next(&i3) < 0) goto err; if (i3.next(&i3) < 0) goto err;
} }
else else
{ /* Dueling deletes */ { /* 1<2 and 1<3: both deleted 1.key */
merge_error(i1.position, i2.position, i3.position, 5); merge_error(i1.position, i2.position, i3.position, 5);
goto err; goto err;
} }
} }
...@@ -179,7 +216,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -179,7 +216,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
{ /* New inserts */ { /* New inserts */
TEST_KEY_SET_OR(cmp23, i2.key, i3.key) goto err; TEST_KEY_SET_OR(cmp23, i2.key, i3.key) goto err;
if (cmp23==0) if (cmp23==0)
{ /* dualing inserts */ { /* dueling inserts */
merge_error(i1.position, i2.position, i3.position, 6); merge_error(i1.position, i2.position, i3.position, 6);
goto err; goto err;
} }
...@@ -196,7 +233,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -196,7 +233,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
} }
while (i1.position >= 0 && i2.position >= 0) while (i1.position >= 0 && i2.position >= 0)
{ /* deleting i3 */ { /* remainder of i1 deleted in i3 */
TEST_KEY_SET_OR(cmp12, i1.key, i2.key) goto err; TEST_KEY_SET_OR(cmp12, i1.key, i2.key) goto err;
if (cmp12 > 0) if (cmp12 > 0)
{ /* insert i2 */ { /* insert i2 */
...@@ -209,14 +246,14 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -209,14 +246,14 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
if (i2.next(&i2) < 0) goto err; if (i2.next(&i2) < 0) goto err;
} }
else else
{ /* Dualing deletes or delete and change */ { /* Dueling deletes or delete and change */
merge_error(i1.position, i2.position, i3.position, 7); merge_error(i1.position, i2.position, i3.position, 7);
goto err; goto err;
} }
} }
while (i1.position >= 0 && i3.position >= 0) while (i1.position >= 0 && i3.position >= 0)
{ /* deleting i2 */ { /* remainder of i1 deleted in i2 */
TEST_KEY_SET_OR(cmp13, i1.key, i3.key) goto err; TEST_KEY_SET_OR(cmp13, i1.key, i3.key) goto err;
if (cmp13 > 0) if (cmp13 > 0)
{ /* insert i3 */ { /* insert i3 */
...@@ -229,7 +266,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -229,7 +266,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
if (i3.next(&i3) < 0) goto err; if (i3.next(&i3) < 0) goto err;
} }
else else
{ /* Dualing deletes or delete and change */ { /* Dueling deletes or delete and change */
merge_error(i1.position, i2.position, i3.position, 8); merge_error(i1.position, i2.position, i3.position, 8);
goto err; goto err;
} }
...@@ -248,7 +285,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -248,7 +285,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
} }
while (i3.position >= 0) while (i3.position >= 0)
{ /* Inserting i2 at end */ { /* Inserting i3 at end */
if (merge_output(r, &i3, mapping) < 0) goto err; if (merge_output(r, &i3, mapping) < 0) goto err;
if (i3.next(&i3) < 0) goto err; if (i3.next(&i3) < 0) goto err;
} }
...@@ -271,7 +308,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3) ...@@ -271,7 +308,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
Py_INCREF(s1->next); Py_INCREF(s1->next);
r->next = s1->next; r->next = s1->next;
} }
s=bucket_getstate(r, NULL); s = bucket_getstate(r);
Py_DECREF(r); Py_DECREF(r);
return s; return s;
......
...@@ -14,8 +14,3 @@ ...@@ -14,8 +14,3 @@
# hack to overcome dynamic-linking headache. # hack to overcome dynamic-linking headache.
from _OIBTree import * from _OIBTree import *
# We don't really want _ names in pickles, so update all of the __module__
# references.
for obj in OIBucket, OIBTree, OISet, OITreeSet:
obj.__module__ = __name__
...@@ -14,8 +14,3 @@ ...@@ -14,8 +14,3 @@
# hack to overcome dynamic-linking headache. # hack to overcome dynamic-linking headache.
from _OOBTree import * from _OOBTree import *
# We don't really want _ names in pickles, so update all of the __module__
# references.
for obj in OOBucket, OOBTree, OOSet, OOTreeSet:
obj.__module__ = __name__
...@@ -16,34 +16,7 @@ ...@@ -16,34 +16,7 @@
Set operations Set operations
****************************************************************************/ ****************************************************************************/
#define SETOPTEMPLATE_C "$Id: SetOpTemplate.c,v 1.29 2002/06/27 22:24:16 tim_one Exp $\n" #define SETOPTEMPLATE_C "$Id: SetOpTemplate.c,v 1.30 2003/11/28 16:44:44 jim Exp $\n"
#ifdef INTSET_H
static int
nextIntSet(SetIteration *i)
{
if (i->position >= 0)
{
UNLESS(PER_USE(INTSET(i->set))) return -1;
if (i->position < INTSET(i->set)->len)
{
i->key = INTSET(i->set)->data[i->position];
i->position ++;
}
else
{
i->position = -1;
PER_ACCESSED(INTSET(i->set));
}
PER_ALLOW_DEACTIVATION(INTSET(i->set));
}
return 0;
}
#endif
#ifdef KEY_CHECK #ifdef KEY_CHECK
static int static int
...@@ -103,7 +76,7 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues) ...@@ -103,7 +76,7 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues)
i->position = -1; /* set to 0 only on normal return */ i->position = -1; /* set to 0 only on normal return */
i->usesValue = 0; /* assume it's a set or that values aren't iterated */ i->usesValue = 0; /* assume it's a set or that values aren't iterated */
if (ExtensionClassSubclassInstance_Check(s, &BucketType)) if (PyObject_IsInstance(s, (PyObject *)&BucketType))
{ {
i->set = s; i->set = s;
Py_INCREF(s); Py_INCREF(s);
...@@ -116,15 +89,15 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues) ...@@ -116,15 +89,15 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues)
else else
i->next = nextSet; i->next = nextSet;
} }
else if (ExtensionClassSubclassInstance_Check(s, &SetType)) else if (PyObject_IsInstance(s, (PyObject *)&SetType))
{ {
i->set = s; i->set = s;
Py_INCREF(s); Py_INCREF(s);
i->next = nextSet; i->next = nextSet;
} }
else if (ExtensionClassSubclassInstance_Check(s, &BTreeType)) else if (PyObject_IsInstance(s, (PyObject *)&BTreeType))
{ {
i->set = BTree_rangeSearch(BTREE(s), NULL, 'i'); i->set = BTree_rangeSearch(BTREE(s), NULL, NULL, 'i');
UNLESS(i->set) return -1; UNLESS(i->set) return -1;
if (useValues) if (useValues)
...@@ -135,20 +108,12 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues) ...@@ -135,20 +108,12 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues)
else else
i->next = nextTreeSetItems; i->next = nextTreeSetItems;
} }
else if (ExtensionClassSubclassInstance_Check(s, &TreeSetType)) else if (PyObject_IsInstance(s, (PyObject *)&TreeSetType))
{ {
i->set = BTree_rangeSearch(BTREE(s), NULL, 'k'); i->set = BTree_rangeSearch(BTREE(s), NULL, NULL, 'k');
UNLESS(i->set) return -1; UNLESS(i->set) return -1;
i->next = nextTreeSetItems; i->next = nextTreeSetItems;
} }
#ifdef INTSET_H
else if (s->ob_type == (PyTypeObject*)intSetType)
{
i->set = s;
Py_INCREF(s);
i->next = nextIntSet;
}
#endif
#ifdef KEY_CHECK #ifdef KEY_CHECK
else if (KEY_CHECK(s)) else if (KEY_CHECK(s))
{ {
...@@ -244,7 +209,7 @@ set_operation(PyObject *s1, PyObject *s2, ...@@ -244,7 +209,7 @@ set_operation(PyObject *s1, PyObject *s2,
#ifndef MERGE #ifndef MERGE
if (c12 && i1.usesValue && i2.usesValue) goto invalid_set_operation; if (c12 && i1.usesValue && i2.usesValue) goto invalid_set_operation;
#endif #endif
if (! i1.usesValue && i2.usesValue) if (! i1.usesValue&& i2.usesValue)
{ {
SetIteration t; SetIteration t;
int i; int i;
...@@ -339,6 +304,7 @@ set_operation(PyObject *s1, PyObject *s2, ...@@ -339,6 +304,7 @@ set_operation(PyObject *s1, PyObject *s2,
if(c1 && copyRemaining(r, &i1, merge, w1) < 0) goto err; if(c1 && copyRemaining(r, &i1, merge, w1) < 0) goto err;
if(c2 && copyRemaining(r, &i2, merge, w2) < 0) goto err; if(c2 && copyRemaining(r, &i2, merge, w2) < 0) goto err;
finiSetIteration(&i1); finiSetIteration(&i1);
finiSetIteration(&i2); finiSetIteration(&i2);
...@@ -383,7 +349,7 @@ union_m(PyObject *ignored, PyObject *args) ...@@ -383,7 +349,7 @@ union_m(PyObject *ignored, PyObject *args)
UNLESS(PyArg_ParseTuple(args, "OO", &o1, &o2)) return NULL; UNLESS(PyArg_ParseTuple(args, "OO", &o1, &o2)) return NULL;
if (o1==Py_None) if (o1 == Py_None)
{ {
Py_INCREF(o2); Py_INCREF(o2);
return o2; return o2;
...@@ -552,5 +518,4 @@ Error: ...@@ -552,5 +518,4 @@ Error:
finiSetIteration(&setiter); finiSetIteration(&setiter);
return NULL; return NULL;
} }
#endif #endif
This diff is collapsed.
This diff is collapsed.
/* Setup template macros */ /* Setup template macros */
#define MASTER_ID "$Id: _IIBTree.c,v 1.7 2002/06/25 02:00:55 tim_one Exp $\n" #define MASTER_ID "$Id: _IIBTree.c,v 1.8 2003/11/28 16:44:44 jim Exp $\n"
#define PERSISTENT #define PERSISTENT
...@@ -11,8 +11,4 @@ ...@@ -11,8 +11,4 @@
#include "intkeymacros.h" #include "intkeymacros.h"
#include "intvaluemacros.h" #include "intvaluemacros.h"
#include "cPersistence.h"
#ifndef EXCLUDE_INTSET_SUPPORT
#include "BTree/intSet.h"
#endif
#include "BTreeModuleTemplate.c" #include "BTreeModuleTemplate.c"
#define MASTER_ID "$Id: _IOBTree.c,v 1.5 2002/02/21 21:41:17 jeremy Exp $\n" #define MASTER_ID "$Id: _IOBTree.c,v 1.6 2003/11/28 16:44:44 jim Exp $\n"
#define PERSISTENT #define PERSISTENT
...@@ -10,8 +10,4 @@ ...@@ -10,8 +10,4 @@
#include "intkeymacros.h" #include "intkeymacros.h"
#include "objectvaluemacros.h" #include "objectvaluemacros.h"
#include "cPersistence.h"
#ifndef EXCLUDE_INTSET_SUPPORT
#include "BTree/intSet.h"
#endif
#include "BTreeModuleTemplate.c" #include "BTreeModuleTemplate.c"
#define MASTER_ID "$Id: _OIBTree.c,v 1.2 2001/03/27 16:37:42 jim Exp $\n" #define MASTER_ID "$Id: _OIBTree.c,v 1.3 2003/11/28 16:44:44 jim Exp $\n"
#define PERSISTENT #define PERSISTENT
......
#define MASTER_ID "$Id: _OOBTree.c,v 1.2 2001/03/27 16:37:42 jim Exp $\n" #define MASTER_ID "$Id: _OOBTree.c,v 1.3 2003/11/28 16:44:44 jim Exp $\n"
#define PERSISTENT #define PERSISTENT
......
import ZODB try:
import intSet
try: import intSet except:
except: pass pass
else: del intSet else:
del intSet
# Register interfaces # Register interfaces
try: import Interface try:
except ImportError: pass # Don't register interfaces if no scarecrow import Interface
except ImportError:
pass # Don't register interfaces if no scarecrow
else: else:
import Interfaces import Interfaces
del Interfaces del Interfaces
......
...@@ -10,10 +10,9 @@ ...@@ -10,10 +10,9 @@
typedef unsigned char char2[2]; typedef unsigned char char2[2];
typedef unsigned char char6[6]; typedef unsigned char char6[6];
/* Setup template macros */ /* Setup template macros */
#define MASTER_ID "$Id: _fsBTree.c,v 1.7 2003/09/03 17:14:25 kiko Exp $\n" #define MASTER_ID "$Id: _fsBTree.c,v 1.8 2003/11/28 16:44:44 jim Exp $\n"
#define PERSISTENT #define PERSISTENT
...@@ -21,10 +20,10 @@ typedef unsigned char char6[6]; ...@@ -21,10 +20,10 @@ typedef unsigned char char6[6];
#define INITMODULE init_fsBTree #define INITMODULE init_fsBTree
#define DEFAULT_MAX_BUCKET_SIZE 500 #define DEFAULT_MAX_BUCKET_SIZE 500
#define DEFAULT_MAX_BTREE_SIZE 500 #define DEFAULT_MAX_BTREE_SIZE 500
/*#include "intkeymacros.h"*/ /*#include "intkeymacros.h"*/
#define KEYMACROS_H "$Id: _fsBTree.c,v 1.7 2003/09/03 17:14:25 kiko Exp $\n" #define KEYMACROS_H "$Id: _fsBTree.c,v 1.8 2003/11/28 16:44:44 jim Exp $\n"
#define KEY_TYPE char2 #define KEY_TYPE char2
#undef KEY_TYPE_IS_PYOBJECT #undef KEY_TYPE_IS_PYOBJECT
#define KEY_CHECK(K) (PyString_Check(K) && PyString_GET_SIZE(K)==2) #define KEY_CHECK(K) (PyString_Check(K) && PyString_GET_SIZE(K)==2)
...@@ -36,14 +35,13 @@ typedef unsigned char char6[6]; ...@@ -36,14 +35,13 @@ typedef unsigned char char6[6];
#define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \ #define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \
if (KEY_CHECK(ARG)) memcpy(TARGET, PyString_AS_STRING(ARG), 2); else { \ if (KEY_CHECK(ARG)) memcpy(TARGET, PyString_AS_STRING(ARG), 2); else { \
PyErr_SetString(PyExc_TypeError, "expected two-character string key"); \ PyErr_SetString(PyExc_TypeError, "expected two-character string key"); \
(STATUS)=0; } (STATUS)=0; }
/*#include "intvaluemacros.h"*/ /*#include "intvaluemacros.h"*/
#define VALUEMACROS_H "$Id: _fsBTree.c,v 1.7 2003/09/03 17:14:25 kiko Exp $\n" #define VALUEMACROS_H "$Id: _fsBTree.c,v 1.8 2003/11/28 16:44:44 jim Exp $\n"
#define VALUE_TYPE char6 #define VALUE_TYPE char6
#undef VALUE_TYPE_IS_PYOBJECT #undef VALUE_TYPE_IS_PYOBJECT
#define TEST_VALUE(K, T) memcmp(K,T,6) #define TEST_VALUE(K, T) memcmp(K,T,6)
#define DECLARE_VALUE(NAME) VALUE_TYPE NAME
#define DECREF_VALUE(k) #define DECREF_VALUE(k)
#define INCREF_VALUE(k) #define INCREF_VALUE(k)
#define COPY_VALUE(V, E) (memcpy(V, E, 6)) #define COPY_VALUE(V, E) (memcpy(V, E, 6))
...@@ -52,7 +50,7 @@ typedef unsigned char char6[6]; ...@@ -52,7 +50,7 @@ typedef unsigned char char6[6];
if ((PyString_Check(ARG) && PyString_GET_SIZE(ARG)==6)) \ if ((PyString_Check(ARG) && PyString_GET_SIZE(ARG)==6)) \
memcpy(TARGET, PyString_AS_STRING(ARG), 6); else { \ memcpy(TARGET, PyString_AS_STRING(ARG), 6); else { \
PyErr_SetString(PyExc_TypeError, "expected six-character string key"); \ PyErr_SetString(PyExc_TypeError, "expected six-character string key"); \
(STATUS)=0; } (STATUS)=0; }
#define NORMALIZE_VALUE(V, MIN) #define NORMALIZE_VALUE(V, MIN)
#include "BTreeModuleTemplate.c" #include "BTreeModuleTemplate.c"
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
/* Revision information: $Id: sorters.c,v 1.4 2002/06/12 04:17:48 tim_one Exp $ */ /* Revision information: $Id: sorters.c,v 1.5 2003/11/28 16:44:44 jim Exp $ */
/* The only routine here intended to be used outside the file is /* The only routine here intended to be used outside the file is
size_t sort_int4_nodups(int *p, size_t n) size_t sort_int4_nodups(int *p, size_t n)
......
This diff is collapsed.
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
# #
############################################################################## ##############################################################################
__version__ = '$Id: testBTreesUnicode.py,v 1.7 2002/06/08 19:40:13 tim_one Exp $' __version__ = '$Id: testBTreesUnicode.py,v 1.8 2003/11/28 16:44:45 jim Exp $'
import unittest,types import unittest
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
# When an OOBtree contains unicode strings as keys, # When an OOBtree contains unicode strings as keys,
...@@ -43,14 +43,14 @@ class TestBTreesUnicode(unittest.TestCase): ...@@ -43,14 +43,14 @@ class TestBTreesUnicode(unittest.TestCase):
self.tree = OOBTree() self.tree = OOBTree()
for k, v in self.data: for k, v in self.data:
if isinstance(k, types.StringType): if isinstance(k, str):
k = unicode(k, 'latin1') k = unicode(k, 'latin1')
self.tree[k] = v self.tree[k] = v
def testAllKeys(self): def testAllKeys(self):
# check every item of the tree # check every item of the tree
for k, v in self.data: for k, v in self.data:
if isinstance(k, types.StringType): if isinstance(k, str):
k = unicode(k, encoding) k = unicode(k, encoding)
self.assert_(self.tree.has_key(k)) self.assert_(self.tree.has_key(k))
self.assertEqual(self.tree[k], v) self.assertEqual(self.tree[k], v)
...@@ -65,7 +65,7 @@ class TestBTreesUnicode(unittest.TestCase): ...@@ -65,7 +65,7 @@ class TestBTreesUnicode(unittest.TestCase):
def testAsciiKeys(self): def testAsciiKeys(self):
# try to access some "plain ASCII" keys in the tree # try to access some "plain ASCII" keys in the tree
for k, v in self.data[0], self.data[2]: for k, v in self.data[0], self.data[2]:
self.assert_(isinstance(k, types.StringType)) self.assert_(isinstance(k, str))
self.assertEqual(self.tree[k], v) self.assertEqual(self.tree[k], v)
def test_suite(): def test_suite():
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -25,7 +25,7 @@ register_loop_callback() to register interest. When the mainloop ...@@ -25,7 +25,7 @@ register_loop_callback() to register interest. When the mainloop
thread calls loop(), each registered callback will be called with the thread calls loop(), each registered callback will be called with the
socket map as its first argument. socket map as its first argument.
""" """
__version__ = '$Revision: 1.10 $'[11:-2] __version__ = '$Revision: 1.11 $'[11:-2]
import asyncore import asyncore
import select import select
...@@ -37,6 +37,16 @@ _loop_lock = thread.allocate_lock() ...@@ -37,6 +37,16 @@ _loop_lock = thread.allocate_lock()
_looping = None _looping = None
_loop_callbacks = [] _loop_callbacks = []
def remove_loop_callback(callback):
"""Remove a callback function registered earlier.
This is useful if loop() was never called.
"""
for i in range(len(_loop_callbacks)):
if _loop_callbacks[i][0] == callback:
del _loop_callbacks[i]
return
def register_loop_callback(callback, args=(), kw=None): def register_loop_callback(callback, args=(), kw=None):
"""Register callback function to be called when mainloop starts """Register callback function to be called when mainloop starts
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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