]> granicus.if.org Git - python/commitdiff
Fix for SF# 1701409: segfault in c_char_p of ctypes. The repr output
authorThomas Heller <theller@ctypes.org>
Fri, 13 Jul 2007 17:07:55 +0000 (17:07 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 13 Jul 2007 17:07:55 +0000 (17:07 +0000)
of c_char_p and c_wchar_p has changed as a sideeffect.

Lib/ctypes/__init__.py
Misc/NEWS

index 5937304495636dd6695c73caf38536a3b9ee438f..7b5f7482e60052c466a7fde256a449f167689a93 100644 (file)
@@ -226,6 +226,14 @@ _check_size(c_char)
 
 class c_char_p(_SimpleCData):
     _type_ = "z"
+    if _os.name == "nt":
+        def __repr__(self):
+            if not windll.kernel32.IsBadStringPtrA(self, -1):
+                return "%s(%r)" % (self.__class__.__name__, self.value)
+            return "%s(%s)" % (self.__class__.__name__, cast(self, c_void_p).value)
+    else:
+        def __repr__(self):
+            return "%s(%s)" % (self.__class__.__name__, cast(self, c_void_p).value)
 _check_size(c_char_p, "P")
 
 class c_void_p(_SimpleCData):
index c75b2f27083d81d415af8a7296943a97870875af..c873f46fd9940f5a2a8e1c40f44f81dd43cbfc1d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -26,6 +26,10 @@ Core and builtins
 Library
 -------
 
+- Bug #1701409: Fix a segfault in printing ctypes.c_char_p and
+  ctypes.c_wchar_p when they point to an invalid location.  As a
+  sideeffect the representation of these instances has changed.
+
 - Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute.
 
 - Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it