-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-39608: Derive command_lengths from command_array at compile time #5076
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
Open
keeper
wants to merge
1
commit into
MariaDB:main
Choose a base branch
from
keeper:command-lengths-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+10
−14
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ | |
| #include "sql_audit.h" | ||
| #include "password.h" | ||
| #include "scope.h" | ||
| #include <array> | ||
|
|
||
| #include "sql_plugin_compat.h" | ||
| #include "wsrep_mysqld.h" | ||
|
|
@@ -9419,7 +9420,7 @@ static void add_user_parameters(THD *thd, String *result, ACL_USER* acl_user, | |
| } | ||
| } | ||
|
|
||
| static const char *command_array[]= | ||
| static constexpr const char *command_array[]= | ||
| { | ||
| "SELECT", "INSERT", "UPDATE", "DELETE", "CREATE", "DROP", "RELOAD", | ||
| "SHUTDOWN", "PROCESS","FILE", "GRANT", "REFERENCES", "INDEX", | ||
|
|
@@ -9432,23 +9433,18 @@ static const char *command_array[]= | |
| "BINLOG REPLAY", "SLAVE MONITOR", "SHOW CREATE ROUTINE" | ||
| }; | ||
|
|
||
| static uint command_lengths[]= | ||
| { | ||
| 6, 6, 6, 6, 6, 4, 6, | ||
| 8, 7, 4, 5, 10, 5, | ||
| 5, 14, 5, 23, | ||
| 11, 7, 17, 14, | ||
| 11, 9, 14, 13, | ||
| 11, 5, 7, 17, 14, | ||
| 8, 15, 16, 15, | ||
| 23, 24, 12, | ||
| 13, 13, 19 | ||
| }; | ||
| static constexpr auto command_lengths= []() constexpr { | ||
| std::array<uint32_t, std::size(command_array)> lengths{}; | ||
| for (size_t i= 0; i < lengths.size(); i++) | ||
| lengths[i]= static_cast<uint32_t>( | ||
| std::char_traits<char>::length(command_array[i])); | ||
| return lengths; | ||
| }(); | ||
|
|
||
|
|
||
| static_assert(array_elements(command_array) == PRIVILEGE_T_MAX_BIT + 1, | ||
| "The definition of command_array does not match privilege_t"); | ||
| static_assert(array_elements(command_lengths) == PRIVILEGE_T_MAX_BIT + 1, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you are generating this there's no need for assert. Please remove it. |
||
| static_assert(command_lengths.size() == PRIVILEGE_T_MAX_BIT + 1, | ||
| "The definition of command_lengths does not match privilege_t"); | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 original code used the
uinttype for the elements ofcommand_lengths. Usinguint32_there introduces an inconsistency with the rest of the file and thecommand_arraylogic. It is better to useuintto maintain consistency and avoid potential type mismatch warnings in other parts of the code that consume this array. Additionally, usingarray_elements(command_array)instead ofstd::size(command_array)is more consistent with the existing codebase style and thestatic_asserton line 9445.References
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'd agree with gemini here: please use the base type.
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 intentionally switch to
uint32_tbecause this jira:https://jira.mariadb.org/browse/MDEV-35460
For std::size(), AFAIK MariaDB is moving toward C++17 and
array_elements()is not type-safe, that's why I choose modernstd::size(). So I'm curious about the preferred approach here: should style modernization (like uint32_t, std::size()) happen opportunistically in related refactors, or strictly in dedicated PRs?I understand it's a different topic so I'm ok with reverting — just wondering what the approach is for phasing in C++17 idioms.