[Zope-Checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeTemplate.c:1.16 BucketTemplate.c:1.6
Jeremy Hylton
jeremy@zope.com
Thu, 13 Jun 2002 14:16:22 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv1932
Modified Files:
BTreeTemplate.c BucketTemplate.c
Log Message:
Expose BTree.firstbucket as the _firstbucket attribute in Python.
Expose Bucket.next as _next attribute in Python.
The attributes are read-only, but a user could still hose a BTree by
calling methods on an individual bucket.
Also, reformat the method defs.
=== Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c 1.15 => 1.16 ===
}
+/* XXX Even though the _firstbucket attribute is read-only, a program
+ could probably do arbitrary damage to a the btree internals. For
+ example, it could call clear() on a bucket inside a BTree.
+
+ We need to decide if the convenience for inspecting BTrees is worth
+ the risk.
+*/
+
+static struct PyMemberDef BTree_members[] = {
+ {"_firstbucket", T_OBJECT, offsetof(BTree, firstbucket), RO},
+ {NULL}
+};
static struct PyMethodDef BTree_methods[] = {
- {"__getstate__", (PyCFunction) BTree_getstate, METH_NOARGS,
- "__getstate__() -> state\n\n"
- "Return the picklable state of the BTree."},
- {"__setstate__", (PyCFunction) BTree_setstate, METH_O,
- "__setstate__(state)\n\n"
- "Set the state of the BTree."},
- {"has_key", (PyCFunction) BTree_has_key, METH_O,
- "has_key(key)\n\n"
- "Return true if the BTree contains the given key."},
- {"keys", (PyCFunction) BTree_keys, METH_VARARGS,
- "keys([min, max]) -> list of keys\n\n"
- "Returns the keys of the BTree. If min and max are supplied, only\n"
- "keys greater than min and less than max are returned."},
- {"values", (PyCFunction) BTree_values, METH_VARARGS,
- "values([min, max]) -> list of values\n\n"
- "Returns the values of the BTree. If min and max are supplied, only\n"
- "values corresponding to keys greater than min and less than max are\n"
- "returned."},
- {"items", (PyCFunction) BTree_items, METH_VARARGS,
- "items([min, max]) -> -- list of key, value pairs\n\n"
- "Returns the items of the BTree. If min and max are supplied, only\n"
- "items with keys greater than min and less than max are returned."},
- {"byValue", (PyCFunction) BTree_byValue, METH_O,
- "byValue(min) -> list of value, key pairs\n\n"
- "Returns list of value, key pairs where the value is >= min. The\n"
- "list is sorted by value. Note that items() returns keys in the\n"
- "opposite order."},
- {"get", (PyCFunction) BTree_getm, METH_VARARGS,
- "get(key[, default=None]) -> Value for key or default\n\n"
- "Return the value or the default if the key is not found."},
- {"maxKey", (PyCFunction) BTree_maxKey, METH_VARARGS,
- "maxKey([max]) -> key\n\n"
- "Return the largest key in the BTree. If max is specified, return\n"
- "the largest key <= max."},
- {"minKey", (PyCFunction) BTree_minKey, METH_VARARGS,
- "minKey([mi]) -> key\n\n"
- "Return the smallest key in the BTree. If min is specified, return\n"
- "the smallest key >= min."},
- {"clear", (PyCFunction) BTree_clear, METH_NOARGS,
- "clear()\n\nRemove all of the items from the BTree."},
- {"insert", (PyCFunction)BTree_addUnique, METH_VARARGS,
- "insert(key, value) -> 0 or 1\n\n"
- "Add an item if the key is not already used. Return 1 if the item was\n"
- "added, or 0 otherwise."},
- {"update", (PyCFunction) Mapping_update, METH_O,
- "update(collection)\n\n Add the items from the given collection."},
+ {"__getstate__", (PyCFunction) BTree_getstate, METH_NOARGS,
+ "__getstate__() -> state\n\n"
+ "Return the picklable state of the BTree."},
+ {"__setstate__", (PyCFunction) BTree_setstate, METH_O,
+ "__setstate__(state)\n\n"
+ "Set the state of the BTree."},
+ {"has_key", (PyCFunction) BTree_has_key, METH_O,
+ "has_key(key)\n\n"
+ "Return true if the BTree contains the given key."},
+ {"keys", (PyCFunction) BTree_keys, METH_VARARGS,
+ "keys([min, max]) -> list of keys\n\n"
+ "Returns the keys of the BTree. If min and max are supplied, only\n"
+ "keys greater than min and less than max are returned."},
+ {"values", (PyCFunction) BTree_values, METH_VARARGS,
+ "values([min, max]) -> list of values\n\n"
+ "Returns the values of the BTree. If min and max are supplied, only\n"
+ "values corresponding to keys greater than min and less than max are\n"
+ "returned."},
+ {"items", (PyCFunction) BTree_items, METH_VARARGS,
+ "items([min, max]) -> -- list of key, value pairs\n\n"
+ "Returns the items of the BTree. If min and max are supplied, only\n"
+ "items with keys greater than min and less than max are returned."},
+ {"byValue", (PyCFunction) BTree_byValue, METH_O,
+ "byValue(min) -> list of value, key pairs\n\n"
+ "Returns list of value, key pairs where the value is >= min. The\n"
+ "list is sorted by value. Note that items() returns keys in the\n"
+ "opposite order."},
+ {"get", (PyCFunction) BTree_getm, METH_VARARGS,
+ "get(key[, default=None]) -> Value for key or default\n\n"
+ "Return the value or the default if the key is not found."},
+ {"maxKey", (PyCFunction) BTree_maxKey, METH_VARARGS,
+ "maxKey([max]) -> key\n\n"
+ "Return the largest key in the BTree. If max is specified, return\n"
+ "the largest key <= max."},
+ {"minKey", (PyCFunction) BTree_minKey, METH_VARARGS,
+ "minKey([mi]) -> key\n\n"
+ "Return the smallest key in the BTree. If min is specified, return\n"
+ "the smallest key >= min."},
+ {"clear", (PyCFunction) BTree_clear, METH_NOARGS,
+ "clear()\n\nRemove all of the items from the BTree."},
+ {"insert", (PyCFunction)BTree_addUnique, METH_VARARGS,
+ "insert(key, value) -> 0 or 1\n\n"
+ "Add an item if the key is not already used. Return 1 if the item was\n"
+ "added, or 0 otherwise."},
+ {"update", (PyCFunction) Mapping_update, METH_O,
+ "update(collection)\n\n Add the items from the given collection."},
#ifdef PERSISTENT
- {"_p_resolveConflict", (PyCFunction) BTree__p_resolveConflict, METH_VARARGS,
- "_p_resolveConflict() -- Reinitialize from a newly created copy"},
- {"_p_deactivate", (PyCFunction) BTree__p_deactivate, METH_NOARGS,
- "_p_deactivate()\n\nReinitialize from a newly created copy."},
+ {"_p_resolveConflict", (PyCFunction) BTree__p_resolveConflict,
+ METH_VARARGS,
+ "_p_resolveConflict() -- Reinitialize from a newly created copy"},
+ {"_p_deactivate", (PyCFunction) BTree__p_deactivate, METH_NOARGS,
+ "_p_deactivate()\n\nReinitialize from a newly created copy."},
#endif
- {NULL, NULL} /* sentinel */
+ {NULL, NULL}
};
static int
@@ -1607,7 +1620,7 @@
0, /* tp_iter */
0, /* tp_iternext */
BTree_methods, /* tp_methods */
- 0, /* tp_members */
+ BTree_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
=== Zope3/lib/python/Persistence/BTrees/BucketTemplate.c 1.5 => 1.6 ===
#endif
+/* XXX Even though the _next attribute is read-only, a program could
+ probably do arbitrary damage to a the btree internals. For
+ example, it could call clear() on a bucket inside a BTree.
+
+ We need to decide if the convenience for inspecting BTrees is worth
+ the risk.
+*/
+
+static struct PyMemberDef Bucket_members[] = {
+ {"_next", T_OBJECT, offsetof(Bucket, next), RO},
+ {NULL}
+};
+
static struct PyMethodDef Bucket_methods[] = {
- {"__getstate__", (PyCFunction) bucket_getstate, METH_NOARGS,
- "__getstate__() -- Return the picklable state of the object"},
- {"__setstate__", (PyCFunction) bucket_setstate, METH_O,
- "__setstate__() -- Set the state of the object"},
- {"keys", (PyCFunction) bucket_keys, METH_VARARGS,
+ {"__getstate__", (PyCFunction) bucket_getstate, METH_NOARGS,
+ "__getstate__() -- Return the picklable state of the object"},
+ {"__setstate__", (PyCFunction) bucket_setstate, METH_O,
+ "__setstate__() -- Set the state of the object"},
+ {"keys", (PyCFunction) bucket_keys, METH_VARARGS,
"keys([min, max]) -- Return the keys"},
- {"has_key", (PyCFunction) bucket_has_key, METH_O,
+ {"has_key", (PyCFunction) bucket_has_key, METH_O,
"has_key(key) -- Test whether the bucket contains the given key"},
- {"clear", (PyCFunction) bucket_clear, METH_VARARGS,
- "clear() -- Remove all of the items from the bucket"},
- {"update", (PyCFunction) Mapping_update, METH_O,
- "update(collection) -- Add the items from the given collection"},
- {"maxKey", (PyCFunction) Bucket_maxKey, METH_VARARGS,
- "maxKey([key]) -- Fine the maximum key\n\n"
- "If an argument is given, find the maximum <= the argument"},
- {"minKey", (PyCFunction) Bucket_minKey, METH_VARARGS,
- "minKey([key]) -- Fine the minimum key\n\n"
- "If an argument is given, find the minimum >= the argument"},
- {"values", (PyCFunction) bucket_values, METH_VARARGS,
+ {"clear", (PyCFunction) bucket_clear, METH_VARARGS,
+ "clear() -- Remove all of the items from the bucket"},
+ {"update", (PyCFunction) Mapping_update, METH_O,
+ "update(collection) -- Add the items from the given collection"},
+ {"maxKey", (PyCFunction) Bucket_maxKey, METH_VARARGS,
+ "maxKey([key]) -- Fine the maximum key\n\n"
+ "If an argument is given, find the maximum <= the argument"},
+ {"minKey", (PyCFunction) Bucket_minKey, METH_VARARGS,
+ "minKey([key]) -- Fine the minimum key\n\n"
+ "If an argument is given, find the minimum >= the argument"},
+ {"values", (PyCFunction) bucket_values, METH_VARARGS,
"values([min, max]) -- Return the values"},
- {"items", (PyCFunction) bucket_items, METH_VARARGS,
+ {"items", (PyCFunction) bucket_items, METH_VARARGS,
"items([min, max])) -- Return the items"},
- {"byValue", (PyCFunction) bucket_byValue, METH_O,
- "byValue(min) -- "
- "Return value-keys with values >= min and reverse sorted by values"
- },
- {"get", (PyCFunction) bucket_getm, METH_VARARGS,
- "get(key[,default]) -- Look up a value\n\n"
- "Return the default (or None) if the key is not found."
- },
+ {"byValue", (PyCFunction) bucket_byValue, METH_O,
+ "byValue(min) -- "
+ "Return value-keys with values >= min and reverse sorted by values"},
+ {"get", (PyCFunction) bucket_getm, METH_VARARGS,
+ "get(key[,default]) -- Look up a value\n\n"
+ "Return the default (or None) if the key is not found."},
#ifdef PERSISTENT
- {"_p_resolveConflict", (PyCFunction) bucket__p_resolveConflict, METH_VARARGS,
- "_p_resolveConflict() -- Reinitialize from a newly created copy"},
- {"_p_deactivate", (PyCFunction) bucket__p_deactivate, METH_NOARGS,
- "_p_deactivate() -- Reinitialize from a newly created copy"},
+ {"_p_resolveConflict", (PyCFunction) bucket__p_resolveConflict,
+ METH_VARARGS,
+ "_p_resolveConflict() -- Reinitialize from a newly created copy"},
+ {"_p_deactivate", (PyCFunction) bucket__p_deactivate, METH_NOARGS,
+ "_p_deactivate() -- Reinitialize from a newly created copy"},
#endif
- {NULL, NULL} /* sentinel */
+ {NULL, NULL}
};
static int
@@ -1411,7 +1423,7 @@
0, /* tp_iter */
0, /* tp_iternext */
Bucket_methods, /* tp_methods */
- 0, /* tp_members */
+ Bucket_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */