Message361690
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 <theller@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. |
|
| Date |
User |
Action |
Args |
| 2020-02-10 12:57:06 | vstinner | set | recipients:
+ vstinner, shihai1991 |
| 2020-02-10 12:57:06 | vstinner | set | messageid: <1581339426.41.0.323615293452.issue39593@roundup.psfhosted.org> |
| 2020-02-10 12:57:06 | vstinner | link | issue39593 messages |
| 2020-02-10 12:57:06 | vstinner | create | |
|