]> granicus.if.org Git - python/commitdiff
Adds c_ssize_t to ctypes. issue 6729.
authorGregory P. Smith <greg@mad-scientist.com>
Mon, 1 Mar 2010 04:56:12 +0000 (04:56 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Mon, 1 Mar 2010 04:56:12 +0000 (04:56 +0000)
Doc/library/ctypes.rst
Lib/ctypes/__init__.py
Lib/ctypes/test/test_sizes.py
Misc/NEWS

index 582300c28c4124933e7f1805cc6facc97257466e..631a0fb1759daaedac76d03e6031ad691c0fe182 100644 (file)
@@ -2248,6 +2248,13 @@ These are the fundamental ctypes data types:
    Represents the C :ctype:`size_t` datatype.
 
 
+.. class:: c_ssize_t
+
+   Represents the C :ctype:`ssize_t` datatype.
+
+   .. versionadded:: 2.7
+
+
 .. class:: c_ubyte
 
    Represents the C :ctype:`unsigned char` datatype, it interprets the value as
index 1b0383564e7c861daa2dd4829c8cfbf2cbe1f5bb..16489b953498b6253954effecd2a14c736baa361 100644 (file)
@@ -462,10 +462,13 @@ _pointer_type_cache[None] = c_void_p
 
 if sizeof(c_uint) == sizeof(c_void_p):
     c_size_t = c_uint
+    c_ssize_t = c_int
 elif sizeof(c_ulong) == sizeof(c_void_p):
     c_size_t = c_ulong
+    c_ssize_t = c_long
 elif sizeof(c_ulonglong) == sizeof(c_void_p):
     c_size_t = c_ulonglong
+    c_ssize_t = c_longlong
 
 # functions
 
index 0509cbb68082f39b1c2d1faf2db9aa6b8f8c3e5c..f9b5e9726009e05146fe20390bb8d486fd649741 100644 (file)
@@ -1,8 +1,11 @@
 # Test specifically-sized containers.
 
-import unittest
 from ctypes import *
 
+import sys
+import unittest
+
+
 class SizesTestCase(unittest.TestCase):
     def test_8(self):
         self.assertEqual(1, sizeof(c_int8))
@@ -23,5 +26,9 @@ class SizesTestCase(unittest.TestCase):
     def test_size_t(self):
         self.assertEqual(sizeof(c_void_p), sizeof(c_size_t))
 
+    def test_ssize_t(self):
+        self.assertEqual(sizeof(c_void_p), sizeof(c_ssize_t))
+
+
 if __name__ == "__main__":
     unittest.main()
index 184c028f66f91e6793584b84375133639a4840de..b1105590af8ed4837d590b30636a1f3b2521dbb8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -78,6 +78,8 @@ Library
 - Issue #1068268: The subprocess module now handles EINTR in internal
   os.waitpid and os.read system calls where appropriate.
 
+- Issue #6729: Added ctypes.c_ssize_t to represent ssize_t.
+
 Extension Modules
 -----------------