[Python-checkins] r54246 - in python/branches/release25-maint: Lib/ctypes Lib/ctypes/__init__.py Lib/ctypes/test/test_memfunctions.py Misc/NEWS Modules/_ctypes Modules/_ctypes/_ctypes.c

thomas.heller python-checkins at python.org
Fri Mar 9 21:21:20 CET 2007


Author: thomas.heller
Date: Fri Mar  9 21:21:16 2007
New Revision: 54246

Modified:
   python/branches/release25-maint/Lib/ctypes/   (props changed)
   python/branches/release25-maint/Lib/ctypes/__init__.py
   python/branches/release25-maint/Lib/ctypes/test/test_memfunctions.py
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Modules/_ctypes/   (props changed)
   python/branches/release25-maint/Modules/_ctypes/_ctypes.c
Log:
Merged revisions 54244 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk/Lib/ctypes

........
  r54244 | thomas.heller | 2007-03-09 20:21:28 +0100 (Fr, 09 Mär 2007) | 3 lines
  
  Fix bug #1646630: ctypes.string_at(buf, 0) and ctypes.wstring_at(buf, 0)
  returned string up to the first NUL character.
........


Modified: python/branches/release25-maint/Lib/ctypes/__init__.py
==============================================================================
--- python/branches/release25-maint/Lib/ctypes/__init__.py	(original)
+++ python/branches/release25-maint/Lib/ctypes/__init__.py	Fri Mar  9 21:21:16 2007
@@ -478,7 +478,7 @@
     return _cast(obj, obj, typ)
 
 _string_at = CFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
-def string_at(ptr, size=0):
+def string_at(ptr, size=-1):
     """string_at(addr[, size]) -> string
 
     Return the string at addr."""
@@ -490,7 +490,7 @@
     pass
 else:
     _wstring_at = CFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
-    def wstring_at(ptr, size=0):
+    def wstring_at(ptr, size=-1):
         """wstring_at(addr[, size]) -> string
 
         Return the string at addr."""

Modified: python/branches/release25-maint/Lib/ctypes/test/test_memfunctions.py
==============================================================================
--- python/branches/release25-maint/Lib/ctypes/test/test_memfunctions.py	(original)
+++ python/branches/release25-maint/Lib/ctypes/test/test_memfunctions.py	Fri Mar  9 21:21:16 2007
@@ -14,6 +14,7 @@
         self.failUnlessEqual(string_at(result), "Hello, World")
         self.failUnlessEqual(string_at(result, 5), "Hello")
         self.failUnlessEqual(string_at(result, 16), "Hello, World\0\0\0\0")
+        self.failUnlessEqual(string_at(result, 0), "")
 
     def test_memset(self):
         a = create_string_buffer(1000000)
@@ -54,6 +55,7 @@
             self.failUnlessEqual(wstring_at(a), "Hello, World")
             self.failUnlessEqual(wstring_at(a, 5), "Hello")
             self.failUnlessEqual(wstring_at(a, 16), "Hello, World\0\0\0\0")
+            self.failUnlessEqual(wstring_at(a, 0), "")
 
 if __name__ == "__main__":
     unittest.main()

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Fri Mar  9 21:21:16 2007
@@ -197,6 +197,9 @@
 Library
 -------
 
+- Fix bug #1646630: ctypes.string_at(buf, 0) and ctypes.wstring_at(buf, 0)
+  returned string up to the first NUL character.
+
 - Bug #1637850:  make_table in difflib did not work with unicode
 
 - Bugs #1676321:  the empty() function in sched.py returned the wrong result

Modified: python/branches/release25-maint/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/release25-maint/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/release25-maint/Modules/_ctypes/_ctypes.c	Fri Mar  9 21:21:16 2007
@@ -4531,9 +4531,9 @@
 #endif
 
 static PyObject *
-string_at(const char *ptr, Py_ssize_t size)
+string_at(const char *ptr, int size)
 {
-	if (size == 0)
+	if (size == -1)
 		return PyString_FromString(ptr);
 	return PyString_FromStringAndSize(ptr, size);
 }
@@ -4618,7 +4618,7 @@
 static PyObject *
 wstring_at(const wchar_t *ptr, int size)
 {
-	if (size == 0)
+	if (size == -1)
 		size = wcslen(ptr);
 	return PyUnicode_FromWideChar(ptr, size);
 }


More information about the Python-checkins mailing list