Dropped IFCLEARPGRES macro

PQclear already guards against NULL, so the extra check is redundant
This commit is contained in:
Daniele Varrazzo 2013-03-20 00:47:20 +00:00
parent 16021dae6d
commit 0830deb790
5 changed files with 22 additions and 23 deletions

View File

@ -890,7 +890,7 @@ conn_poll(connectionObject *self)
}
curs = (cursorObject *)py_curs;
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
curs->pgres = pq_get_last_result(self);
/* fetch the tuples (if there are any) and build the result. We

View File

@ -379,7 +379,7 @@ _psyco_curs_execute(cursorObject *self,
if (operation == NULL) { goto exit; }
IFCLEARPGRES(self->pgres);
CLEARPGRES(self->pgres);
Py_CLEAR(self->query);
Dprintf("psyco_curs_execute: starting execution of new query");
@ -790,7 +790,7 @@ psyco_curs_fetchone(cursorObject *self)
if (self->row >= self->rowcount
&& self->conn->async_cursor
&& PyWeakref_GetObject(self->conn->async_cursor) == (PyObject*)self)
IFCLEARPGRES(self->pgres);
CLEARPGRES(self->pgres);
return res;
}
@ -837,7 +837,7 @@ psyco_curs_next_named(cursorObject *self)
if (self->row >= self->rowcount
&& self->conn->async_cursor
&& PyWeakref_GetObject(self->conn->async_cursor) == (PyObject*)self)
IFCLEARPGRES(self->pgres);
CLEARPGRES(self->pgres);
return res;
}
@ -922,7 +922,7 @@ psyco_curs_fetchmany(cursorObject *self, PyObject *args, PyObject *kwords)
if (self->row >= self->rowcount
&& self->conn->async_cursor
&& PyWeakref_GetObject(self->conn->async_cursor) == (PyObject*)self)
IFCLEARPGRES(self->pgres);
CLEARPGRES(self->pgres);
/* success */
rv = list;
@ -991,7 +991,7 @@ psyco_curs_fetchall(cursorObject *self)
if (self->row >= self->rowcount
&& self->conn->async_cursor
&& PyWeakref_GetObject(self->conn->async_cursor) == (PyObject*)self)
IFCLEARPGRES(self->pgres);
CLEARPGRES(self->pgres);
/* success */
rv = list;
@ -1904,7 +1904,7 @@ cursor_dealloc(PyObject* obj)
Py_CLEAR(self->string_types);
Py_CLEAR(self->binary_types);
IFCLEARPGRES(self->pgres);
CLEARPGRES(self->pgres);
Dprintf("cursor_dealloc: deleted cursor object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,

View File

@ -102,7 +102,7 @@ error_clear(errorObject *self)
Py_CLEAR(self->pgcode);
Py_CLEAR(self->cursor);
PyMem_Free(self->codec);
IFCLEARPGRES(self->pgres);
CLEARPGRES(self->pgres);
return ((PyTypeObject *)PyExc_StandardError)->tp_clear((PyObject *)self);
}

View File

@ -230,7 +230,7 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult **pgres)
Py_CLEAR(perr->pgcode);
perr->pgcode = error_text_from_chars(perr, code);
IFCLEARPGRES(perr->pgres);
CLEARPGRES(perr->pgres);
if (pgres && *pgres) {
perr->pgres = *pgres;
*pgres = NULL;
@ -394,7 +394,7 @@ pq_execute_command_locked(connectionObject *conn, const char *query,
}
retvalue = 0;
IFCLEARPGRES(*pgres);
CLEARPGRES(*pgres);
cleanup:
return retvalue;
@ -902,7 +902,7 @@ pq_execute(cursorObject *curs, const char *query, int async, int no_result)
}
if (async == 0) {
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
Dprintf("pq_execute: executing SYNC query: pgconn = %p", curs->conn->pgconn);
Dprintf(" %-.200s", query);
if (!psyco_green()) {
@ -941,7 +941,7 @@ pq_execute(cursorObject *curs, const char *query, int async, int no_result)
Dprintf("pq_execute: executing ASYNC query: pgconn = %p", curs->conn->pgconn);
Dprintf(" %-.200s", query);
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
if (PQsendQuery(curs->conn->pgconn, query) == 0) {
pthread_mutex_unlock(&(curs->conn->lock));
Py_BLOCK_THREADS;
@ -1338,7 +1338,7 @@ _pq_copy_in_v3(cursorObject *curs)
/* XXX would be nice to propagate the exeption */
res = PQputCopyEnd(curs->conn->pgconn, "error in .read() call");
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
Dprintf("_pq_copy_in_v3: copy ended; res = %d", res);
@ -1362,7 +1362,7 @@ _pq_copy_in_v3(cursorObject *curs)
break;
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
pq_raise(curs->conn, curs, NULL);
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
}
}
@ -1428,7 +1428,7 @@ _pq_copy_out_v3(cursorObject *curs)
}
/* and finally we grab the operation result from the backend */
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
for (;;) {
Py_BEGIN_ALLOW_THREADS;
curs->pgres = PQgetResult(curs->conn->pgconn);
@ -1438,7 +1438,7 @@ _pq_copy_out_v3(cursorObject *curs)
break;
if (PQresultStatus(curs->pgres) == PGRES_FATAL_ERROR)
pq_raise(curs->conn, curs, NULL);
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
}
ret = 1;
@ -1499,7 +1499,7 @@ pq_fetch(cursorObject *curs, int no_result)
curs->rowcount = -1;
/* error caught by out glorious notice handler */
if (PyErr_Occurred()) ex = -1;
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
break;
case PGRES_COPY_IN:
@ -1508,7 +1508,7 @@ pq_fetch(cursorObject *curs, int no_result)
curs->rowcount = -1;
/* error caught by out glorious notice handler */
if (PyErr_Occurred()) ex = -1;
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
break;
case PGRES_TUPLES_OK:
@ -1520,7 +1520,7 @@ pq_fetch(cursorObject *curs, int no_result)
}
else {
Dprintf("pq_fetch: got tuples, discarding them");
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
curs->rowcount = -1;
ex = 0;
}
@ -1529,7 +1529,7 @@ pq_fetch(cursorObject *curs, int no_result)
case PGRES_EMPTY_QUERY:
PyErr_SetString(ProgrammingError,
"can't execute an empty query");
IFCLEARPGRES(curs->pgres);
CLEARPGRES(curs->pgres);
ex = -1;
break;

View File

@ -29,9 +29,8 @@
#include "psycopg/cursor.h"
#include "psycopg/connection.h"
/* macros to clean the pg result */
#define IFCLEARPGRES(pgres) if (pgres) {PQclear(pgres); pgres = NULL;}
#define CLEARPGRES(pgres) PQclear(pgres); pgres = NULL
/* macro to clean the pg result */
#define CLEARPGRES(pgres) do { PQclear(pgres); pgres = NULL; } while (0)
/* exported functions */
HIDDEN PGresult *pq_get_last_result(connectionObject *conn);