-
Notifications
You must be signed in to change notification settings - Fork 93
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
Support build cython codes with -Werror=strict-aliasing
#247
Conversation
WalkthroughThe update in Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (1)
- thriftpy2/protocol/cybin/cybin.pyx (4 hunks)
Additional comments: 1
thriftpy2/protocol/cybin/cybin.pyx (1)
- 5-5: The import of
memcpy
fromlibc.string
is correctly added to support the new approach for handling double values, aligning with the PR's objectives.
cdef int64_t v | ||
memcpy(&v, &val, 8) | ||
v = htobe64(v) |
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.
The use of memcpy
in write_double
correctly addresses the strict-aliasing violation by safely copying the double value. It's a good practice to add a brief comment explaining the reason behind using memcpy
here, for the benefit of future maintainers.
+ # Using memcpy to comply with strict-aliasing rules
memcpy(&v, &val, 8)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
cdef int64_t v | |
memcpy(&v, &val, 8) | |
v = htobe64(v) | |
cdef int64_t v | |
# Using memcpy to comply with strict-aliasing rules | |
memcpy(&v, &val, 8) | |
v = htobe64(v) |
memcpy(&double_value, &n, 8) | ||
return double_value |
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.
The use of memcpy
for handling T_DOUBLE
in c_read_val
is correctly implemented to avoid strict-aliasing violations. Consider adding a comment here as well, explaining the use of memcpy
for future code maintainers.
+ # Using memcpy to safely convert int64_t to double, adhering to strict-aliasing rules
memcpy(&double_value, &n, 8)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
memcpy(&double_value, &n, 8) | |
return double_value | |
# Using memcpy to safely convert int64_t to double, adhering to strict-aliasing rules | |
memcpy(&double_value, &n, 8) | |
return double_value |
The change itself compiles fine. I don't think much of the chatbot's ineffectual analysis though. |
Cython does not support using
*
operator to dereferencing a pointer, so the old code is using[0]
for this job. However, this usage can't be built with-Werror=strict-aliasing
, see #246 for details.In this PR, using
memcpy
to force cast adouble
to anint64_t
to do the job. This can be built on my machine with-Werror=strict-aliasing
.Hi @eli-schwartz can you help me test it on your machine?
Close #246
Summary by CodeRabbit