-
Notifications
You must be signed in to change notification settings - Fork 559
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
utf8n_to_uvchr_msgs(): Macroïze a common paradigm #22762
Conversation
utf8.c
Outdated
: ((msgs) \ | ||
/* Here are to return a warning message. Choose the \ | ||
* highest priority enabled category, or 'warning' \ | ||
* if neither is enabled */ \ | ||
? ((ckWARN_d(warning)) \ | ||
? warning \ | ||
: ((extra_ckWARN(extra_category) \ | ||
? extra_category \ | ||
: warning))) \ | ||
/* Here are to raise a warning if either category is \ | ||
* enabled. Return the highest priority enabled \ | ||
* one, or 0 if neither is enabled */ \ | ||
: ((ckWARN_d(warning) \ | ||
? warning \ | ||
: ((extra_ckWARN(extra_category) \ | ||
? extra_category \ | ||
: 0)))))) |
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.
Wouldn't this be simpler if you invert the order of checks (i.e. check msgs
on the inside)?
: ((ckWARN_d(warning)) \
? warning \
: ((extra_ckWARN(extra_category) \
? extra_category \
: (msgs) ? warning : 0)))) \
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.
Yes, I got fixated on checking msgs
first because it is cheaper than the function calls, and lost sight of the fact that that is irrelevant in this case because there is no possible path through the code that doesn't also have a function call
pack_warn = NEED_MESSAGE(WARN_UTF8, | ||
ckWARN_d, WARN_NON_UNICODE); |
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 is not the same logic. In the old version, if msgs
was true, ckWARN_d(WARN_UTF8)
false, ckWARN_d(WARN_NON_UNICODE)
true, we still used WARN_UTF8
. With the new macro, we now use WARN_NON_UNICODE
.
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.
Yes; it is a bug fix. I don't know why I thought it not necessary to point that out in the commit message. Now revised
858acff
to
45ab74e
Compare
I decided that the behavior change should be in a separate pull request, and so I created #22767 |
45ab74e
to
da8e8fa
Compare
da8e8fa
to
5870272
Compare
5870272
to
8f7d284
Compare
Each of the cases in the loop had a somewhat obscure conditional that had a few variants. This commit creates a macro that puts the complication in one place.
8f7d284
to
dbf5e7f
Compare
Each of the cases in the loop had a somewhat obscure conditional that had a few variants. This commit creates a macro that puts the complication in one place.
It also fixes a bug found by more robust test cases, yet to be committed. The function can either raise a warning (if appropriate) or pass the needed information about the warning back to the caller when the function parameters say to. The data for each should be identical, but prior to this commit, they weren't in one unlikely case.
This happened when the input UTF-8 sequence represents a code point whose value doesn't fit in the platform's word size. This is viewed as a malformation, and, if enabled, a warning using the WARN_UTF8 category is raised. But if disabled, another way to look at it is that this is an attempt to use a code point that isn't legal Unicode. There is another warnings category for that, WARN_NON_UNICODE. And, so a warning is raised if that category is enabled.
Note that WARN_NON_UNICODE is a subcategory of WARN_UTF8, so the only way to get to this situation is
(those two statements could be separated by many lines)
Prior to this commit, if the caller asked for the warning information to be passed to it instead of raising the warnings, WARN_NON_UNICODE never was returned, making the two modes sometimes inconsistent.
With this commit, WARN_NON_UNICODE is passed to the caller if (and only if) a warning would otherwise have been generated using it.