libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / cpython-plugin-test-PyList_Append.c
blobe1efd9efda5ef6df3803de03762492be1ec00fda
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
8 #include <Python.h>
9 #include "../analyzer/analyzer-decls.h"
11 PyObject *
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 } */
21 PyObject *
22 test_PyListAppend_2 (long n)
24 PyObject *item = PyLong_FromLong (n);
25 if (!item)
26 return NULL;
28 __analyzer_eval (item->ob_refcnt == 1); /* { dg-warning "TRUE" } */
29 PyObject *list = PyList_New (n);
30 if (!list)
32 Py_DECREF(item);
33 return NULL;
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" } */
40 else
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 } */
47 PyObject *
48 test_PyListAppend_3 (PyObject *item, PyObject *list)
50 PyList_Append (list, item);
51 return list;
54 PyObject *
55 test_PyListAppend_4 (long n)
57 PyObject *item = PyLong_FromLong (n);
58 PyObject *list = NULL;
59 PyList_Append(list, item);
60 return list;
63 PyObject *
64 test_PyListAppend_5 ()
66 PyObject *list = PyList_New (0);
67 PyList_Append(list, NULL);
68 return list;
71 PyObject *
72 test_PyListAppend_6 ()
74 PyObject *item = NULL;
75 PyObject *list = NULL;
76 PyList_Append(list, item);
77 return list;