[Python-checkins] r65681 - in python/trunk: Lib/ctypes/__init__.py Lib/ctypes/test/test_memfunctions.py Misc/NEWS
thomas.heller
python-checkins at python.org
Thu Aug 14 21:10:48 CEST 2008
Author: thomas.heller
Date: Thu Aug 14 21:10:48 2008
New Revision: 65681
Log:
issue #3554: ctypes.string_at and ctypes.wstring_at must use the
pythonapi calling convention so that the GIL is held and error return
values are checked.
Modified:
python/trunk/Lib/ctypes/__init__.py
python/trunk/Lib/ctypes/test/test_memfunctions.py
python/trunk/Misc/NEWS
Modified: python/trunk/Lib/ctypes/__init__.py
==============================================================================
--- python/trunk/Lib/ctypes/__init__.py (original)
+++ python/trunk/Lib/ctypes/__init__.py Thu Aug 14 21:10:48 2008
@@ -488,7 +488,7 @@
def cast(obj, typ):
return _cast(obj, obj, typ)
-_string_at = CFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
+_string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
def string_at(ptr, size=-1):
"""string_at(addr[, size]) -> string
@@ -500,7 +500,7 @@
except ImportError:
pass
else:
- _wstring_at = CFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
+ _wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
def wstring_at(ptr, size=-1):
"""wstring_at(addr[, size]) -> string
Modified: python/trunk/Lib/ctypes/test/test_memfunctions.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_memfunctions.py (original)
+++ python/trunk/Lib/ctypes/test/test_memfunctions.py Thu Aug 14 21:10:48 2008
@@ -3,6 +3,17 @@
from ctypes import *
class MemFunctionsTest(unittest.TestCase):
+ def test_overflow(self):
+ # string_at and wstring_at must use the Python calling
+ # convention (which acquires the GIL and checks the Python
+ # error flag). Provoke an error and catch it; see also issue
+ # #3554: <http://bugs.python.org/issue3554>
+ if hasattr(sys, "maxsize"):
+ self.assertRaises((OverflowError, MemoryError),
+ lambda: wstring_at(u"foo", sys.maxsize))
+ self.assertRaises((OverflowError, MemoryError),
+ lambda: string_at("foo", sys.maxsize))
+
def test_memmove(self):
# large buffers apparently increase the chance that the memory
# is allocated in high address space.
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Thu Aug 14 21:10:48 2008
@@ -199,6 +199,10 @@
Library
-------
+- Issue #3554: ctypes.string_at and ctypes.wstring_at did call Python
+ api functions without holding the GIL, which could lead to a fatal
+ error when they failed.
+
- Issue #799428: Fix Tkinter.Misc._nametowidget to unwrap Tcl command objects.
- Issue #3395: fix reference in test_multiprocessing to old debugInfo method
More information about the Python-checkins
mailing list