mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 17:34:08 +03:00
Use more compact macros to annotate functions for the static checker
This commit is contained in:
parent
f2e4a8ed78
commit
5bfb6cdefe
|
@ -86,8 +86,7 @@
|
|||
|
||||
/* Helpers for formatstring */
|
||||
|
||||
CPYCHECKER_RETURNS_BORROWED_REF
|
||||
Py_LOCAL_INLINE(PyObject *)
|
||||
BORROWED Py_LOCAL_INLINE(PyObject *)
|
||||
getnextarg(PyObject *args, Py_ssize_t arglen, Py_ssize_t *p_argidx)
|
||||
{
|
||||
Py_ssize_t argidx = *p_argidx;
|
||||
|
|
|
@ -162,31 +162,31 @@ static double round(double num)
|
|||
|
||||
/* decorators for the gcc cpychecker plugin */
|
||||
#if defined(WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE)
|
||||
#define CPYCHECKER_RETURNS_BORROWED_REF \
|
||||
#define BORROWED \
|
||||
__attribute__((cpychecker_returns_borrowed_ref))
|
||||
#else
|
||||
#define CPYCHECKER_RETURNS_BORROWED_REF
|
||||
#define BORROWED
|
||||
#endif
|
||||
|
||||
#if defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)
|
||||
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
|
||||
#define STEALS(n) \
|
||||
__attribute__((cpychecker_steals_reference_to_arg(n)))
|
||||
#else
|
||||
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
|
||||
#define STEALS(n)
|
||||
#endif
|
||||
|
||||
#if defined(WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE)
|
||||
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION \
|
||||
#define RAISES_NEG \
|
||||
__attribute__((cpychecker_negative_result_sets_exception))
|
||||
#else
|
||||
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
#define RAISES_NEG
|
||||
#endif
|
||||
|
||||
#if defined(WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE)
|
||||
#define CPYCHECKER_SETS_EXCEPTION \
|
||||
#define RAISES \
|
||||
__attribute__((cpychecker_sets_exception))
|
||||
#else
|
||||
#define CPYCHECKER_SETS_EXCEPTION
|
||||
#define RAISES
|
||||
#endif
|
||||
|
||||
#endif /* !defined(PSYCOPG_CONFIG_H) */
|
||||
|
|
|
@ -131,8 +131,7 @@ typedef struct {
|
|||
/* C-callable functions in connection_int.c and connection_ext.c */
|
||||
HIDDEN PyObject *conn_text_from_chars(connectionObject *pgconn, const char *str);
|
||||
HIDDEN int conn_get_standard_conforming_strings(PGconn *pgconn);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int conn_get_isolation_level(connectionObject *self);
|
||||
RAISES_NEG HIDDEN int conn_get_isolation_level(connectionObject *self);
|
||||
HIDDEN int conn_get_protocol_version(PGconn *pgconn);
|
||||
HIDDEN int conn_get_server_version(PGconn *pgconn);
|
||||
HIDDEN PGcancel *conn_get_cancel(PGconn *pgconn);
|
||||
|
@ -142,23 +141,17 @@ HIDDEN void conn_notifies_process(connectionObject *self);
|
|||
HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
|
||||
HIDDEN int conn_connect(connectionObject *self, long int async);
|
||||
HIDDEN void conn_close(connectionObject *self);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int conn_commit(connectionObject *self);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int conn_rollback(connectionObject *self);
|
||||
RAISES_NEG HIDDEN int conn_commit(connectionObject *self);
|
||||
RAISES_NEG HIDDEN int conn_rollback(connectionObject *self);
|
||||
HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
|
||||
const char *readonly, const char *deferrable,
|
||||
int autocommit);
|
||||
HIDDEN int conn_set_autocommit(connectionObject *self, int value);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int conn_switch_isolation_level(connectionObject *self, int level);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc);
|
||||
RAISES_NEG HIDDEN int conn_switch_isolation_level(connectionObject *self, int level);
|
||||
RAISES_NEG HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc);
|
||||
HIDDEN int conn_poll(connectionObject *self);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int conn_tpc_begin(connectionObject *self, XidObject *xid);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int conn_tpc_command(connectionObject *self,
|
||||
RAISES_NEG HIDDEN int conn_tpc_begin(connectionObject *self, XidObject *xid);
|
||||
RAISES_NEG HIDDEN int conn_tpc_command(connectionObject *self,
|
||||
const char *cmd, XidObject *xid);
|
||||
HIDDEN PyObject *conn_tpc_recover(connectionObject *self);
|
||||
|
||||
|
|
|
@ -253,8 +253,7 @@ conn_get_standard_conforming_strings(PGconn *pgconn)
|
|||
* Return a buffer allocated on Python heap into 'clean' and return 0 on
|
||||
* success, otherwise return -1 and set an exception.
|
||||
*/
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
static int
|
||||
RAISES_NEG static int
|
||||
clear_encoding_name(const char *enc, char **clean)
|
||||
{
|
||||
const char *i = enc;
|
||||
|
@ -292,8 +291,7 @@ exit:
|
|||
*
|
||||
* 'enc' should be already normalized (uppercase, no - or _).
|
||||
*/
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
static int
|
||||
RAISES_NEG static int
|
||||
conn_encoding_to_codec(const char *enc, char **codec)
|
||||
{
|
||||
char *tmp;
|
||||
|
@ -376,8 +374,7 @@ exit:
|
|||
}
|
||||
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
conn_get_isolation_level(connectionObject *self)
|
||||
{
|
||||
PGresult *pgres = NULL;
|
||||
|
@ -954,8 +951,7 @@ conn_close(connectionObject *self)
|
|||
|
||||
/* conn_commit - commit on a connection */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
conn_commit(connectionObject *self)
|
||||
{
|
||||
int res;
|
||||
|
@ -966,8 +962,7 @@ conn_commit(connectionObject *self)
|
|||
|
||||
/* conn_rollback - rollback a connection */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
conn_rollback(connectionObject *self)
|
||||
{
|
||||
int res;
|
||||
|
@ -1049,8 +1044,7 @@ conn_set_autocommit(connectionObject *self, int value)
|
|||
|
||||
/* conn_switch_isolation_level - switch isolation level on the connection */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
conn_switch_isolation_level(connectionObject *self, int level)
|
||||
{
|
||||
PGresult *pgres = NULL;
|
||||
|
@ -1132,8 +1126,7 @@ endlock:
|
|||
|
||||
/* conn_set_client_encoding - switch client encoding on connection */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
conn_set_client_encoding(connectionObject *self, const char *enc)
|
||||
{
|
||||
PGresult *pgres = NULL;
|
||||
|
@ -1206,8 +1199,7 @@ exit:
|
|||
* in regular transactions, as PostgreSQL won't even know we are in a TPC
|
||||
* until PREPARE. */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
conn_tpc_begin(connectionObject *self, XidObject *xid)
|
||||
{
|
||||
PGresult *pgres = NULL;
|
||||
|
@ -1241,8 +1233,7 @@ conn_tpc_begin(connectionObject *self, XidObject *xid)
|
|||
* The function doesn't change the connection state as it can be used
|
||||
* for many commands and for recovered transactions. */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
conn_tpc_command(connectionObject *self, const char *cmd, XidObject *xid)
|
||||
{
|
||||
PGresult *pgres = NULL;
|
||||
|
|
|
@ -550,8 +550,7 @@ psyco_conn_autocommit_get(connectionObject *self)
|
|||
return ret;
|
||||
}
|
||||
|
||||
CPYCHECKER_RETURNS_BORROWED_REF
|
||||
static PyObject *
|
||||
BORROWED static PyObject *
|
||||
_psyco_conn_autocommit_set_checks(connectionObject *self)
|
||||
{
|
||||
/* wrapper to use the EXC_IF macros.
|
||||
|
|
|
@ -85,8 +85,7 @@ struct cursorObject {
|
|||
|
||||
|
||||
/* C-callable functions in cursor_int.c and cursor_ext.c */
|
||||
CPYCHECKER_RETURNS_BORROWED_REF
|
||||
HIDDEN PyObject *curs_get_cast(cursorObject *self, PyObject *oid);
|
||||
BORROWED HIDDEN PyObject *curs_get_cast(cursorObject *self, PyObject *oid);
|
||||
HIDDEN void curs_reset(cursorObject *self);
|
||||
|
||||
/* exception-raising macros */
|
||||
|
|
|
@ -38,8 +38,7 @@
|
|||
* Return a borrowed reference.
|
||||
*/
|
||||
|
||||
CPYCHECKER_RETURNS_BORROWED_REF
|
||||
PyObject *
|
||||
BORROWED PyObject *
|
||||
curs_get_cast(cursorObject *self, PyObject *oid)
|
||||
{
|
||||
PyObject *cast;
|
||||
|
|
|
@ -75,8 +75,7 @@ psyco_curs_close(cursorObject *self, PyObject *args)
|
|||
|
||||
/* mogrify a query string and build argument array or dict */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
static int
|
||||
RAISES_NEG static int
|
||||
_mogrify(PyObject *var, PyObject *fmt, cursorObject *curs, PyObject **new)
|
||||
{
|
||||
PyObject *key, *value, *n;
|
||||
|
@ -360,8 +359,7 @@ _psyco_curs_merge_query_args(cursorObject *self,
|
|||
#define psyco_curs_execute_doc \
|
||||
"execute(query, vars=None) -- Execute query with bound vars."
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
static int
|
||||
RAISES_NEG static int
|
||||
_psyco_curs_execute(cursorObject *self,
|
||||
PyObject *operation, PyObject *vars, long int async)
|
||||
{
|
||||
|
@ -645,8 +643,7 @@ psyco_curs_cast(cursorObject *self, PyObject *args)
|
|||
"default) or using the sequence factory previously set in the\n" \
|
||||
"`row_factory` attribute. Return `!None` when no more data is available.\n"
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
static int
|
||||
RAISES_NEG static int
|
||||
_psyco_curs_prefetch(cursorObject *self)
|
||||
{
|
||||
int i = 0;
|
||||
|
@ -663,8 +660,7 @@ _psyco_curs_prefetch(cursorObject *self)
|
|||
return i;
|
||||
}
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
static int
|
||||
RAISES_NEG static int
|
||||
_psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
|
||||
int row, int n, int istuple)
|
||||
{
|
||||
|
|
|
@ -64,8 +64,7 @@ strip_severity(const char *msg)
|
|||
code. A list of error codes can be found at:
|
||||
|
||||
http://www.postgresql.org/docs/current/static/errcodes-appendix.html */
|
||||
CPYCHECKER_RETURNS_BORROWED_REF
|
||||
static PyObject *
|
||||
BORROWED static PyObject *
|
||||
exception_from_sqlstate(const char *sqlstate)
|
||||
{
|
||||
switch (sqlstate[0]) {
|
||||
|
@ -152,8 +151,7 @@ exception_from_sqlstate(const char *sqlstate)
|
|||
|
||||
This function should be called while holding the GIL. */
|
||||
|
||||
CPYCHECKER_SETS_EXCEPTION
|
||||
static void
|
||||
RAISES static void
|
||||
pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres)
|
||||
{
|
||||
PyObject *exc = NULL;
|
||||
|
@ -253,8 +251,7 @@ pq_clear_critical(connectionObject *conn)
|
|||
|
||||
/* return -1 if the exception is set (i.e. if conn->critical is set),
|
||||
* else 0 */
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
static int
|
||||
RAISES_NEG static int
|
||||
pq_resolve_critical(connectionObject *conn, int close)
|
||||
{
|
||||
Dprintf("pq_resolve_critical: resolving %s", conn->critical);
|
||||
|
@ -389,8 +386,7 @@ cleanup:
|
|||
This function should be called while holding the global interpreter
|
||||
lock.
|
||||
*/
|
||||
CPYCHECKER_SETS_EXCEPTION
|
||||
void
|
||||
RAISES void
|
||||
pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
|
||||
{
|
||||
Dprintf("pq_complete_error: pgconn = %p, pgres = %p, error = %s",
|
||||
|
@ -483,8 +479,7 @@ pq_commit(connectionObject *conn)
|
|||
return retvalue;
|
||||
}
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
pq_abort_locked(connectionObject *conn, PGresult **pgres, char **error,
|
||||
PyThreadState **tstate)
|
||||
{
|
||||
|
@ -511,8 +506,7 @@ pq_abort_locked(connectionObject *conn, PGresult **pgres, char **error,
|
|||
This function should be called while holding the global interpreter
|
||||
lock. */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
pq_abort(connectionObject *conn)
|
||||
{
|
||||
int retvalue = -1;
|
||||
|
@ -554,8 +548,7 @@ pq_abort(connectionObject *conn)
|
|||
connection without holding the global interpreter lock.
|
||||
*/
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
pq_reset_locked(connectionObject *conn, PGresult **pgres, char **error,
|
||||
PyThreadState **tstate)
|
||||
{
|
||||
|
@ -847,8 +840,7 @@ pq_flush(connectionObject *conn)
|
|||
this fucntion locks the connection object
|
||||
this function call Py_*_ALLOW_THREADS macros */
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
pq_execute(cursorObject *curs, const char *query, int async)
|
||||
{
|
||||
PGresult *pgres = NULL;
|
||||
|
@ -1028,8 +1020,7 @@ pq_get_last_result(connectionObject *conn)
|
|||
1 - result from backend (possibly data is ready)
|
||||
*/
|
||||
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
static int
|
||||
RAISES_NEG static int
|
||||
_pq_fetch_tuples(cursorObject *curs)
|
||||
{
|
||||
int i, *dsize = NULL;
|
||||
|
|
|
@ -35,23 +35,18 @@
|
|||
|
||||
/* exported functions */
|
||||
HIDDEN PGresult *pq_get_last_result(connectionObject *conn);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int pq_fetch(cursorObject *curs);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int pq_execute(cursorObject *curs, const char *query, int async);
|
||||
RAISES_NEG HIDDEN int pq_fetch(cursorObject *curs);
|
||||
RAISES_NEG HIDDEN int pq_execute(cursorObject *curs, const char *query, int async);
|
||||
HIDDEN int pq_send_query(connectionObject *conn, const char *query);
|
||||
HIDDEN int pq_begin_locked(connectionObject *conn, PGresult **pgres,
|
||||
char **error, PyThreadState **tstate);
|
||||
HIDDEN int pq_commit(connectionObject *conn);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
|
||||
RAISES_NEG HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
|
||||
char **error, PyThreadState **tstate);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int pq_abort(connectionObject *conn);
|
||||
RAISES_NEG HIDDEN int pq_abort(connectionObject *conn);
|
||||
HIDDEN int pq_reset_locked(connectionObject *conn, PGresult **pgres,
|
||||
char **error, PyThreadState **tstate);
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
HIDDEN int pq_reset(connectionObject *conn);
|
||||
RAISES_NEG HIDDEN int pq_reset(connectionObject *conn);
|
||||
HIDDEN char *pq_get_guc_locked(connectionObject *conn, const char *param,
|
||||
PGresult **pgres,
|
||||
char **error, PyThreadState **tstate);
|
||||
|
@ -74,8 +69,7 @@ HIDDEN int pq_execute_command_locked(connectionObject *conn,
|
|||
const char *query,
|
||||
PGresult **pgres, char **error,
|
||||
PyThreadState **tstate);
|
||||
CPYCHECKER_SETS_EXCEPTION
|
||||
HIDDEN void pq_complete_error(connectionObject *conn, PGresult **pgres,
|
||||
RAISES HIDDEN void pq_complete_error(connectionObject *conn, PGresult **pgres,
|
||||
char **error);
|
||||
|
||||
#endif /* !defined(PSYCOPG_PQPATH_H) */
|
||||
|
|
|
@ -120,8 +120,7 @@ HIDDEN PyObject *psyco_GetDecimalType(void);
|
|||
typedef struct cursorObject cursorObject;
|
||||
|
||||
/* some utility functions */
|
||||
CPYCHECKER_SETS_EXCEPTION
|
||||
HIDDEN void psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg,
|
||||
RAISES HIDDEN void psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg,
|
||||
const char *pgerror, const char *pgcode);
|
||||
|
||||
HIDDEN char *psycopg_escape_string(PyObject *conn,
|
||||
|
@ -130,11 +129,9 @@ HIDDEN char *psycopg_escape_identifier_easy(const char *from, Py_ssize_t len);
|
|||
HIDDEN int psycopg_strdup(char **to, const char *from, Py_ssize_t len);
|
||||
HIDDEN int psycopg_is_text_file(PyObject *f);
|
||||
|
||||
CPYCHECKER_STEALS_REFERENCE_TO_ARG(1)
|
||||
HIDDEN PyObject * psycopg_ensure_bytes(PyObject *obj);
|
||||
STEALS(1) HIDDEN PyObject * psycopg_ensure_bytes(PyObject *obj);
|
||||
|
||||
CPYCHECKER_STEALS_REFERENCE_TO_ARG(1)
|
||||
HIDDEN PyObject * psycopg_ensure_text(PyObject *obj);
|
||||
STEALS(1) HIDDEN PyObject * psycopg_ensure_text(PyObject *obj);
|
||||
|
||||
/* Exceptions docstrings */
|
||||
#define Error_doc \
|
||||
|
|
|
@ -600,8 +600,7 @@ psyco_errors_set(PyObject *type)
|
|||
|
||||
Create a new error of the given type with extra attributes. */
|
||||
|
||||
CPYCHECKER_SETS_EXCEPTION
|
||||
void
|
||||
RAISES void
|
||||
psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg,
|
||||
const char *pgerror, const char *pgcode)
|
||||
{
|
||||
|
|
|
@ -116,8 +116,7 @@ psycopg_escape_identifier_easy(const char *from, Py_ssize_t len)
|
|||
* Store the return in 'to' and return 0 in case of success, else return -1
|
||||
* and raise an exception.
|
||||
*/
|
||||
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||
int
|
||||
RAISES_NEG int
|
||||
psycopg_strdup(char **to, const char *from, Py_ssize_t len)
|
||||
{
|
||||
if (!len) { len = strlen(from); }
|
||||
|
@ -139,8 +138,7 @@ psycopg_strdup(char **to, const char *from, Py_ssize_t len)
|
|||
*
|
||||
* It is safe to call the function on NULL.
|
||||
*/
|
||||
CPYCHECKER_STEALS_REFERENCE_TO_ARG(1)
|
||||
PyObject *
|
||||
STEALS(1) PyObject *
|
||||
psycopg_ensure_bytes(PyObject *obj)
|
||||
{
|
||||
PyObject *rv = NULL;
|
||||
|
@ -170,8 +168,7 @@ psycopg_ensure_bytes(PyObject *obj)
|
|||
* The function is ref neutral: steals a ref from obj and adds one to the
|
||||
* return value. It is safe to call it on NULL.
|
||||
*/
|
||||
CPYCHECKER_STEALS_REFERENCE_TO_ARG(1)
|
||||
PyObject *
|
||||
STEALS(1) PyObject *
|
||||
psycopg_ensure_text(PyObject *obj)
|
||||
{
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
|
|
Loading…
Reference in New Issue
Block a user