mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-05-03 14:43:42 +03:00
More functions annotated for static analysis
Also more return values checked for values < 0 for errors, instead of checking == 0 and leaving the positive side unchecked
This commit is contained in:
parent
5bfb6cdefe
commit
e1266d52cd
|
@ -138,12 +138,12 @@ HIDDEN PGcancel *conn_get_cancel(PGconn *pgconn);
|
||||||
HIDDEN void conn_notice_process(connectionObject *self);
|
HIDDEN void conn_notice_process(connectionObject *self);
|
||||||
HIDDEN void conn_notice_clean(connectionObject *self);
|
HIDDEN void conn_notice_clean(connectionObject *self);
|
||||||
HIDDEN void conn_notifies_process(connectionObject *self);
|
HIDDEN void conn_notifies_process(connectionObject *self);
|
||||||
HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
|
RAISES_NEG HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
|
||||||
HIDDEN int conn_connect(connectionObject *self, long int async);
|
HIDDEN int conn_connect(connectionObject *self, long int async);
|
||||||
HIDDEN void conn_close(connectionObject *self);
|
HIDDEN void conn_close(connectionObject *self);
|
||||||
RAISES_NEG HIDDEN int conn_commit(connectionObject *self);
|
RAISES_NEG HIDDEN int conn_commit(connectionObject *self);
|
||||||
RAISES_NEG HIDDEN int conn_rollback(connectionObject *self);
|
RAISES_NEG HIDDEN int conn_rollback(connectionObject *self);
|
||||||
HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
|
RAISES_NEG HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
|
||||||
const char *readonly, const char *deferrable,
|
const char *readonly, const char *deferrable,
|
||||||
int autocommit);
|
int autocommit);
|
||||||
HIDDEN int conn_set_autocommit(connectionObject *self, int value);
|
HIDDEN int conn_set_autocommit(connectionObject *self, int value);
|
||||||
|
|
|
@ -332,7 +332,7 @@ exit:
|
||||||
*
|
*
|
||||||
* Return 0 on success, else nonzero.
|
* Return 0 on success, else nonzero.
|
||||||
*/
|
*/
|
||||||
static int
|
RAISES_NEG static int
|
||||||
conn_read_encoding(connectionObject *self, PGconn *pgconn)
|
conn_read_encoding(connectionObject *self, PGconn *pgconn)
|
||||||
{
|
{
|
||||||
char *enc = NULL, *codec = NULL;
|
char *enc = NULL, *codec = NULL;
|
||||||
|
@ -468,7 +468,7 @@ conn_is_datestyle_ok(PGconn *pgconn)
|
||||||
|
|
||||||
/* conn_setup - setup and read basic information about the connection */
|
/* conn_setup - setup and read basic information about the connection */
|
||||||
|
|
||||||
int
|
RAISES_NEG int
|
||||||
conn_setup(connectionObject *self, PGconn *pgconn)
|
conn_setup(connectionObject *self, PGconn *pgconn)
|
||||||
{
|
{
|
||||||
PGresult *pgres = NULL;
|
PGresult *pgres = NULL;
|
||||||
|
@ -482,7 +482,7 @@ conn_setup(connectionObject *self, PGconn *pgconn)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn_read_encoding(self, pgconn)) {
|
if (0 > conn_read_encoding(self, pgconn)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ conn_setup(connectionObject *self, PGconn *pgconn)
|
||||||
pthread_mutex_lock(&self->lock);
|
pthread_mutex_lock(&self->lock);
|
||||||
Py_BLOCK_THREADS;
|
Py_BLOCK_THREADS;
|
||||||
|
|
||||||
if (psyco_green() && (pq_set_non_blocking(self, 1, 1) != 0)) {
|
if (psyco_green() && (0 > pq_set_non_blocking(self, 1))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,7 +774,7 @@ _conn_poll_setup_async(connectionObject *self)
|
||||||
switch (self->status) {
|
switch (self->status) {
|
||||||
case CONN_STATUS_CONNECTING:
|
case CONN_STATUS_CONNECTING:
|
||||||
/* Set the connection to nonblocking now. */
|
/* Set the connection to nonblocking now. */
|
||||||
if (pq_set_non_blocking(self, 1, 1) != 0) {
|
if (pq_set_non_blocking(self, 1) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -785,7 +785,7 @@ _conn_poll_setup_async(connectionObject *self)
|
||||||
PyErr_SetString(InterfaceError, "only protocol 3 supported");
|
PyErr_SetString(InterfaceError, "only protocol 3 supported");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (conn_read_encoding(self, self->pgconn)) {
|
if (0 > conn_read_encoding(self, self->pgconn)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
self->cancel = conn_get_cancel(self->pgconn);
|
self->cancel = conn_get_cancel(self->pgconn);
|
||||||
|
@ -971,7 +971,7 @@ conn_rollback(connectionObject *self)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
RAISES_NEG int
|
||||||
conn_set_session(connectionObject *self,
|
conn_set_session(connectionObject *self,
|
||||||
const char *isolevel, const char *readonly, const char *deferrable,
|
const char *isolevel, const char *readonly, const char *deferrable,
|
||||||
int autocommit)
|
int autocommit)
|
||||||
|
|
|
@ -528,7 +528,7 @@ psyco_conn_set_session(connectionObject *self, PyObject *args, PyObject *kwargs)
|
||||||
if (-1 == c_autocommit) { return NULL; }
|
if (-1 == c_autocommit) { return NULL; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != conn_set_session(self,
|
if (0 > conn_set_session(self,
|
||||||
c_isolevel, c_readonly, c_deferrable, c_autocommit)) {
|
c_isolevel, c_readonly, c_deferrable, c_autocommit)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -726,7 +726,7 @@ _psyco_curs_buildrow(cursorObject *self, int row)
|
||||||
}
|
}
|
||||||
if (!t) { goto exit; }
|
if (!t) { goto exit; }
|
||||||
|
|
||||||
if (0 == _psyco_curs_buildrow_fill(self, t, row, n, istuple)) {
|
if (0 <= _psyco_curs_buildrow_fill(self, t, row, n, istuple)) {
|
||||||
rv = t;
|
rv = t;
|
||||||
t = NULL;
|
t = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1347,7 +1347,7 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
Py_INCREF(file);
|
Py_INCREF(file);
|
||||||
self->copyfile = file;
|
self->copyfile = file;
|
||||||
|
|
||||||
if (pq_execute(self, query, 0) == 1) {
|
if (pq_execute(self, query, 0) >= 0) {
|
||||||
res = Py_None;
|
res = Py_None;
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
}
|
}
|
||||||
|
@ -1443,7 +1443,7 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
Py_INCREF(file);
|
Py_INCREF(file);
|
||||||
self->copyfile = file;
|
self->copyfile = file;
|
||||||
|
|
||||||
if (pq_execute(self, query, 0) == 1) {
|
if (pq_execute(self, query, 0) >= 0) {
|
||||||
res = Py_None;
|
res = Py_None;
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
}
|
}
|
||||||
|
@ -1517,7 +1517,7 @@ psyco_curs_copy_expert(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
self->copyfile = file;
|
self->copyfile = file;
|
||||||
|
|
||||||
/* At this point, the SQL statement must be str, not unicode */
|
/* At this point, the SQL statement must be str, not unicode */
|
||||||
if (pq_execute(self, Bytes_AS_STRING(sql), 0) == 1) {
|
if (pq_execute(self, Bytes_AS_STRING(sql), 0) >= 0) {
|
||||||
res = Py_None;
|
res = Py_None;
|
||||||
Py_INCREF(res);
|
Py_INCREF(res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,19 +304,16 @@ pq_clear_async(connectionObject *conn)
|
||||||
|
|
||||||
Accepted arg values are 1 (nonblocking) and 0 (blocking).
|
Accepted arg values are 1 (nonblocking) and 0 (blocking).
|
||||||
|
|
||||||
Return 0 if everything ok, else nonzero.
|
Return 0 if everything ok, else < 0 and set an exception.
|
||||||
|
|
||||||
In case of error, if pyerr is nonzero, set a Python exception.
|
|
||||||
*/
|
*/
|
||||||
int
|
RAISES_NEG int
|
||||||
pq_set_non_blocking(connectionObject *conn, int arg, int pyerr)
|
pq_set_non_blocking(connectionObject *conn, int arg)
|
||||||
{
|
{
|
||||||
int ret = PQsetnonblocking(conn->pgconn, arg);
|
int ret = PQsetnonblocking(conn->pgconn, arg);
|
||||||
if (0 != ret) {
|
if (0 != ret) {
|
||||||
Dprintf("PQsetnonblocking(%d) FAILED", arg);
|
Dprintf("PQsetnonblocking(%d) FAILED", arg);
|
||||||
if (pyerr) {
|
PyErr_SetString(OperationalError, "PQsetnonblocking() failed");
|
||||||
PyErr_SetString(OperationalError, "PQsetnonblocking() failed");
|
ret = -1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ HIDDEN int pq_is_busy(connectionObject *conn);
|
||||||
HIDDEN int pq_is_busy_locked(connectionObject *conn);
|
HIDDEN int pq_is_busy_locked(connectionObject *conn);
|
||||||
HIDDEN int pq_flush(connectionObject *conn);
|
HIDDEN int pq_flush(connectionObject *conn);
|
||||||
HIDDEN void pq_clear_async(connectionObject *conn);
|
HIDDEN void pq_clear_async(connectionObject *conn);
|
||||||
HIDDEN int pq_set_non_blocking(connectionObject *conn, int arg, int pyerr);
|
RAISES_NEG HIDDEN int pq_set_non_blocking(connectionObject *conn, int arg);
|
||||||
|
|
||||||
HIDDEN void pq_set_critical(connectionObject *conn, const char *msg);
|
HIDDEN void pq_set_critical(connectionObject *conn, const char *msg);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user