-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
ports/unix/modffi: Fix signed integer cast in return_ffi_value. #15767
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #15767 +/- ##
=======================================
Coverage 98.43% 98.43%
=======================================
Files 163 163
Lines 21294 21294
=======================================
Hits 20960 20960
Misses 334 334 ☔ View full report in Codecov by Sentry. |
|
Code size report: |
Casting an ffi_arg to a signed int may truncate the value. E.g., when the ffi_arg is 64-bit and the signed int is 32-bit. Also, casting an ffi_arg to a larger signed type will not sign extend the value. E.g., when the ffi_arg is 32-bit and the larger signed type is int64_t. If the value is signed, it should be cast to ffi_sarg, which is the same size as ffi_arg. Signed-off-by: Michael Sawyer <mjfsawyer@gmail.com>
Added the "long" modffi tests. The tests could not be added to the existing ffi_types test because two .exp files were required for the 32-bit and 64-bit results. Code common to both the ffi_types and type "long" tests was factored into ffi_int_base. ffi_types was renamed to ffi_int_types to group the related tests under the "ffi_int" prefix. Signed-off-by: Michael Sawyer <mjfsawyer@gmail.com>
projectgus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very good to me, especially the additional test coverage. Thanks, @mchlswyr!
dpgeorge
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
Summary
This PR builds on #7358. In
return_ffi_value, integers of typechar,short, andlongare cast to typeint. In an x86-64 Linux build,longis 64-bit andintis 32-bit, so the value is truncated.Testing
I added some
longtests. The tests could not be added to the existing ffi_types test because two .exp files were required for the 32-bit and 64-bit results. Code common to both the ffi_types andlongtests was factored into ffi_int_base. ffi_types was renamed to ffi_int_types to group the related tests under the "ffi_int" prefix.I ran the tests in the following four cases:
MICROPY_FORCE_32BIT=0: ffi_int_long64 will fail;MICROPY_FORCE_32BIT=1: all tests will pass or skip;MICROPY_FORCE_32BIT=0: all tests will pass or skip;MICROPY_FORCE_32BIT=1: all tests will pass or skip.