Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6bb7eb

Browse files
committed
Issue #23765: Removed IsBadStringPtr calls in ctypes
1 parent 632a77e commit e6bb7eb

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

Lib/ctypes/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,8 @@ class c_char(_SimpleCData):
237237

238238
class c_char_p(_SimpleCData):
239239
_type_ = "z"
240-
if _os.name == "nt":
241-
def __repr__(self):
242-
if not windll.kernel32.IsBadStringPtrA(self, -1):
243-
return "%s(%r)" % (self.__class__.__name__, self.value)
244-
return "%s(%s)" % (self.__class__.__name__, cast(self, c_void_p).value)
245-
else:
246-
def __repr__(self):
247-
return "%s(%s)" % (self.__class__.__name__, cast(self, c_void_p).value)
240+
def __repr__(self):
241+
return "%s(%s)" % (self.__class__.__name__, c_void_p.from_buffer(self).value)
248242
_check_size(c_char_p, "P")
249243

250244
class c_void_p(_SimpleCData):
@@ -259,6 +253,8 @@ class c_bool(_SimpleCData):
259253

260254
class c_wchar_p(_SimpleCData):
261255
_type_ = "Z"
256+
def __repr__(self):
257+
return "%s(%s)" % (self.__class__.__name__, c_void_p.from_buffer(self).value)
262258

263259
class c_wchar(_SimpleCData):
264260
_type_ = "u"

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Core and Builtins
3030
Library
3131
-------
3232

33+
- Issue #23765: Removed IsBadStringPtr calls in ctypes
34+
3335
- Issue #22364: Improved some re error messages using regex for hints.
3436

3537
- Issue #23742: ntpath.expandvars() no longer loses unbalanced single quotes.

0 commit comments

Comments
 (0)