[Python-checkins] cpython: Issue #23765: Removed IsBadStringPtr calls in ctypes

steve.dower python-checkins at python.org
Thu Mar 26 05:58:52 CET 2015


https://hg.python.org/cpython/rev/339d90983e29
changeset:   95208:339d90983e29
user:        Steve Dower <steve.dower at microsoft.com>
date:        Wed Mar 25 21:58:36 2015 -0700
summary:
  Issue #23765: Removed IsBadStringPtr calls in ctypes

files:
  Lib/ctypes/__init__.py |  12 ++++--------
  Misc/NEWS              |   2 ++
  2 files changed, 6 insertions(+), 8 deletions(-)


diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -237,14 +237,8 @@
 
 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)
+    def __repr__(self):
+        return "%s(%s)" % (self.__class__.__name__, c_void_p.from_buffer(self).value)
 _check_size(c_char_p, "P")
 
 class c_void_p(_SimpleCData):
@@ -259,6 +253,8 @@
 
 class c_wchar_p(_SimpleCData):
     _type_ = "Z"
+    def __repr__(self):
+        return "%s(%s)" % (self.__class__.__name__, c_void_p.from_buffer(self).value)
 
 class c_wchar(_SimpleCData):
     _type_ = "u"
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -30,6 +30,8 @@
 Library
 -------
 
+- Issue #23765: Removed IsBadStringPtr calls in ctypes
+
 - Issue #22364: Improved some re error messages using regex for hints.
 
 - Issue #23742: ntpath.expandvars() no longer loses unbalanced single quotes.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list