STINNER Victor <vstin...@python.org> added the comment:
Using strlen() seems to be as old as ctypes itself. -- I don't know which behavior is correct. It's a little bit strange that ctypes truncate the string at "\0". A "char" buffer can be an arbitrary array of bytes. It may be a binary format which doesn't use null byte as string terminator, but just to encode a 16-bit integer as two bytes. My attempt to understand the current behavior: https://github.com/python/cpython/pull/18419#pullrequestreview-355606890 "size = strlen(data);" instruction was added when the ctypes was added by this commit: commit d4c9320412177895f598a93d73a0e654db27c351 Author: Thomas Heller <thel...@ctypes.org> Date: Wed Mar 8 19:35:11 2006 +0000 Copy ctypes-0.9.9.4 sources from external into the trunk. Sadly, Thomas Heller no longer contributes to Python since 2011: https://blog.python.org/2011/04/thomas-heller-steps-down-as-ctypes.html The original project is hosted at: https://sourceforge.net/p/ctypes/code/ It seems like s_set() function was added between these source/cfield.c two versions: revision 1.116 date: 2006/03/15 20:35:55; author: theller; state: Exp; lines: +14 -4 PyString_FromFormat()b understands the C99 "z" qualifier on all platforms, in Python 2.5. Patch from Tim Peters, adapted to work with older Python versions. revision 1.115 date: 2006/03/03 20:17:15; author: theller; state: Exp; lines: +636 -279 Moving files from branch_1_0 to HEAD. Sadly, the commit message doesn't say much about the rationale. ---------- nosy: +vstinner _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39593> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com