mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-11 03:26:37 +03:00
Use Py_CLEAR() in a few more places, and do INCREF's before setting
struct members rather than afterwards.
This commit is contained in:
parent
e0287c0db4
commit
2273b79be9
|
@ -96,8 +96,8 @@ asis_setup(asisObject *self, PyObject *obj)
|
|||
self, ((PyObject *)self)->ob_refcnt
|
||||
);
|
||||
|
||||
Py_INCREF(obj);
|
||||
self->wrapped = obj;
|
||||
Py_INCREF(self->wrapped);
|
||||
|
||||
Dprintf("asis_setup: good asis object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
@ -118,7 +118,7 @@ asis_dealloc(PyObject* obj)
|
|||
{
|
||||
asisObject *self = (asisObject *)obj;
|
||||
|
||||
Py_XDECREF(self->wrapped);
|
||||
Py_CLEAR(self->wrapped);
|
||||
|
||||
Dprintf("asis_dealloc: deleted asis object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
|
|
@ -257,8 +257,8 @@ binary_setup(binaryObject *self, PyObject *str)
|
|||
|
||||
self->buffer = NULL;
|
||||
self->conn = NULL;
|
||||
Py_INCREF(str);
|
||||
self->wrapped = str;
|
||||
Py_INCREF(self->wrapped);
|
||||
|
||||
Dprintf("binary_setup: good binary object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
@ -282,9 +282,9 @@ binary_dealloc(PyObject* obj)
|
|||
{
|
||||
binaryObject *self = (binaryObject *)obj;
|
||||
|
||||
Py_XDECREF(self->wrapped);
|
||||
Py_XDECREF(self->buffer);
|
||||
Py_XDECREF(self->conn);
|
||||
Py_CLEAR(self->wrapped);
|
||||
Py_CLEAR(self->buffer);
|
||||
Py_CLEAR(self->conn);
|
||||
|
||||
Dprintf("binary_dealloc: deleted binary object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
|
|
@ -131,8 +131,8 @@ pydatetime_setup(pydatetimeObject *self, PyObject *obj, int type)
|
|||
self, ((PyObject *)self)->ob_refcnt);
|
||||
|
||||
self->type = type;
|
||||
Py_INCREF(obj);
|
||||
self->wrapped = obj;
|
||||
Py_INCREF(self->wrapped);
|
||||
|
||||
Dprintf("pydatetime_setup: good pydatetime object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
@ -154,7 +154,7 @@ pydatetime_dealloc(PyObject* obj)
|
|||
{
|
||||
pydatetimeObject *self = (pydatetimeObject *)obj;
|
||||
|
||||
Py_XDECREF(self->wrapped);
|
||||
Py_CLEAR(self->wrapped);
|
||||
|
||||
Dprintf("mpydatetime_dealloc: deleted pydatetime object at %p, "
|
||||
"refcnt = " FORMAT_CODE_PY_SSIZE_T, obj, obj->ob_refcnt);
|
||||
|
|
|
@ -108,9 +108,9 @@ list_prepare(listObject *self, PyObject *args)
|
|||
reference to it; we'll need it during the recursive adapt() call (the
|
||||
encoding is here for a future expansion that will make .getquoted()
|
||||
work even without a connection to the backend. */
|
||||
Py_XDECREF(self->connection);
|
||||
Py_CLEAR(self->connection);
|
||||
Py_INCREF(conn);
|
||||
self->connection = (PyObject*)conn;
|
||||
Py_INCREF(self->connection);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
@ -169,8 +169,8 @@ list_setup(listObject *self, PyObject *obj, const char *enc)
|
|||
if (enc) self->encoding = strdup(enc);
|
||||
|
||||
self->connection = NULL;
|
||||
Py_INCREF(obj);
|
||||
self->wrapped = obj;
|
||||
Py_INCREF(self->wrapped);
|
||||
|
||||
Dprintf("list_setup: good list object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
@ -194,8 +194,8 @@ list_dealloc(PyObject* obj)
|
|||
{
|
||||
listObject *self = (listObject *)obj;
|
||||
|
||||
Py_XDECREF(self->wrapped);
|
||||
Py_XDECREF(self->connection);
|
||||
Py_CLEAR(self->wrapped);
|
||||
Py_CLEAR(self->connection);
|
||||
if (self->encoding) free(self->encoding);
|
||||
|
||||
Dprintf("list_dealloc: deleted list object at %p, "
|
||||
|
|
|
@ -152,8 +152,8 @@ mxdatetime_setup(mxdatetimeObject *self, PyObject *obj, int type)
|
|||
);
|
||||
|
||||
self->type = type;
|
||||
Py_INCREF(obj);
|
||||
self->wrapped = obj;
|
||||
Py_INCREF(self->wrapped);
|
||||
|
||||
Dprintf("mxdatetime_setup: good mxdatetime object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
@ -176,7 +176,7 @@ mxdatetime_dealloc(PyObject* obj)
|
|||
{
|
||||
mxdatetimeObject *self = (mxdatetimeObject *)obj;
|
||||
|
||||
Py_XDECREF(self->wrapped);
|
||||
Py_CLEAR(self->wrapped);
|
||||
|
||||
Dprintf("mxdatetime_dealloc: deleted mxdatetime object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
|
|
@ -106,8 +106,8 @@ pboolean_setup(pbooleanObject *self, PyObject *obj)
|
|||
self, ((PyObject *)self)->ob_refcnt
|
||||
);
|
||||
|
||||
Py_INCREF(obj);
|
||||
self->wrapped = obj;
|
||||
Py_INCREF(self->wrapped);
|
||||
|
||||
Dprintf("pboolean_setup: good pboolean object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
@ -130,7 +130,7 @@ pboolean_dealloc(PyObject* obj)
|
|||
{
|
||||
pbooleanObject *self = (pbooleanObject *)obj;
|
||||
|
||||
Py_XDECREF(self->wrapped);
|
||||
Py_CLEAR(self->wrapped);
|
||||
|
||||
Dprintf("pboolean_dealloc: deleted pboolean object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
|
|
@ -216,10 +216,10 @@ qstring_prepare(qstringObject *self, PyObject *args)
|
|||
Dprintf("qstring_prepare: set encoding to %s", conn->encoding);
|
||||
}
|
||||
|
||||
Py_XDECREF(self->conn);
|
||||
Py_CLEAR(self->conn);
|
||||
if (conn) {
|
||||
Py_INCREF(conn);
|
||||
self->conn = (PyObject*)conn;
|
||||
Py_INCREF(self->conn);
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
|
@ -280,8 +280,8 @@ qstring_setup(qstringObject *self, PyObject *str, const char *enc)
|
|||
/* FIXME: remove this orrible strdup */
|
||||
if (enc) self->encoding = strdup(enc);
|
||||
|
||||
Py_INCREF(str);
|
||||
self->wrapped = str;
|
||||
Py_INCREF(self->wrapped);
|
||||
|
||||
Dprintf("qstring_setup: good qstring object at %p, refcnt = "
|
||||
FORMAT_CODE_PY_SSIZE_T,
|
||||
|
@ -306,9 +306,9 @@ qstring_dealloc(PyObject* obj)
|
|||
{
|
||||
qstringObject *self = (qstringObject *)obj;
|
||||
|
||||
Py_XDECREF(self->wrapped);
|
||||
Py_XDECREF(self->buffer);
|
||||
Py_XDECREF(self->conn);
|
||||
Py_CLEAR(self->wrapped);
|
||||
Py_CLEAR(self->buffer);
|
||||
Py_CLEAR(self->conn);
|
||||
|
||||
if (self->encoding) free(self->encoding);
|
||||
|
||||
|
|
|
@ -1688,7 +1688,7 @@ cursor_repr(cursorObject *self)
|
|||
static int
|
||||
cursor_traverse(cursorObject *self, visitproc visit, void *arg)
|
||||
{
|
||||
Py_VISIT(self->conn);
|
||||
Py_VISIT((PyObject *)self->conn);
|
||||
Py_VISIT(self->description);
|
||||
Py_VISIT(self->pgstatus);
|
||||
Py_VISIT(self->casts);
|
||||
|
|
Loading…
Reference in New Issue
Block a user