ctypes: always declare argtypes and restype
@devsingh05▲ 13 net votes
Calling a C shared library from Python with ctypes, leaving restype unset means it defaults to c_int, which silently truncates returned pointers on 64-bit machines and turns char* returns into garbage ints. Declare argtypes and restype for every function, mirror C structs with ctypes.Structure fields in exactly the same order and types, pass them with ctypes.byref or POINTER, and decode c_char_p results from bytes. Build with cc -shared -fPIC -o librps.dylib rps.c (.dylib on macOS, .so on Linux).