changeset 729:f953ae5b3732

PyTouhou: Fix GLFW callbacks to be nogil
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 08 Dec 2019 20:13:01 +0100
parents 414f8611f344
children f2c3848dabff
files pytouhou/lib/glfw.pyx
diffstat 1 files changed, 23 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/lib/glfw.pyx
+++ b/pytouhou/lib/glfw.pyx
@@ -27,31 +27,35 @@ OPENGL_API = GLFW_OPENGL_API
 OPENGL_ES_API = GLFW_OPENGL_ES_API
 OPENGL_CORE_PROFILE = GLFW_OPENGL_CORE_PROFILE
 
-cdef void error_callback(int a, const char* b):
-    print('GLFW error 0x%x: %s' % (a, b.decode('utf-8')))
+cdef void error_callback(int a, const char* b) nogil:
+    with gil:
+        print('GLFW error 0x%x: %s' % (a, b.decode('utf-8')))
 
 cdef list _global_events = []
 
-cdef void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods):
-    if action != GLFW_PRESS:
-        return
-    if key == GLFW_KEY_ESCAPE:
-        _global_events.append((gui.PAUSE, None))
-    elif key in (GLFW_KEY_P, GLFW_KEY_HOME):
-        _global_events.append((gui.SCREENSHOT, None))
-    elif key == GLFW_KEY_DOWN:
-        _global_events.append((gui.DOWN, None))
-    elif key == GLFW_KEY_F11:
-        _global_events.append((gui.FULLSCREEN, None))
-    elif key == GLFW_KEY_ENTER:
-        if mods & GLFW_MOD_ALT:
+cdef void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) nogil:
+    with gil:
+        if action != GLFW_PRESS:
+            return
+        if key == GLFW_KEY_ESCAPE:
+            _global_events.append((gui.PAUSE, None))
+        elif key in (GLFW_KEY_P, GLFW_KEY_HOME):
+            _global_events.append((gui.SCREENSHOT, None))
+        elif key == GLFW_KEY_DOWN:
+            _global_events.append((gui.DOWN, None))
+        elif key == GLFW_KEY_F11:
             _global_events.append((gui.FULLSCREEN, None))
+        elif key == GLFW_KEY_ENTER:
+            if mods & GLFW_MOD_ALT:
+                _global_events.append((gui.FULLSCREEN, None))
 
-cdef void size_callback(GLFWwindow* window, int width, int height):
-    _global_events.append((gui.RESIZE, (width, height)))
+cdef void size_callback(GLFWwindow* window, int width, int height) nogil:
+    with gil:
+        _global_events.append((gui.RESIZE, (width, height)))
 
-cdef void close_callback(GLFWwindow* window):
-    _global_events.append((gui.EXIT, None))
+cdef void close_callback(GLFWwindow* window) nogil:
+    with gil:
+        _global_events.append((gui.EXIT, None))
 
 cdef void init() except *:
     glfwSetErrorCallback(<GLFWerrorfun>error_callback)