[pypy-svn] r73652 - in pypy/branch/cpython-extension/pypy/module/cpyext: . include
xoraxax at codespeak.net
xoraxax at codespeak.net
Sun Apr 11 22:04:10 CEST 2010
Author: xoraxax
Date: Sun Apr 11 22:04:09 2010
New Revision: 73652
Added:
pypy/branch/cpython-extension/pypy/module/cpyext/include/pystate.h (contents, props changed)
pypy/branch/cpython-extension/pypy/module/cpyext/pystate.py (contents, props changed)
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h
Log:
Implemented basic GIL handling for CPyExt.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py Sun Apr 11 22:04:09 2010
@@ -63,6 +63,7 @@
import pypy.module.cpyext.number
import pypy.module.cpyext.sliceobject
import pypy.module.cpyext.stubsactive
+import pypy.module.cpyext.pystate
# now that all rffi_platform.Struct types are registered, configure them
api.configure_types()
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h Sun Apr 11 22:04:09 2010
@@ -7,6 +7,7 @@
# include <stdint.h>
# include <stddef.h>
# include <limits.h>
+# include <math.h>
# define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
# define PyAPI_DATA(RTYPE) extern RTYPE
#else
@@ -41,6 +42,10 @@
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
#endif
+#ifndef DL_EXPORT /* declarations for DLL import/export */
+#define DL_EXPORT(RTYPE) RTYPE
+#endif
+
#define statichere static
#define Py_MEMCPY memcpy
@@ -83,6 +88,7 @@
#include "pycobject.h"
#include "bufferobject.h"
#include "sliceobject.h"
+#include "pystate.h"
// XXX This shouldn't be included here
#include "structmember.h"
Added: pypy/branch/cpython-extension/pypy/module/cpyext/include/pystate.h
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/pystate.h Sun Apr 11 22:04:09 2010
@@ -0,0 +1,3 @@
+typedef struct _ts {
+ int initialized; // not used
+} PyThreadState;
Added: pypy/branch/cpython-extension/pypy/module/cpyext/pystate.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/pystate.py Sun Apr 11 22:04:09 2010
@@ -0,0 +1,31 @@
+from pypy.module.cpyext.api import cpython_api, generic_cpy_call, CANNOT_FAIL,\
+ cpython_struct
+from pypy.rpython.lltypesystem import rffi, lltype
+
+
+PyThreadState = lltype.Ptr(cpython_struct("PyThreadState", ()))
+
+ at cpython_api([], PyThreadState, error=CANNOT_FAIL)
+def PyEval_SaveThread(space):
+ """Release the global interpreter lock (if it has been created and thread
+ support is enabled) and reset the thread state to NULL, returning the
+ previous thread state (which is not NULL except in PyPy). If the lock has been created,
+ the current thread must have acquired it. (This function is available even
+ when thread support is disabled at compile time.)"""
+ if space.config.objspace.usemodules.thread:
+ from pypy.module.thread.gil import before_external_call
+ before_external_call()
+ return lltype.nullptr(PyThreadState.TO)
+
+ at cpython_api([PyThreadState], lltype.Void)
+def PyEval_RestoreThread(space, tstate):
+ """Acquire the global interpreter lock (if it has been created and thread
+ support is enabled) and set the thread state to tstate, which must not be
+ NULL. If the lock has been created, the current thread must not have
+ acquired it, otherwise deadlock ensues. (This function is available even
+ when thread support is disabled at compile time.)"""
+ if space.config.objspace.usemodules.thread:
+ from pypy.module.thread.gil import after_external_call
+ after_external_call()
+
+
More information about the Pypy-commit
mailing list