Skip to content

Commit

Permalink
Added TO_STATE() marker to work around cpychecker refcount issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarrazzo committed Jan 25, 2019
1 parent 25a51d8 commit 458aeaf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion psycopg/connection_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ conn_tpc_begin(connectionObject *self, xidObject *xid)

/* The transaction started ok, let's store this xid. */
Py_INCREF(xid);
self->tpc_xid = xid;
self->tpc_xid = (xidObject *)TO_STATE((PyObject *)xid);

return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions psycopg/connection_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (!(self->notice_list = PyList_New(0))) { goto exit; }
if (!(self->notifies = PyList_New(0))) { goto exit; }
if (!(self->notice_list = TO_STATE(PyList_New(0)))) { goto exit; }
if (!(self->notifies = TO_STATE(PyList_New(0)))) { goto exit; }
self->async = async;
self->status = CONN_STATUS_SETUP;
self->async_status = ASYNC_DONE;
if (!(self->string_types = PyDict_New())) { goto exit; }
if (!(self->binary_types = PyDict_New())) { goto exit; }
if (!(self->string_types = TO_STATE(PyDict_New()))) { goto exit; }
if (!(self->binary_types = TO_STATE(PyDict_New()))) { goto exit; }
self->isolevel = ISOLATION_LEVEL_DEFAULT;
self->readonly = STATE_DEFAULT;
self->deferrable = STATE_DEFAULT;
Expand Down
16 changes: 16 additions & 0 deletions psycopg/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,19 @@ psyco_GetDecimalType(void)

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
6 changes: 6 additions & 0 deletions psycopg/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ HIDDEN RAISES BORROWED PyObject *psyco_set_error(

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) */

0 comments on commit 458aeaf

Please sign in to comment.