Author: Armin Rigo <[email protected]>
Branch:
Changeset: r72281:f65f69804dfc
Date: 2014-06-30 09:16 +0200
http://bitbucket.org/pypy/pypy/changeset/f65f69804dfc/
Log: Merge disable_pythonapi by matti, which disables the buggy
"ctypes.pythnonapi" and updates the docs.
diff --git a/lib-python/2.7/ctypes/__init__.py
b/lib-python/2.7/ctypes/__init__.py
--- a/lib-python/2.7/ctypes/__init__.py
+++ b/lib-python/2.7/ctypes/__init__.py
@@ -389,12 +389,13 @@
func.__name__ = name_or_ordinal
return func
-class PyDLL(CDLL):
- """This class represents the Python library itself. It allows to
- access Python API functions. The GIL is not released, and
- Python exceptions are handled correctly.
- """
- _func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
+# Not in PyPy
+#class PyDLL(CDLL):
+# """This class represents the Python library itself. It allows to
+# access Python API functions. The GIL is not released, and
+# Python exceptions are handled correctly.
+# """
+# _func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
if _os.name in ("nt", "ce"):
@@ -447,15 +448,8 @@
return self._dlltype(name)
cdll = LibraryLoader(CDLL)
-pydll = LibraryLoader(PyDLL)
-
-if _os.name in ("nt", "ce"):
- pythonapi = PyDLL("python dll", None, _sys.dllhandle)
-elif _sys.platform == "cygwin":
- pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2])
-else:
- pythonapi = PyDLL(None)
-
+# not on PyPy
+#pydll = LibraryLoader(PyDLL)
if _os.name in ("nt", "ce"):
windll = LibraryLoader(WinDLL)
diff --git a/lib-python/2.7/ctypes/test/test_values.py
b/lib-python/2.7/ctypes/test/test_values.py
--- a/lib-python/2.7/ctypes/test/test_values.py
+++ b/lib-python/2.7/ctypes/test/test_values.py
@@ -4,6 +4,7 @@
import unittest
from ctypes import *
+from ctypes.test import xfail
import _ctypes_test
@@ -23,7 +24,8 @@
class Win_ValuesTestCase(unittest.TestCase):
"""This test only works when python itself is a dll/shared library"""
-
+
+ @xfail
def test_optimizeflag(self):
# This test accesses the Py_OptimizeFlag intger, which is
# exported by the Python dll.
@@ -40,6 +42,7 @@
else:
self.assertEqual(opt, 2)
+ @xfail
def test_frozentable(self):
# Python exports a PyImport_FrozenModules symbol. This is a
# pointer to an array of struct _frozen entries. The end of the
@@ -75,6 +78,7 @@
from ctypes import _pointer_type_cache
del _pointer_type_cache[struct_frozen]
+ @xfail
def test_undefined(self):
self.assertRaises(ValueError, c_int.in_dll, pydll,
"Undefined_Symbol")
diff --git a/pypy/doc/ctypes-implementation.rst
b/pypy/doc/ctypes-implementation.rst
--- a/pypy/doc/ctypes-implementation.rst
+++ b/pypy/doc/ctypes-implementation.rst
@@ -72,13 +72,11 @@
Here is a list of the limitations and missing features of the
current implementation:
-* ``ctypes.pythonapi`` lets you access the CPython C API emulation layer
- of PyPy, at your own risks and without doing anything sensible about
- the GIL. Since PyPy 2.3, these functions are also named with an extra
- "Py", for example ``PyPyInt_FromLong()``. Basically, don't use this,
- but it might more or less work in simple cases if you do. (Obviously,
- assuming the PyObject pointers you get have any particular fields in
- any particular order is just going to crash.)
+* ``ctypes.pythonapi`` is missing. In previous versions, it was present
+ and redirected to the `cpyext` C API emulation layer, but our
+ implementation did not do anything sensible about the GIL and the
+ functions were named with an extra "Py", for example
+ ``PyPyInt_FromLong()``. It was removed for being unhelpful.
* We copy Python strings instead of having pointers to raw buffers
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -43,3 +43,7 @@
.. branch: jit-get-errno
Optimize the errno handling in the JIT, notably around external
function calls. Linux-only.
+
+.. branch: disable_pythonapi
+Remove non-functioning ctypes.pyhonapi and ctypes.PyDLL, document this
+incompatibility with cpython. Recast sys.dllhandle to an int.
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
@@ -205,12 +205,7 @@
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('PyPyErr_NewException')
- import ctypes # slow
- PyUnicode_GetDefaultEncoding =
ctypes.pythonapi.PyPyUnicode_GetDefaultEncoding
- PyUnicode_GetDefaultEncoding.restype = ctypes.c_char_p
- assert PyUnicode_GetDefaultEncoding() == 'ascii'
+ assert isinstance(sys.dllhandle, int)
class AppTestCpythonExtensionBase(LeakCheckingTest):
diff --git a/pypy/module/sys/test/test_sysmodule.py
b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -391,7 +391,8 @@
import sys
if hasattr(sys, "getwindowsversion"):
v = sys.getwindowsversion()
- assert isinstance(v, tuple)
+ if '__pypy__' in sys.builtin_module_names:
+ assert isinstance(v, tuple)
assert len(v) == 5
assert isinstance(v[0], int)
assert isinstance(v[1], int)
@@ -419,6 +420,10 @@
if hasattr(sys, "winver"):
assert sys.winver == sys.version[:3]
+ def test_dllhandle(self):
+ import sys
+ assert hasattr(sys, 'dllhandle') == (sys.platform == 'win32')
+
def test_dlopenflags(self):
import sys
if hasattr(sys, "setdlopenflags"):
@@ -486,7 +491,8 @@
assert isinstance(sys.version, basestring)
assert isinstance(sys.warnoptions, list)
vi = sys.version_info
- assert isinstance(vi, tuple)
+ if '__pypy__' in sys.builtin_module_names:
+ assert isinstance(vi, tuple)
assert len(vi) == 5
assert isinstance(vi[0], int)
assert isinstance(vi[1], int)
@@ -512,6 +518,8 @@
def test_pypy_attributes(self):
import sys
+ if '__pypy__' not in sys.builtin_module_names:
+ skip("only on PyPy")
assert isinstance(sys.pypy_objspaceclass, str)
vi = sys.pypy_version_info
assert isinstance(vi, tuple)
@@ -528,10 +536,14 @@
def test_subversion(self):
import sys
+ if '__pypy__' not in sys.builtin_module_names:
+ skip("only on PyPy")
assert sys.subversion == ('PyPy', '', '')
def test__mercurial(self):
import sys, re
+ if '__pypy__' not in sys.builtin_module_names:
+ skip("only on PyPy")
project, hgtag, hgid = sys._mercurial
assert project == 'PyPy'
# the tag or branch may be anything, including the empty string
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
@@ -233,8 +233,6 @@
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)
@@ -243,11 +241,14 @@
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))
+ # It used to be a CDLL
+ # 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))
+ # Provide a cpython-compatible int
+ from rpython.rtyper.lltypesystem import lltype, rffi
+ return space.wrap(rffi.cast(lltype.Signed, handle))
def getsizeof(space, w_object, w_default=None):
"""Not implemented on PyPy."""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit