From 3c699d334a1f6f413326bd8a3cbcd1a7a4b4a93d Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Mon, 1 Mar 2010 04:56:12 +0000 Subject: [PATCH] Adds c_ssize_t to ctypes. issue 6729. --- Doc/library/ctypes.rst | 7 +++++++ Lib/ctypes/__init__.py | 3 +++ Lib/ctypes/test/test_sizes.py | 9 ++++++++- Misc/NEWS | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index 582300c28c4..631a0fb1759 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -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 diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index 1b0383564e7..16489b95349 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -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 diff --git a/Lib/ctypes/test/test_sizes.py b/Lib/ctypes/test/test_sizes.py index 0509cbb6808..f9b5e972600 100644 --- a/Lib/ctypes/test/test_sizes.py +++ b/Lib/ctypes/test/test_sizes.py @@ -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() diff --git a/Misc/NEWS b/Misc/NEWS index 184c028f66f..b1105590af8 100644 --- 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 -----------------