New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctypes s_set() uses strlen() and so truncates string at null character #83774
Comments
strlen(data) can not be replaced by Py_SIZE(value) in https://github.com/python/cpython/blob/master/Modules/_ctypes/cfield.c#L1297. victor have give a great example about it in #18419 I create this bpo for two reasons:
|
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: "size = strlen(data);" instruction was added when the ctypes was added by this commit: commit d4c9320
Sadly, Thomas Heller no longer contributes to Python since 2011: The original project is hosted at: It seems like s_set() function was added between these source/cfield.c two versions: revision 1.116 revision 1.115 Sadly, the commit message doesn't say much about the rationale. |
releated bpo: bpo-12769 s_get() in cfield.c function have similar behavior. So far, this is a planned action(lack evidence). |
I am not sure it have realtion of libffi's type or not?
REF: https://www.manpagez.com/info/libffi/libffi-3.0.13/libffi_6.php#index-ffi_005ftype_005fpointer |
I guess the |
Thanks Hai Shi. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: