What is ctypes.create_string_buffer in Python?
Create mutable C char buffers in Python with ctypes.create_string_buffer, read them with value and raw, and pass them safely to C functions.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Create mutable C char buffers in Python with ctypes.create_string_buffer, read them with value and raw, and pass them safely to C functions.
ctypes.byref passes a cheap reference to a ctypes object so a C function can modify it. See examples, the offset argument and byref versus pointer.
ctypes.POINTER creates C pointer types in Python. See how it differs from pointer and byref, with runnable examples for NULL, structs and qsort.
ctypes.c_uint64 is the 64-bit unsigned integer type in Python, matching C uint64_t with a range up to 18,446,744,073,709,551,615. Use it for C arguments.
ctypes.c_uint32 is the 32-bit unsigned integer type in Python, matching C uint32_t with a range of 0 to 4,294,967,295. Use it for C arguments and structs.
ctypes.c_uint16 is the 16-bit unsigned integer type in Python, matching C uint16_t with a range of 0 to 65,535. Use it for C function arguments and structs.
ctypes.c_uint8 is the 8-bit unsigned integer type in Python, matching C uint8_t with a range of 0 to 255. Use it for bytes, flags and C function arguments.
c_int64 is the ctypes type for a 64-bit signed integer. See its range, why argtypes are required for large values and how to use it with C int64_t.
c_int32 is the ctypes type for a 32-bit signed integer. See its range, silent overflow and how to pass int32_t values to C functions.
c_int16 is the ctypes type for a 16-bit signed integer. See its range, wrap-around behaviour and how to pass int16_t values to C functions safely.
ctypes.c_int8 is Python's signed 8-bit integer type for C interop. See its range, wrap-around behaviour and how to pass int8_t values to C functions.
ctypes.c_ssize_t maps to the signed C ssize_t type. See how it returns byte counts and -1 errors from calls like read and write, with errno handling.
ctypes.c_size_t maps to the C size_t type. Learn its platform size, how it wraps, and how to use it for lengths and allocation sizes in C calls.
ctypes.c_void_p models a C void pointer as an integer address or None. See how to set restype, cast memory and free what C allocates.
ctypes.c_wchar_p maps to wchar_t pointers and converts Python strings automatically. See how to pass, return and buffer wide strings safely.
ctypes.c_char_p represents a C char * pointer to a NUL-terminated string. Its value is a Python bytes object or None, and it must not be used for writable buffers.
ctypes.c_bool is the ctypes data type for the C _Bool (bool) type. It converts between Python True/False and the 0/1 values C libraries expect.
ctypes.c_longdouble represents the C long double, whose size varies by platform. Learn the precision limits and how to keep extended precision.
ctypes.c_double is the ctypes type for the C double, a 64-bit IEEE 754 floating-point number. Its value is a Python float, used for C function arguments and results.
c_float is the ctypes type for the C float: a 32-bit single-precision number. See how to declare argtypes and restype and use byref and structures correctly.