Added TO_STATE() marker to work around cpychecker refcount issue

See davidmalcolm/gcc-python-plugin#109
This commit is contained in:
Daniele Varrazzo 2018-12-28 14:12:22 +01:00
parent 79ba3a9573
commit 22edcd3d0e
4 changed files with 27 additions and 5 deletions

View File

@ -1392,7 +1392,7 @@ conn_tpc_begin(connectionObject *self, xidObject *xid)
/* The transaction started ok, let's store this xid. */ /* The transaction started ok, let's store this xid. */
Py_INCREF(xid); Py_INCREF(xid);
self->tpc_xid = xid; self->tpc_xid = (xidObject *)TO_STATE((PyObject *)xid);
return 0; return 0;
} }

View File

@ -1337,13 +1337,13 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
); );
if (0 > psycopg_strdup(&self->dsn, dsn, -1)) { goto exit; } if (0 > psycopg_strdup(&self->dsn, dsn, -1)) { goto exit; }
if (!(self->notice_list = PyList_New(0))) { goto exit; } if (!(self->notice_list = TO_STATE(PyList_New(0)))) { goto exit; }
if (!(self->notifies = PyList_New(0))) { goto exit; } if (!(self->notifies = TO_STATE(PyList_New(0)))) { goto exit; }
self->async = async; self->async = async;
self->status = CONN_STATUS_SETUP; self->status = CONN_STATUS_SETUP;
self->async_status = ASYNC_DONE; self->async_status = ASYNC_DONE;
if (!(self->string_types = PyDict_New())) { goto exit; } if (!(self->string_types = TO_STATE(PyDict_New()))) { goto exit; }
if (!(self->binary_types = PyDict_New())) { goto exit; } if (!(self->binary_types = TO_STATE(PyDict_New()))) { goto exit; }
self->isolevel = ISOLATION_LEVEL_DEFAULT; self->isolevel = ISOLATION_LEVEL_DEFAULT;
self->readonly = STATE_DEFAULT; self->readonly = STATE_DEFAULT;
self->deferrable = STATE_DEFAULT; self->deferrable = STATE_DEFAULT;

View File

@ -465,3 +465,19 @@ psyco_GetDecimalType(void)
return decimalType; return decimalType;
} }
/* Transfer ownership of an object to another object's state.
*
* Work around what seems a bug to the cpychecker which doesn't recognise
* the new reference: tell it one reference is just gone.
*
* See davidmalcolm/gcc-python-plugin#109
*/
#ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE
STEALS(1) IGNORE_REFCOUNT BORROWED PyObject *
TO_STATE(PyObject* obj)
{
return obj;
}
#endif

View File

@ -58,4 +58,10 @@ HIDDEN RAISES BORROWED PyObject *psyco_set_error(
HIDDEN PyObject *psyco_GetDecimalType(void); HIDDEN PyObject *psyco_GetDecimalType(void);
#ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE
HIDDEN STEALS(1) IGNORE_REFCOUNT BORROWED PyObject *TO_STATE(PyObject* obj);
#else
#define TO_STATE(x) x
#endif
#endif /* !defined(UTILS_H) */ #endif /* !defined(UTILS_H) */