summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Smelkov <kirr@nexedi.com>2019-06-25 07:41:12 +0300
committerStefan Behnel <stefan_ml@behnel.de>2019-07-19 17:18:15 +0200
commitf97ff50868ac9febf6db8b6b2820d70ac5dc8ee2 (patch)
tree89d47d1456d2d36a1770389d79008e5dda43aa5d
parent7047d62cfee083c2b708f22e53e7d7503728383a (diff)
downloadcython-f97ff50868ac9febf6db8b6b2820d70ac5dc8ee2.tar.gz
Include: cpython.pystate: Make PyGILState_STATE definition usable (GH-2997)
PyGILState_STATE was added in commit 3fd6fdce66 (Gilnanny + pystate.pxd) with struct type on-purpose different from what CPython actually uses with the idea so that PyGILState_STATE cannot be coerced into int. However as it is, it prevents PyGILState_STATE usage: cdef PyGILState_STATE gstate = PyGILState_Ensure() gives Variable type 'PyGILState_STATE' is incomplete Fix it by making PyGILState_STATE a defined structure. (cherry picked from commit 82a0ed43b31f0ad263256d2725d762ee82cd2179)
-rw-r--r--Cython/Includes/cpython/pystate.pxd3
-rw-r--r--tests/run/cpython_capi.pyx15
2 files changed, 17 insertions, 1 deletions
diff --git a/Cython/Includes/cpython/pystate.pxd b/Cython/Includes/cpython/pystate.pxd
index dfe19a191..1af630793 100644
--- a/Cython/Includes/cpython/pystate.pxd
+++ b/Cython/Includes/cpython/pystate.pxd
@@ -20,7 +20,8 @@ cdef extern from "Python.h":
# This is not actually a struct, but make sure it can never be coerced to
# an int or used in arithmetic expressions
- ctypedef struct PyGILState_STATE
+ ctypedef struct PyGILState_STATE:
+ pass
# The type of the trace function registered using PyEval_SetProfile() and
# PyEval_SetTrace().
diff --git a/tests/run/cpython_capi.pyx b/tests/run/cpython_capi.pyx
index db9af7446..62100ed7f 100644
--- a/tests/run/cpython_capi.pyx
+++ b/tests/run/cpython_capi.pyx
@@ -2,6 +2,7 @@
# tag: c-api
from cpython cimport mem
+from cpython.pystate cimport PyGILState_Ensure, PyGILState_Release, PyGILState_STATE
def test_pymalloc():
@@ -47,3 +48,17 @@ def test_pymalloc_raw():
mem.PyMem_RawFree(m)
assert m2
return retval
+
+
+def test_gilstate():
+ """
+ >>> test_gilstate()
+ 'ok'
+ """
+
+ # cython used to have invalid definition for PyGILState_STATE, which was
+ # making the following code fail to compile
+ cdef PyGILState_STATE gstate = PyGILState_Ensure()
+ # TODO assert that GIL is taken
+ PyGILState_Release(gstate)
+ return 'ok'