1 /* { dg-do compile } */
2 /* { dg-require-effective-target analyzer } */
3 /* { dg-options "-fanalyzer" } */
4 /* { dg-require-python-h "" } */
7 #define PY_SSIZE_T_CLEAN
9 #include "../analyzer/analyzer-decls.h"
12 test_PyListAppend (long n
)
14 PyObject
*item
= PyLong_FromLong (n
);
15 PyObject
*list
= PyList_New (0);
16 PyList_Append(list
, item
);
17 return list
; /* { dg-warning "leak of 'item'" } */
18 /* { dg-warning "expected 'item' to have reference count" "" { target *-*-* } .-1 } */
22 test_PyListAppend_2 (long n
)
24 PyObject
*item
= PyLong_FromLong (n
);
28 __analyzer_eval (item
->ob_refcnt
== 1); /* { dg-warning "TRUE" } */
29 PyObject
*list
= PyList_New (n
);
36 __analyzer_eval (list
->ob_refcnt
== 1); /* { dg-warning "TRUE" } */
38 if (PyList_Append (list
, item
) < 0)
39 __analyzer_eval (item
->ob_refcnt
== 1); /* { dg-warning "TRUE" } */
41 __analyzer_eval (item
->ob_refcnt
== 2); /* { dg-warning "TRUE" } */
42 return list
; /* { dg-warning "leak of 'item'" } */
43 /* { dg-warning "expected 'item' to have reference count" "" { target *-*-* } .-1 } */
48 test_PyListAppend_3 (PyObject
*item
, PyObject
*list
)
50 PyList_Append (list
, item
);
55 test_PyListAppend_4 (long n
)
57 PyObject
*item
= PyLong_FromLong (n
);
58 PyObject
*list
= NULL
;
59 PyList_Append(list
, item
);
64 test_PyListAppend_5 ()
66 PyObject
*list
= PyList_New (0);
67 PyList_Append(list
, NULL
);
72 test_PyListAppend_6 ()
74 PyObject
*item
= NULL
;
75 PyObject
*list
= NULL
;
76 PyList_Append(list
, item
);