| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events" } */ |
| 3 |
|
| 4 |
#include <stddef.h> |
| 5 |
#include <stdlib.h> |
| 6 |
|
| 7 |
/* Minimal reimplementation of cpython API. */ |
| 8 |
typedef struct PyObject {} PyObject; |
| 9 |
extern int PyArg_ParseTuple (PyObject *args, const char *fmt, ...); |
| 10 |
extern PyObject *PyList_New (int); |
| 11 |
extern PyObject *PyLong_FromLong(long); |
| 12 |
extern void PyList_Append(PyObject *list, PyObject *item); |
| 13 |
|
| 14 |
PyObject * |
| 15 |
make_a_list_of_random_ints_badly(PyObject *self, |
| 16 |
PyObject *args) |
| 17 |
{ |
| 18 |
PyObject *list, *item; |
| 19 |
long count, i; |
| 20 |
|
| 21 |
if (!PyArg_ParseTuple(args, "i", &count)) { |
| 22 |
return NULL; |
| 23 |
} |
| 24 |
|
| 25 |
list = PyList_New(0); |
| 26 |
|
| 27 |
for (i = 0; i < count; i++) { |
| 28 |
item = PyLong_FromLong(random()); |
| 29 |
PyList_Append(list, item); /* { dg-line PyList_Append } */ |
| 30 |
} |
| 31 |
|
| 32 |
return list; |
| 33 |
|
| 34 |
/* { dg-error "passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter" "" { target *-*-* } PyList_Append } */ |
| 35 |
/* { dg-begin-multiline-output "" } |
| 36 |
29 | PyList_Append(list, item); |
| 37 |
| ^~~~~~~~~~~~~~~~~~~~~~~~~ |
| 38 |
'make_a_list_of_random_ints_badly': events 1-3 |
| 39 |
25 | list = PyList_New(0); |
| 40 |
| ^~~~~~~~~~~~~ |
| 41 |
| | |
| 42 |
| (1) when 'PyList_New' fails, returning NULL |
| 43 |
26 | |
| 44 |
27 | for (i = 0; i < count; i++) { |
| 45 |
| ~~~~~~~~~ |
| 46 |
| | |
| 47 |
| (2) when 'i < count' |
| 48 |
28 | item = PyLong_FromLong(random()); |
| 49 |
29 | PyList_Append(list, item); |
| 50 |
| ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 51 |
| | |
| 52 |
| (3) when calling 'PyList_Append', passing NULL from (1) as argument 1 |
| 53 |
{ dg-end-multiline-output "" } */ |
| 54 |
} |