Debian Codegraph @

gcc/testsuite/gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c

raw
1 /* { dg-do compile } */
2 /* { dg-require-effective-target analyzer } */
3 /* { dg-options "-fanalyzer" } */
4 /* { dg-require-python-h "" } */
5
6
7 #define PY_SSIZE_T_CLEAN
8 #include <Python.h>
9 #include "../analyzer/analyzer-decls.h"
10
11 PyObject *
12 test_PyLong_New (long n)
13 {
14 PyObject *obj = PyLong_FromLong (n);
15 if (obj)
16 {
17 __analyzer_eval (obj->ob_refcnt == 1); /* { dg-warning "TRUE" } */
18 __analyzer_eval (PyLong_CheckExact (obj)); /* { dg-warning "TRUE" } */
19 }
20 else
21 __analyzer_dump_path (); /* { dg-message "path" } */
22 return obj;
23 }
24
25 void
26 test_PyLong_New_2 (long n)
27 {
28 PyObject *obj = PyLong_FromLong (n);
29 } /* { dg-warning "leak of 'obj'" } */
30
31 PyObject *test_stray_incref_PyLong (long val)
32 {
33 PyObject *p = PyLong_FromLong (val);
34 if (p)
35 Py_INCREF (p);
36 return p;
37 /* { dg-warning "expected 'p' to have reference count" "" { target *-*-* } .-1 } */
38 }