diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-01 00:57:52 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-01 02:53:28 +0000 |
commit | 5bfb6cdefed3754b2a15e1e3372630691392ca47 (patch) | |
tree | a5184076e1f38373395bf0206655fb4f9e0effb2 | |
parent | f2e4a8ed78973a0d14dbe0d463911436562683f3 (diff) | |
download | psycopg2-5bfb6cdefed3754b2a15e1e3372630691392ca47.tar.gz |
Use more compact macros to annotate functions for the static checker
-rw-r--r-- | psycopg/bytes_format.c | 3 | ||||
-rw-r--r-- | psycopg/config.h | 16 | ||||
-rw-r--r-- | psycopg/connection.h | 21 | ||||
-rw-r--r-- | psycopg/connection_int.c | 27 | ||||
-rw-r--r-- | psycopg/connection_type.c | 3 | ||||
-rw-r--r-- | psycopg/cursor.h | 3 | ||||
-rw-r--r-- | psycopg/cursor_int.c | 3 | ||||
-rw-r--r-- | psycopg/cursor_type.c | 12 | ||||
-rw-r--r-- | psycopg/pqpath.c | 27 | ||||
-rw-r--r-- | psycopg/pqpath.h | 18 | ||||
-rw-r--r-- | psycopg/psycopg.h | 9 | ||||
-rw-r--r-- | psycopg/psycopgmodule.c | 3 | ||||
-rw-r--r-- | psycopg/utils.c | 9 |
13 files changed, 54 insertions, 100 deletions
diff --git a/psycopg/bytes_format.c b/psycopg/bytes_format.c index b22422b..6866207 100644 --- a/psycopg/bytes_format.c +++ b/psycopg/bytes_format.c @@ -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; diff --git a/psycopg/config.h b/psycopg/config.h index 4d3fa99..f309449 100644 --- a/psycopg/config.h +++ b/psycopg/config.h @@ -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) */ diff --git a/psycopg/connection.h b/psycopg/connection.h index d4a8348..79f823e 100644 --- a/psycopg/connection.h +++ b/psycopg/connection.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); diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 7375da3..4d1ffb9 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -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; diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index d88126b..47afbd7 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -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. diff --git a/psycopg/cursor.h b/psycopg/cursor.h index fe16b56..723bd17 100644 --- a/psycopg/cursor.h +++ b/psycopg/cursor.h @@ -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 */ diff --git a/psycopg/cursor_int.c b/psycopg/cursor_int.c index 8004bef..1ac3f55 100644 --- a/psycopg/cursor_int.c +++ b/psycopg/cursor_int.c @@ -38,8 +38,7 @@ * Return a borrowed reference. */ -CPYCHECKER_RETURNS_BORROWED_REF -PyObject * +BORROWED PyObject * curs_get_cast(cursorObject *self, PyObject *oid) { PyObject *cast; diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index b60263b..3ce02a1 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -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) { diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index e850699..899c331 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -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; diff --git a/psycopg/pqpath.h b/psycopg/pqpath.h index ef0e325..2fff85f 100644 --- a/psycopg/pqpath.h +++ b/psycopg/pqpath.h @@ -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) */ diff --git a/psycopg/psycopg.h b/psycopg/psycopg.h index 0eec138..2e86dca 100644 --- a/psycopg/psycopg.h +++ b/psycopg/psycopg.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 \ diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 7d77ee1..497c42e 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -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) { diff --git a/psycopg/utils.c b/psycopg/utils.c index 9ae710d..57586c5 100644 --- a/psycopg/utils.c +++ b/psycopg/utils.c @@ -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 |