aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/cpython-plugin-test-PyList_Append.c
blob: e1efd9efda5ef6df3803de03762492be1ec00fda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* { dg-do compile } */
/* { dg-require-effective-target analyzer } */
/* { dg-options "-fanalyzer" } */
/* { dg-require-python-h "" } */


#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "../analyzer/analyzer-decls.h"

PyObject *
test_PyListAppend (long n)
{
  PyObject *item = PyLong_FromLong (n);
  PyObject *list = PyList_New (0);
  PyList_Append(list, item);
  return list; /* { dg-warning "leak of 'item'" } */
  /* { dg-warning "expected 'item' to have reference count" "" { target *-*-* } .-1 } */
}

PyObject *
test_PyListAppend_2 (long n)
{
  PyObject *item = PyLong_FromLong (n);
  if (!item)
	return NULL;

  __analyzer_eval (item->ob_refcnt == 1); /* { dg-warning "TRUE" } */
  PyObject *list = PyList_New (n);
  if (!list)
  {
	Py_DECREF(item);
	return NULL;
  }

  __analyzer_eval (list->ob_refcnt == 1); /* { dg-warning "TRUE" } */

  if (PyList_Append (list, item) < 0)
    __analyzer_eval (item->ob_refcnt == 1); /* { dg-warning "TRUE" } */
  else
    __analyzer_eval (item->ob_refcnt == 2); /* { dg-warning "TRUE" } */
  return list; /* { dg-warning "leak of 'item'" } */
  /* { dg-warning "expected 'item' to have reference count" "" { target *-*-* } .-1 } */
}


PyObject *
test_PyListAppend_3 (PyObject *item, PyObject *list)
{
  PyList_Append (list, item);
  return list;
}

PyObject *
test_PyListAppend_4 (long n)
{
  PyObject *item = PyLong_FromLong (n);
  PyObject *list = NULL;
  PyList_Append(list, item);
  return list;
}

PyObject *
test_PyListAppend_5 ()
{
  PyObject *list = PyList_New (0);
  PyList_Append(list, NULL);
  return list;
}

PyObject *
test_PyListAppend_6 ()
{
  PyObject *item = NULL;
  PyObject *list = NULL;
  PyList_Append(list, item);
  return list;
}