|
From: Yuval T. <yu...@il...> - 2003-10-27 14:12:14
|
??? wrote:
>>3. In DB2_connection_object_cursor (line 666 :-), there's a commented
>>out call to Py_INCREF(self) right after the assignment of cursor->conn =
>>self. If we want to make sure that the connection object stays alive
>>while the cursor is alive, we must call incref ( and decref upon
>>destruction ).
>>
>>
>
>I didn't find the clean way to avoid cyclic reference situation.
>In case of db.close(), users expect cursors from that ``db'' also close,
>I think. How about your idea?
>
Ok - I saw that we're holding a reference to the connection object
inside the python cursor object. So there's really no need to hold it
in the C module as well. Also, I saw that the only function that uses
this connection object from within the C cursor is 'callproc'. So what
I did is removed the C connection reference from the C cursor (thus no
need to play with ref. counting at all), and in
DB2_cursor_object_callproc I added/changed the following lines:
DB2ConnectionObject *conn = NULL;
/* start parsing */
if ( !PyArg_ParseTuple(args, "Os|O", conn, &proc_name, &p_args) ) {
return NULL;
}
if ( ! conn )
{
PyErr_SetString(DB2_Error, "Connection object not found.");
return NULL;
}
And in the callproc method of the python cursor I changed the following
lines:
def callproc(self, procname, *args):
t_args = args[:]
r = self._cs.callproc(self._conn, procname.upper(), t_args)
self._refresh_info()
This way, we're holding the ref. of the connection object only once - in
the python code, and we send this reference to the C module only when we
need to use it (only in callproc at the moment).
What do you say ?
--
Yuval Turgeman
Content Technology, Aduva LTD.
|