aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/cpython-plugin-test-PyLong_FromLong.c
blob: 6ac593964ba3194283a0f148e72376e096ab8430 (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
/* { 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_PyLong_New (long n)
{
  PyObject *obj = PyLong_FromLong (n);
  if (obj)
    {
     __analyzer_eval (obj->ob_refcnt == 1); /* { dg-warning "TRUE" } */
     __analyzer_eval (PyLong_CheckExact (obj)); /* { dg-warning "TRUE" } */
    }
  else
    __analyzer_dump_path (); /* { dg-message "path" } */
  return obj;
}

void
test_PyLong_New_2 (long n)
{
  PyObject *obj = PyLong_FromLong (n);
} /* { dg-warning "leak of 'obj'" } */

PyObject *test_stray_incref_PyLong (long val)
{
  PyObject *p = PyLong_FromLong (val);
  if (p)
    Py_INCREF (p);
  return p;
  /* { dg-warning "expected 'p' to have reference count" "" { target *-*-* } .-1 } */
}