1  /* Adapted from CPython 3.8's ceval.h.  */
       2  typedef struct PyThreadState PyThreadState;
       3  extern PyThreadState * PyEval_SaveThread(void);
       4  extern void PyEval_RestoreThread(PyThreadState *);
       5  
       6  #define Py_BEGIN_ALLOW_THREADS { \
       7                          PyThreadState *_save; \
       8                          _save = PyEval_SaveThread();
       9  #define Py_BLOCK_THREADS        PyEval_RestoreThread(_save);
      10  #define Py_UNBLOCK_THREADS      _save = PyEval_SaveThread();
      11  #define Py_END_ALLOW_THREADS    PyEval_RestoreThread(_save); \
      12                   }
      13  
      14  /* Adapted/hacked up from CPython 3.8's object.h.  */
      15  
      16  typedef struct _object {
      17      int ob_refcnt;
      18  } PyObject;
      19  
      20  #define _PyObject_CAST(op) ((PyObject*)(op))
      21  
      22  extern void _Py_Dealloc(PyObject *);
      23  
      24  #define _Py_INCREF(OP) do { (OP)->ob_refcnt++; } while (0);
      25  #define _Py_DECREF(OP) do {	  \
      26      if (--(OP)->ob_refcnt == 0) { \
      27        _Py_Dealloc(OP);		  \
      28      }				  \
      29    } while (0)
      30  
      31  #define Py_INCREF(op) _Py_INCREF(_PyObject_CAST(op))
      32  #define Py_DECREF(op) _Py_DECREF(_PyObject_CAST(op))