Author: mattip <[email protected]>
Branch: disable_pythonapi
Changeset: r72274:ad184a18b1ef
Date: 2014-06-30 03:56 +0300
http://bitbucket.org/pypy/pypy/changeset/ad184a18b1ef/
Log: backout removal of sys.dllhandle
diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -65,7 +65,7 @@
signal
struct
symbol
- sys (without sys.dllhandle on windows)
+ sys
termios
thread
time
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -809,6 +809,8 @@
import ctypes
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
+ space.fromcache(State).install_dll(eci)
+
# populate static data
for name, (typ, expr) in GLOBALS.iteritems():
from pypy.module import cpyext
@@ -1002,6 +1004,23 @@
separate_module_sources = [code, struct_source]
+ if sys.platform == 'win32':
+ get_pythonapi_source = '''
+ #include <windows.h>
+ HANDLE pypy_get_pythonapi_handle() {
+ MEMORY_BASIC_INFORMATION mi;
+ memset(&mi, 0, sizeof(mi));
+
+ if( !VirtualQueryEx(GetCurrentProcess(),
&pypy_get_pythonapi_handle,
+ &mi, sizeof(mi)) )
+ return 0;
+
+ return (HMODULE)mi.AllocationBase;
+ }
+ '''
+ separate_module_sources.append(get_pythonapi_source)
+ export_symbols_eci.append('pypy_get_pythonapi_handle')
+
eci = ExternalCompilationInfo(
include_dirs=include_dirs,
separate_module_files=[source_dir / "varargwrapper.c",
@@ -1046,6 +1065,8 @@
eci = build_eci(False, export_symbols, code)
+ space.fromcache(State).install_dll(eci)
+
run_bootstrap_functions(space)
setup_va_functions(eci)
diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -62,6 +62,14 @@
else:
api.setup_library(self.space)
+ def install_dll(self, eci):
+ """NOT_RPYTHON
+ Called when the dll has been compiled"""
+ if sys.platform == 'win32':
+ self.get_pythonapi_handle = rffi.llexternal(
+ 'pypy_get_pythonapi_handle', [], DLLHANDLE,
+ compilation_info=eci)
+
def startup(self, space):
"This function is called when the program really starts"
diff --git a/pypy/module/cpyext/test/test_cpyext.py
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -201,6 +201,13 @@
raises(ImportError, cpyext.load_module, "missing.file", "foo")
raises(ImportError, cpyext.load_module, self.libc, "invalid.function")
+ def test_dllhandle(self):
+ import sys
+ if sys.platform != "win32" or sys.version_info < (2, 6):
+ skip("Windows Python >= 2.6 only")
+ assert sys.dllhandle
+ assert sys.dllhandle.getaddressindll('cpyexttestErr_NewException')
+
class AppTestCpythonExtensionBase(LeakCheckingTest):
def setup_class(cls):
diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -108,6 +108,12 @@
# don't get the filesystemencoding at translation time
assert self.filesystemencoding is None
+ else:
+ if _WIN:
+ from pypy.module.sys import vm
+ w_handle = vm.get_dllhandle(space)
+ space.setitem(self.w_dict, space.wrap("dllhandle"), w_handle)
+
def getmodule(self, name):
space = self.space
w_modules = self.get('modules')
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -229,6 +229,26 @@
])
return space.call_function(w_windows_version_info, raw_version)
[email protected]_look_inside
+def get_dllhandle(space):
+ if not space.config.objspace.usemodules.cpyext:
+ return space.wrap(0)
+ if not space.config.objspace.usemodules._rawffi:
+ return space.wrap(0)
+
+ return _get_dllhandle(space)
+
+def _get_dllhandle(space):
+ # Retrieve cpyext api handle
+ from pypy.module.cpyext.api import State
+ handle = space.fromcache(State).get_pythonapi_handle()
+
+ # Make a dll object with it
+ from pypy.module._rawffi.interp_rawffi import W_CDLL
+ from rpython.rlib.clibffi import RawCDLL
+ cdll = RawCDLL(handle)
+ return space.wrap(W_CDLL(space, "python api", cdll))
+
def getsizeof(space, w_object, w_default=None):
"""Not implemented on PyPy."""
if w_default is None:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit