| 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_PyListAppend (long n) |
| 13 |
{ |
| 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 } */ |
| 19 |
} |
| 20 |
|
| 21 |
PyObject * |
| 22 |
test_PyListAppend_2 (long n) |
| 23 |
{ |
| 24 |
PyObject *item = PyLong_FromLong (n); |
| 25 |
if (!item) |
| 26 |
return NULL; |
| 27 |
|
| 28 |
__analyzer_eval (item->ob_refcnt == 1); /* { dg-warning "TRUE" } */ |
| 29 |
PyObject *list = PyList_New (n); |
| 30 |
if (!list) |
| 31 |
{ |
| 32 |
Py_DECREF(item); |
| 33 |
return NULL; |
| 34 |
} |
| 35 |
|
| 36 |
__analyzer_eval (list->ob_refcnt == 1); /* { dg-warning "TRUE" } */ |
| 37 |
|
| 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 } */ |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
PyObject * |
| 48 |
test_PyListAppend_3 (PyObject *item, PyObject *list) |
| 49 |
{ |
| 50 |
PyList_Append (list, item); |
| 51 |
return list; |
| 52 |
} |
| 53 |
|
| 54 |
PyObject * |
| 55 |
test_PyListAppend_4 (long n) |
| 56 |
{ |
| 57 |
PyObject *item = PyLong_FromLong (n); |
| 58 |
PyObject *list = NULL; |
| 59 |
PyList_Append(list, item); |
| 60 |
return list; |
| 61 |
} |
| 62 |
|
| 63 |
PyObject * |
| 64 |
test_PyListAppend_5 () |
| 65 |
{ |
| 66 |
PyObject *list = PyList_New (0); |
| 67 |
PyList_Append(list, NULL); |
| 68 |
return list; |
| 69 |
} |
| 70 |
|
| 71 |
PyObject * |
| 72 |
test_PyListAppend_6 () |
| 73 |
{ |
| 74 |
PyObject *item = NULL; |
| 75 |
PyObject *list = NULL; |
| 76 |
PyList_Append(list, item); |
| 77 |
return list; |
| 78 |
} |