summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--psycopg/config.h9
-rw-r--r--psycopg/psycopg.h6
-rw-r--r--psycopg/utils.c2
3 files changed, 15 insertions, 2 deletions
diff --git a/psycopg/config.h b/psycopg/config.h
index 321587a..2038ced 100644
--- a/psycopg/config.h
+++ b/psycopg/config.h
@@ -160,7 +160,7 @@ static double round(double num)
#define isinf(x) (!finite((x)) && (x)==(x))
#endif
-/* decorator for the gcc cpychecker plugin */
+/* decorators for the gcc cpychecker plugin */
#if defined(WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE)
#define CPYCHECKER_RETURNS_BORROWED_REF \
__attribute__((cpychecker_returns_borrowed_ref))
@@ -168,4 +168,11 @@ static double round(double num)
#define CPYCHECKER_RETURNS_BORROWED_REF
#endif
+#if defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)
+ #define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
+ __attribute__((cpychecker_steals_reference_to_arg(n)))
+#else
+ #define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
+#endif
+
#endif /* !defined(PSYCOPG_CONFIG_H) */
diff --git a/psycopg/psycopg.h b/psycopg/psycopg.h
index 2f06c37..01a68d9 100644
--- a/psycopg/psycopg.h
+++ b/psycopg/psycopg.h
@@ -127,9 +127,13 @@ HIDDEN char *psycopg_escape_string(PyObject *conn,
const char *from, Py_ssize_t len, char *to, Py_ssize_t *tolen);
HIDDEN char *psycopg_escape_identifier_easy(const char *from, Py_ssize_t len);
HIDDEN char *psycopg_strdup(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);
+
+CPYCHECKER_STEALS_REFERENCE_TO_ARG(1)
HIDDEN PyObject * psycopg_ensure_text(PyObject *obj);
-HIDDEN int psycopg_is_text_file(PyObject *f);
/* Exceptions docstrings */
#define Error_doc \
diff --git a/psycopg/utils.c b/psycopg/utils.c
index 2e81c11..4f40cc8 100644
--- a/psycopg/utils.c
+++ b/psycopg/utils.c
@@ -139,6 +139,7 @@ psycopg_strdup(const char *from, Py_ssize_t len)
*
* It is safe to call the function on NULL.
*/
+CPYCHECKER_STEALS_REFERENCE_TO_ARG(1)
PyObject *
psycopg_ensure_bytes(PyObject *obj)
{
@@ -169,6 +170,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 *
psycopg_ensure_text(PyObject *obj)
{