[pypy-svn] r73714 - in pypy/branch/cpython-extension/pypy/module/cpyext: include test

afa at codespeak.net afa at codespeak.net
Tue Apr 13 12:54:13 CEST 2010


Author: afa
Date: Tue Apr 13 12:54:12 2010
New Revision: 73714

Added:
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_pystate.py   (contents, props changed)
Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/include/pystate.h
Log:
Add Py_BEGIN_ALLOW_THREADS &co
with a minimal test.


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/pystate.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/pystate.h	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/pystate.h	Tue Apr 13 12:54:12 2010
@@ -1,3 +1,16 @@
+#ifndef Py_PYSTATE_H
+#define Py_PYSTATE_H
+
 typedef struct _ts {
     int initialized; // not used
 } 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); \
+		 }
+
+#endif /* !Py_PYSTATE_H */

Added: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_pystate.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_pystate.py	Tue Apr 13 12:54:12 2010
@@ -0,0 +1,19 @@
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
+
+class AppTestStringObject(AppTestCpythonExtensionBase):
+    def test_allow_threads(self):
+        module = self.import_extension('foo', [
+            ("test", "METH_NOARGS",
+             """
+                Py_BEGIN_ALLOW_THREADS
+                {
+                    Py_BLOCK_THREADS
+                    Py_UNBLOCK_THREADS
+                }
+                Py_END_ALLOW_THREADS
+                Py_RETURN_NONE;
+             """),
+            ])
+        # Should compile at least
+        module.test()
+



More information about the Pypy-commit mailing list