Skip to content

Commit 5bfb6cd

Browse files
committed
Use more compact macros to annotate functions for the static checker
1 parent f2e4a8e commit 5bfb6cd

File tree

13 files changed

+54
-100
lines changed

13 files changed

+54
-100
lines changed

psycopg/bytes_format.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@
8686

8787
/* Helpers for formatstring */
8888

89-
CPYCHECKER_RETURNS_BORROWED_REF
90-
Py_LOCAL_INLINE(PyObject *)
89+
BORROWED Py_LOCAL_INLINE(PyObject *)
9190
getnextarg(PyObject *args, Py_ssize_t arglen, Py_ssize_t *p_argidx)
9291
{
9392
Py_ssize_t argidx = *p_argidx;

psycopg/config.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,31 +162,31 @@ static double round(double num)
162162

163163
/* decorators for the gcc cpychecker plugin */
164164
#if defined(WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE)
165-
#define CPYCHECKER_RETURNS_BORROWED_REF \
165+
#define BORROWED \
166166
__attribute__((cpychecker_returns_borrowed_ref))
167167
#else
168-
#define CPYCHECKER_RETURNS_BORROWED_REF
168+
#define BORROWED
169169
#endif
170170

171171
#if defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)
172-
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
172+
#define STEALS(n) \
173173
__attribute__((cpychecker_steals_reference_to_arg(n)))
174174
#else
175-
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
175+
#define STEALS(n)
176176
#endif
177177

178178
#if defined(WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE)
179-
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION \
179+
#define RAISES_NEG \
180180
__attribute__((cpychecker_negative_result_sets_exception))
181181
#else
182-
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
182+
#define RAISES_NEG
183183
#endif
184184

185185
#if defined(WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE)
186-
#define CPYCHECKER_SETS_EXCEPTION \
186+
#define RAISES \
187187
__attribute__((cpychecker_sets_exception))
188188
#else
189-
#define CPYCHECKER_SETS_EXCEPTION
189+
#define RAISES
190190
#endif
191191

192192
#endif /* !defined(PSYCOPG_CONFIG_H) */

psycopg/connection.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ typedef struct {
131131
/* C-callable functions in connection_int.c and connection_ext.c */
132132
HIDDEN PyObject *conn_text_from_chars(connectionObject *pgconn, const char *str);
133133
HIDDEN int conn_get_standard_conforming_strings(PGconn *pgconn);
134-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
135-
HIDDEN int conn_get_isolation_level(connectionObject *self);
134+
RAISES_NEG HIDDEN int conn_get_isolation_level(connectionObject *self);
136135
HIDDEN int conn_get_protocol_version(PGconn *pgconn);
137136
HIDDEN int conn_get_server_version(PGconn *pgconn);
138137
HIDDEN PGcancel *conn_get_cancel(PGconn *pgconn);
@@ -142,23 +141,17 @@ HIDDEN void conn_notifies_process(connectionObject *self);
142141
HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
143142
HIDDEN int conn_connect(connectionObject *self, long int async);
144143
HIDDEN void conn_close(connectionObject *self);
145-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
146-
HIDDEN int conn_commit(connectionObject *self);
147-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
148-
HIDDEN int conn_rollback(connectionObject *self);
144+
RAISES_NEG HIDDEN int conn_commit(connectionObject *self);
145+
RAISES_NEG HIDDEN int conn_rollback(connectionObject *self);
149146
HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
150147
const char *readonly, const char *deferrable,
151148
int autocommit);
152149
HIDDEN int conn_set_autocommit(connectionObject *self, int value);
153-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
154-
HIDDEN int conn_switch_isolation_level(connectionObject *self, int level);
155-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
156-
HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc);
150+
RAISES_NEG HIDDEN int conn_switch_isolation_level(connectionObject *self, int level);
151+
RAISES_NEG HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc);
157152
HIDDEN int conn_poll(connectionObject *self);
158-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
159-
HIDDEN int conn_tpc_begin(connectionObject *self, XidObject *xid);
160-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
161-
HIDDEN int conn_tpc_command(connectionObject *self,
153+
RAISES_NEG HIDDEN int conn_tpc_begin(connectionObject *self, XidObject *xid);
154+
RAISES_NEG HIDDEN int conn_tpc_command(connectionObject *self,
162155
const char *cmd, XidObject *xid);
163156
HIDDEN PyObject *conn_tpc_recover(connectionObject *self);
164157

psycopg/connection_int.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ conn_get_standard_conforming_strings(PGconn *pgconn)
253253
* Return a buffer allocated on Python heap into 'clean' and return 0 on
254254
* success, otherwise return -1 and set an exception.
255255
*/
256-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
257-
static int
256+
RAISES_NEG static int
258257
clear_encoding_name(const char *enc, char **clean)
259258
{
260259
const char *i = enc;
@@ -292,8 +291,7 @@ clear_encoding_name(const char *enc, char **clean)
292291
*
293292
* 'enc' should be already normalized (uppercase, no - or _).
294293
*/
295-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
296-
static int
294+
RAISES_NEG static int
297295
conn_encoding_to_codec(const char *enc, char **codec)
298296
{
299297
char *tmp;
@@ -376,8 +374,7 @@ conn_read_encoding(connectionObject *self, PGconn *pgconn)
376374
}
377375

378376

379-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
380-
int
377+
RAISES_NEG int
381378
conn_get_isolation_level(connectionObject *self)
382379
{
383380
PGresult *pgres = NULL;
@@ -954,8 +951,7 @@ conn_close(connectionObject *self)
954951

955952
/* conn_commit - commit on a connection */
956953

957-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
958-
int
954+
RAISES_NEG int
959955
conn_commit(connectionObject *self)
960956
{
961957
int res;
@@ -966,8 +962,7 @@ conn_commit(connectionObject *self)
966962

967963
/* conn_rollback - rollback a connection */
968964

969-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
970-
int
965+
RAISES_NEG int
971966
conn_rollback(connectionObject *self)
972967
{
973968
int res;
@@ -1049,8 +1044,7 @@ conn_set_autocommit(connectionObject *self, int value)
10491044

10501045
/* conn_switch_isolation_level - switch isolation level on the connection */
10511046

1052-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
1053-
int
1047+
RAISES_NEG int
10541048
conn_switch_isolation_level(connectionObject *self, int level)
10551049
{
10561050
PGresult *pgres = NULL;
@@ -1132,8 +1126,7 @@ conn_switch_isolation_level(connectionObject *self, int level)
11321126

11331127
/* conn_set_client_encoding - switch client encoding on connection */
11341128

1135-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
1136-
int
1129+
RAISES_NEG int
11371130
conn_set_client_encoding(connectionObject *self, const char *enc)
11381131
{
11391132
PGresult *pgres = NULL;
@@ -1206,8 +1199,7 @@ conn_set_client_encoding(connectionObject *self, const char *enc)
12061199
* in regular transactions, as PostgreSQL won't even know we are in a TPC
12071200
* until PREPARE. */
12081201

1209-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
1210-
int
1202+
RAISES_NEG int
12111203
conn_tpc_begin(connectionObject *self, XidObject *xid)
12121204
{
12131205
PGresult *pgres = NULL;
@@ -1241,8 +1233,7 @@ conn_tpc_begin(connectionObject *self, XidObject *xid)
12411233
* The function doesn't change the connection state as it can be used
12421234
* for many commands and for recovered transactions. */
12431235

1244-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
1245-
int
1236+
RAISES_NEG int
12461237
conn_tpc_command(connectionObject *self, const char *cmd, XidObject *xid)
12471238
{
12481239
PGresult *pgres = NULL;

psycopg/connection_type.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,7 @@ psyco_conn_autocommit_get(connectionObject *self)
550550
return ret;
551551
}
552552

553-
CPYCHECKER_RETURNS_BORROWED_REF
554-
static PyObject *
553+
BORROWED static PyObject *
555554
_psyco_conn_autocommit_set_checks(connectionObject *self)
556555
{
557556
/* wrapper to use the EXC_IF macros.

psycopg/cursor.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ struct cursorObject {
8585

8686

8787
/* C-callable functions in cursor_int.c and cursor_ext.c */
88-
CPYCHECKER_RETURNS_BORROWED_REF
89-
HIDDEN PyObject *curs_get_cast(cursorObject *self, PyObject *oid);
88+
BORROWED HIDDEN PyObject *curs_get_cast(cursorObject *self, PyObject *oid);
9089
HIDDEN void curs_reset(cursorObject *self);
9190

9291
/* exception-raising macros */

psycopg/cursor_int.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
* Return a borrowed reference.
3939
*/
4040

41-
CPYCHECKER_RETURNS_BORROWED_REF
42-
PyObject *
41+
BORROWED PyObject *
4342
curs_get_cast(cursorObject *self, PyObject *oid)
4443
{
4544
PyObject *cast;

psycopg/cursor_type.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ psyco_curs_close(cursorObject *self, PyObject *args)
7575

7676
/* mogrify a query string and build argument array or dict */
7777

78-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
79-
static int
78+
RAISES_NEG static int
8079
_mogrify(PyObject *var, PyObject *fmt, cursorObject *curs, PyObject **new)
8180
{
8281
PyObject *key, *value, *n;
@@ -360,8 +359,7 @@ _psyco_curs_merge_query_args(cursorObject *self,
360359
#define psyco_curs_execute_doc \
361360
"execute(query, vars=None) -- Execute query with bound vars."
362361

363-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
364-
static int
362+
RAISES_NEG static int
365363
_psyco_curs_execute(cursorObject *self,
366364
PyObject *operation, PyObject *vars, long int async)
367365
{
@@ -645,8 +643,7 @@ psyco_curs_cast(cursorObject *self, PyObject *args)
645643
"default) or using the sequence factory previously set in the\n" \
646644
"`row_factory` attribute. Return `!None` when no more data is available.\n"
647645

648-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
649-
static int
646+
RAISES_NEG static int
650647
_psyco_curs_prefetch(cursorObject *self)
651648
{
652649
int i = 0;
@@ -663,8 +660,7 @@ _psyco_curs_prefetch(cursorObject *self)
663660
return i;
664661
}
665662

666-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
667-
static int
663+
RAISES_NEG static int
668664
_psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
669665
int row, int n, int istuple)
670666
{

psycopg/pqpath.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ strip_severity(const char *msg)
6464
code. A list of error codes can be found at:
6565
6666
http://www.postgresql.org/docs/current/static/errcodes-appendix.html */
67-
CPYCHECKER_RETURNS_BORROWED_REF
68-
static PyObject *
67+
BORROWED static PyObject *
6968
exception_from_sqlstate(const char *sqlstate)
7069
{
7170
switch (sqlstate[0]) {
@@ -152,8 +151,7 @@ exception_from_sqlstate(const char *sqlstate)
152151
153152
This function should be called while holding the GIL. */
154153

155-
CPYCHECKER_SETS_EXCEPTION
156-
static void
154+
RAISES static void
157155
pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres)
158156
{
159157
PyObject *exc = NULL;
@@ -253,8 +251,7 @@ pq_clear_critical(connectionObject *conn)
253251

254252
/* return -1 if the exception is set (i.e. if conn->critical is set),
255253
* else 0 */
256-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
257-
static int
254+
RAISES_NEG static int
258255
pq_resolve_critical(connectionObject *conn, int close)
259256
{
260257
Dprintf("pq_resolve_critical: resolving %s", conn->critical);
@@ -389,8 +386,7 @@ pq_execute_command_locked(connectionObject *conn, const char *query,
389386
This function should be called while holding the global interpreter
390387
lock.
391388
*/
392-
CPYCHECKER_SETS_EXCEPTION
393-
void
389+
RAISES void
394390
pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
395391
{
396392
Dprintf("pq_complete_error: pgconn = %p, pgres = %p, error = %s",
@@ -483,8 +479,7 @@ pq_commit(connectionObject *conn)
483479
return retvalue;
484480
}
485481

486-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
487-
int
482+
RAISES_NEG int
488483
pq_abort_locked(connectionObject *conn, PGresult **pgres, char **error,
489484
PyThreadState **tstate)
490485
{
@@ -511,8 +506,7 @@ pq_abort_locked(connectionObject *conn, PGresult **pgres, char **error,
511506
This function should be called while holding the global interpreter
512507
lock. */
513508

514-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
515-
int
509+
RAISES_NEG int
516510
pq_abort(connectionObject *conn)
517511
{
518512
int retvalue = -1;
@@ -554,8 +548,7 @@ pq_abort(connectionObject *conn)
554548
connection without holding the global interpreter lock.
555549
*/
556550

557-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
558-
int
551+
RAISES_NEG int
559552
pq_reset_locked(connectionObject *conn, PGresult **pgres, char **error,
560553
PyThreadState **tstate)
561554
{
@@ -847,8 +840,7 @@ pq_flush(connectionObject *conn)
847840
this fucntion locks the connection object
848841
this function call Py_*_ALLOW_THREADS macros */
849842

850-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
851-
int
843+
RAISES_NEG int
852844
pq_execute(cursorObject *curs, const char *query, int async)
853845
{
854846
PGresult *pgres = NULL;
@@ -1028,8 +1020,7 @@ pq_get_last_result(connectionObject *conn)
10281020
1 - result from backend (possibly data is ready)
10291021
*/
10301022

1031-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
1032-
static int
1023+
RAISES_NEG static int
10331024
_pq_fetch_tuples(cursorObject *curs)
10341025
{
10351026
int i, *dsize = NULL;

psycopg/pqpath.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,18 @@
3535

3636
/* exported functions */
3737
HIDDEN PGresult *pq_get_last_result(connectionObject *conn);
38-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
39-
HIDDEN int pq_fetch(cursorObject *curs);
40-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
41-
HIDDEN int pq_execute(cursorObject *curs, const char *query, int async);
38+
RAISES_NEG HIDDEN int pq_fetch(cursorObject *curs);
39+
RAISES_NEG HIDDEN int pq_execute(cursorObject *curs, const char *query, int async);
4240
HIDDEN int pq_send_query(connectionObject *conn, const char *query);
4341
HIDDEN int pq_begin_locked(connectionObject *conn, PGresult **pgres,
4442
char **error, PyThreadState **tstate);
4543
HIDDEN int pq_commit(connectionObject *conn);
46-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
47-
HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
44+
RAISES_NEG HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
4845
char **error, PyThreadState **tstate);
49-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
50-
HIDDEN int pq_abort(connectionObject *conn);
46+
RAISES_NEG HIDDEN int pq_abort(connectionObject *conn);
5147
HIDDEN int pq_reset_locked(connectionObject *conn, PGresult **pgres,
5248
char **error, PyThreadState **tstate);
53-
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
54-
HIDDEN int pq_reset(connectionObject *conn);
49+
RAISES_NEG HIDDEN int pq_reset(connectionObject *conn);
5550
HIDDEN char *pq_get_guc_locked(connectionObject *conn, const char *param,
5651
PGresult **pgres,
5752
char **error, PyThreadState **tstate);
@@ -74,8 +69,7 @@ HIDDEN int pq_execute_command_locked(connectionObject *conn,
7469
const char *query,
7570
PGresult **pgres, char **error,
7671
PyThreadState **tstate);
77-
CPYCHECKER_SETS_EXCEPTION
78-
HIDDEN void pq_complete_error(connectionObject *conn, PGresult **pgres,
72+
RAISES HIDDEN void pq_complete_error(connectionObject *conn, PGresult **pgres,
7973
char **error);
8074

8175
#endif /* !defined(PSYCOPG_PQPATH_H) */

0 commit comments

Comments
 (0)