python/dist/src/Modules _bsddb.c,1.33,1.34

Update of /cvsroot/python/python/dist/src/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18311/Modules Modified Files: _bsddb.c Log Message: Add weakref support to all bsddb.db objects. Make DBTxn objects automatically call abort() in their destructor if not yet finalized and raise a RuntimeWarning to that effect. Index: _bsddb.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/_bsddb.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** _bsddb.c 27 Jun 2004 23:36:37 -0000 1.33 --- _bsddb.c 28 Jun 2004 01:20:40 -0000 1.34 *************** *** 195,198 **** --- 195,205 ---- #endif + /* if Python >= 2.1 better support warnings */ + #if PYTHON_API_VERSION >= 1010 + #define HAVE_WARNINGS + #else + #undef HAVE_WARNINGS + #endif + struct behaviourFlags { /* What is the default behaviour when DB->get or DBCursor->get returns a *************** *** 213,216 **** --- 220,226 ---- int closed; struct behaviourFlags moduleFlags; + #ifdef HAVE_WEAKREF + PyObject *in_weakreflist; /* List of weak references */ + #endif } DBEnvObject; *************** *** 228,231 **** --- 238,244 ---- int primaryDBType; #endif + #ifdef HAVE_WEAKREF + PyObject *in_weakreflist; /* List of weak references */ + #endif } DBObject; *************** *** 244,247 **** --- 257,263 ---- PyObject_HEAD DB_TXN* txn; + #ifdef HAVE_WEAKREF + PyObject *in_weakreflist; /* List of weak references */ + #endif } DBTxnObject; *************** *** 250,253 **** --- 266,272 ---- PyObject_HEAD DB_LOCK lock; + #ifdef HAVE_WEAKREF + PyObject *in_weakreflist; /* List of weak references */ + #endif } DBLockObject; *************** *** 468,473 **** _db_errmsg[0] = 0; } ! /* if Python 2.1 or better use warning framework */ ! #if PYTHON_API_VERSION >= 1010 exceptionRaised = PyErr_Warn(PyExc_RuntimeWarning, errTxt); #else --- 487,491 ---- _db_errmsg[0] = 0; } ! #ifdef HAVE_WARNINGS exceptionRaised = PyErr_Warn(PyExc_RuntimeWarning, errTxt); #else *************** *** 698,701 **** --- 716,722 ---- self->primaryDBType = 0; #endif + #ifdef HAVE_WEAKREF + self->in_weakreflist = NULL; + #endif /* keep a reference to our python DBEnv object */ *************** *** 719,722 **** --- 740,746 ---- #endif MYDB_END_ALLOW_THREADS; + /* TODO add a weakref(self) to the self->myenvobj->open_child_weakrefs + * list so that a DBEnv can refuse to close without aborting any open + * open DBTxns and closing any open DBs first. */ if (makeDBError(err)) { if (self->myenvobj) { *************** *** 742,747 **** self->db->close(self->db, 0); MYDB_END_ALLOW_THREADS; ! /* if Python 2.1 or better use warning framework */ ! #if PYTHON_API_VERSION >= 1010 } else { PyErr_Warn(PyExc_RuntimeWarning, --- 766,770 ---- self->db->close(self->db, 0); MYDB_END_ALLOW_THREADS; ! #ifdef HAVE_WARNINGS } else { PyErr_Warn(PyExc_RuntimeWarning, *************** *** 751,754 **** --- 774,782 ---- self->db = NULL; } + #ifdef HAVE_WEAKREF + if (self->in_weakreflist != NULL) { + PyObject_ClearWeakRefs((PyObject *) self); + } + #endif if (self->myenvobj) { Py_DECREF(self->myenvobj); *************** *** 843,846 **** --- 871,877 ---- self->moduleFlags.getReturnsNone = DEFAULT_GET_RETURNS_NONE; self->moduleFlags.cursorSetReturnsNone = DEFAULT_CURSOR_SET_RETURNS_NONE; + #ifdef HAVE_WEAKREF + self->in_weakreflist = NULL; + #endif MYDB_BEGIN_ALLOW_THREADS; *************** *** 860,863 **** --- 891,900 ---- DBEnv_dealloc(DBEnvObject* self) { + #ifdef HAVE_WEAKREF + if (self->in_weakreflist != NULL) { + PyObject_ClearWeakRefs((PyObject *) self); + } + #endif + if (!self->closed) { MYDB_BEGIN_ALLOW_THREADS; *************** *** 886,889 **** --- 923,929 ---- if (self == NULL) return NULL; + #ifdef HAVE_WEAKREF + self->in_weakreflist = NULL; + #endif MYDB_BEGIN_ALLOW_THREADS; *************** *** 893,896 **** --- 933,939 ---- err = txn_begin(myenv->db_env, parent, &(self->txn), flags); #endif + /* TODO add a weakref(self) to the self->myenvobj->open_child_weakrefs + * list so that a DBEnv can refuse to close without aborting any open + * open DBTxns and closing any open DBs first. */ MYDB_END_ALLOW_THREADS; if (makeDBError(err)) { *************** *** 904,910 **** DBTxn_dealloc(DBTxnObject* self) { ! /* XXX nothing to do for transaction objects?!? */ ! /* TODO: if it hasn't been commited, should we abort it? */ #if PYTHON_API_VERSION <= 1007 --- 947,970 ---- DBTxn_dealloc(DBTxnObject* self) { ! #ifdef HAVE_WEAKREF ! if (self->in_weakreflist != NULL) { ! PyObject_ClearWeakRefs((PyObject *) self); ! } ! #endif ! #ifdef HAVE_WARNINGS ! if (self->txn) { ! /* it hasn't been finalized, abort it! */ ! MYDB_BEGIN_ALLOW_THREADS; ! #if (DBVER >= 40) ! self->txn->abort(self->txn); ! #else ! txn_abort(self->txn); ! #endif ! MYDB_END_ALLOW_THREADS; ! PyErr_Warn(PyExc_RuntimeWarning, ! "DBTxn aborted in destructor. No prior commit() or abort()."); ! } ! #endif #if PYTHON_API_VERSION <= 1007 *************** *** 930,933 **** --- 990,996 ---- if (self == NULL) return NULL; + #ifdef HAVE_WEAKREF + self->in_weakreflist = NULL; + #endif MYDB_BEGIN_ALLOW_THREADS; *************** *** 950,954 **** DBLock_dealloc(DBLockObject* self) { ! /* TODO: if it hasn't been released, should we do it? */ #if PYTHON_API_VERSION <= 1007 --- 1013,1022 ---- DBLock_dealloc(DBLockObject* self) { ! #ifdef HAVE_WEAKREF ! if (self->in_weakreflist != NULL) { ! PyObject_ClearWeakRefs((PyObject *) self); ! } ! #endif ! /* TODO: is this lock held? should we release it? */ #if PYTHON_API_VERSION <= 1007 *************** *** 4306,4309 **** --- 4374,4390 ---- &DB_mapping,/*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(DBObject, in_weakreflist), /* tp_weaklistoffset */ + #endif }; *************** *** 4359,4362 **** --- 4440,4456 ---- 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(DBEnvObject, in_weakreflist), /* tp_weaklistoffset */ + #endif }; *************** *** 4378,4381 **** --- 4472,4488 ---- 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(DBTxnObject, in_weakreflist), /* tp_weaklistoffset */ + #endif }; *************** *** 4398,4401 **** --- 4505,4521 ---- 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(DBLockObject, in_weakreflist), /* tp_weaklistoffset */ + #endif };
participants (1)
-
gregļ¼ users.sourceforge.net