aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/gil.h
blob: b0610cd749e1c01d62ca3cc3b3880ee917c96af4 (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
/* Adapted from CPython 3.8's ceval.h.  */
typedef struct PyThreadState PyThreadState;
extern PyThreadState * PyEval_SaveThread(void);
extern void PyEval_RestoreThread(PyThreadState *);

#define Py_BEGIN_ALLOW_THREADS { \
                        PyThreadState *_save; \
                        _save = PyEval_SaveThread();
#define Py_BLOCK_THREADS        PyEval_RestoreThread(_save);
#define Py_UNBLOCK_THREADS      _save = PyEval_SaveThread();
#define Py_END_ALLOW_THREADS    PyEval_RestoreThread(_save); \
                 }

/* Adapted/hacked up from CPython 3.8's object.h.  */

typedef struct _object {
    int ob_refcnt;
} PyObject;

#define _PyObject_CAST(op) ((PyObject*)(op))

extern void _Py_Dealloc(PyObject *);

#define _Py_INCREF(OP) do { (OP)->ob_refcnt++; } while (0);
#define _Py_DECREF(OP) do {	  \
    if (--(OP)->ob_refcnt == 0) { \
      _Py_Dealloc(OP);		  \
    }				  \
  } while (0)

#define Py_INCREF(op) _Py_INCREF(_PyObject_CAST(op))
#define Py_DECREF(op) _Py_DECREF(_PyObject_CAST(op))