From: Thomas Heller Date: Fri, 13 Jul 2007 17:12:23 +0000 (+0000) Subject: Fix for SF# 1701409: segfault in c_char_p of ctypes. The repr output X-Git-Tag: v2.6a1~1571 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa704c6adef703271844349bad94fbf7d09143d9;p=python Fix for SF# 1701409: segfault in c_char_p of ctypes. The repr output of c_char_p and c_wchar_p has changed as a sideeffect. --- diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index f8b2d75aba..7dff3a7de6 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -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): diff --git a/Misc/NEWS b/Misc/NEWS index b5cf34963e..aa023884d8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -234,6 +234,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. + - tarfile.py: Added "exclude" keyword argument to TarFile.add(). - Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute.