[Python-checkins] python/dist/src/Modules _bsddb.c,1.23,1.24
greg at users.sourceforge.net
greg at users.sourceforge.net
Sun Nov 2 20:04:43 EST 2003
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv10424/Modules
Modified Files:
_bsddb.c
Log Message:
* Use weakref's of DBCursor objects for the iterator cursors to avoid a
memory leak that would've occurred for all iterators that were
destroyed before having iterated until they raised StopIteration.
* Simplify some code.
* Add new test cases to check for the memleak and ensure that mixing
iteration with modification of the values for existing keys works.
Index: _bsddb.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_bsddb.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** _bsddb.c 2 Nov 2003 09:10:15 -0000 1.23
--- _bsddb.c 3 Nov 2003 01:04:41 -0000 1.24
***************
*** 85,88 ****
--- 85,89 ----
/* --------------------------------------------------------------------- */
+ #include <stddef.h> /* for offsetof() */
#include <Python.h>
#include <db.h>
***************
*** 93,98 ****
/* 40 = 4.0, 33 = 3.3; this will break if the second number is > 9 */
#define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
! #define PY_BSDDB_VERSION "4.2.3"
static char *rcs_id = "$Id$";
--- 94,102 ----
/* 40 = 4.0, 33 = 3.3; this will break if the second number is > 9 */
#define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
+ #if DB_VERSION_MINOR > 9
+ #error "eek! DBVER can't handle minor versions > 9"
+ #endif
! #define PY_BSDDB_VERSION "4.2.4"
static char *rcs_id = "$Id$";
***************
*** 185,188 ****
--- 189,198 ----
/* Structure definitions */
+ #if PYTHON_API_VERSION >= 1010 /* python >= 2.1 support weak references */
+ #define HAVE_WEAKREF
+ #else
+ #undef HAVE_WEAKREF
+ #endif
+
struct behaviourFlags {
/* What is the default behaviour when DB->get or DBCursor->get returns a
***************
*** 195,199 ****
#define DEFAULT_GET_RETURNS_NONE 1
! #define DEFAULT_CURSOR_SET_RETURNS_NONE 0 /* 0 in pybsddb < 4.2, python < 2.4 */
typedef struct {
--- 205,209 ----
#define DEFAULT_GET_RETURNS_NONE 1
! #define DEFAULT_CURSOR_SET_RETURNS_NONE 1 /* 0 in pybsddb < 4.2, python < 2.4 */
typedef struct {
***************
*** 225,228 ****
--- 235,241 ----
DBC* dbc;
DBObject* mydb;
+ #ifdef HAVE_WEAKREF
+ PyObject *in_weakreflist; /* List of weak references */
+ #endif
} DBCursorObject;
***************
*** 761,764 ****
--- 774,780 ----
self->dbc = dbc;
self->mydb = db;
+ #ifdef HAVE_WEAKREF
+ self->in_weakreflist = NULL;
+ #endif
Py_INCREF(self->mydb);
return self;
***************
*** 770,773 ****
--- 786,796 ----
{
int err;
+
+ #ifdef HAVE_WEAKREF
+ if (self->in_weakreflist != NULL) {
+ PyObject_ClearWeakRefs((PyObject *) self);
+ }
+ #endif
+
if (self->dbc != NULL) {
MYDB_BEGIN_ALLOW_THREADS;
***************
*** 4253,4256 ****
--- 4276,4292 ----
0, /*tp_as_mapping*/
0, /*tp_hash*/
+ #ifdef HAVE_WEAKREF
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ offsetof(DBCursorObject, in_weakreflist), /* tp_weaklistoffset */
+ #endif
};
More information about the Python-checkins
mailing list