-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improve Macro Safety and Casting Practices: remove trailing semicolon #11815
base: main
Are you sure you want to change the base?
Improve Macro Safety and Casting Practices: remove trailing semicolon #11815
Conversation
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
✅ Deploy Preview for meta-velox canceled.
|
abf09ef
to
cb49aa9
Compare
velox/tpch/gen/dbgen/build.cpp
Outdated
@@ -38,7 +38,7 @@ namespace facebook::velox::tpch::dbgen { | |||
#define V_STR(avg, seed, tgt) \ | |||
tpch_a_rnd((int)(avg * V_STR_LOW), (int)(avg * V_STR_HGH), seed, tgt) | |||
#define TEXT(avg, seed, tgt) \ | |||
dbg_text(tgt, (int)(avg * V_STR_LOW), (int)(avg * V_STR_HGH), seed) | |||
dbg_text(tgt, static_cast<int>((avg) * V_STR_LOW), static_cast<int>((avg) * V_STR_HGH), seed) |
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.
Please check if the casts are already addressed by the PRs that fix the C-syle casts (see open PRs for those).
Please also fix the prior macro that has the same issue for the avg
argument.
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.
Fixed the prior macro. I checked and some c style casts were resolved but these casts were not addressed.
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.
I believe this file changes can be removed since it looks like it has been done in this PR
https://github.com/facebookincubator/velox/pull/11688/files
@anandamideShakyan Please provide a description (see guidelines in contributing). In the description also mention cleanup of semicolons. Also please squash commits and provide a better abstract than copying the name from the internal issue. |
dfc3ab8
to
e46bab0
Compare
velox/tpch/gen/dbgen/build.cpp
Outdated
@@ -38,7 +38,7 @@ namespace facebook::velox::tpch::dbgen { | |||
#define V_STR(avg, seed, tgt) \ | |||
tpch_a_rnd((int)(avg * V_STR_LOW), (int)(avg * V_STR_HGH), seed, tgt) | |||
#define TEXT(avg, seed, tgt) \ | |||
dbg_text(tgt, (int)(avg * V_STR_LOW), (int)(avg * V_STR_HGH), seed) | |||
dbg_text(tgt, static_cast<int>((avg) * V_STR_LOW), static_cast<int>((avg) * V_STR_HGH), seed) |
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.
I believe this file changes can be removed since it looks like it has been done in this PR
https://github.com/facebookincubator/velox/pull/11688/files
8a10393
to
186f320
Compare
@jkhaliqi done. |
PR Description:
This pull request addresses two macro-related issues found in velox/tpch/gen/dbgen/build.cpp and velox/common/base/SpillStats.cpp to improve code correctness and maintainability:
1. Add Parentheses Around Macro Parameters (velox/tpch/gen/dbgen/build.cpp)
Issue: The TEXT macro uses parameters like avg without parentheses, which can lead to incorrect results if the parameter is an expression. For example:
If avg is replaced with an expression (e.g., a + b), the result would be incorrect due to operator precedence:
TEXT(a + b, seed, tgt) // Expands to dbg_text(tgt, (int)(a + b * V_STR_LOW), ...)
Fix: Wrap macro parameters in parentheses to ensure correct precedence and behavior:
We are also replacing (int) C style casts with a static_cast as it ensures safer, clearer, and more maintainable type conversions by enforcing explicit and compile-time-checked behavior.
2. Remove Trailing Semicolon in Macro Definition (velox/common/base/SpillStats.cpp)
Issue: The UPDATE_COUNTER macro ends with a semicolon after the while (0) block:
This results in double semicolons (;;) when the macro is used:
UPDATE_COUNTER(someCounter); // Expands to: do { ... } while (0);;
Fix: Remove the trailing semicolon in the macro definition:
These fixes enhance code safety and eliminate potential pitfalls in macro usage.