[MDEV-19784] C++11 protectors for my_error Created: 2019-06-17 Updated: 2023-11-28 |
|
| Status: | In Review |
| Project: | MariaDB Server |
| Component/s: | Compiling |
| Fix Version/s: | 10.11 |
| Type: | Task | Priority: | Minor |
| Reporter: | Nikita Malyavin | Assignee: | Sergei Golubchik |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
It is easy to pass wrong arguments in `my_error`: it is vararg, and not printf-like. 1. We can protect from LEX_CSTRING by implementing variadic template guard, forbidding, or implicitly converting some arguments by a sane set of rules, e.g.:
See also midenok's idea here: https://github.com/tempesta-tech/mariadb/issues/325 It will be still possible to pass int instead of char*, etc. 2. The above approach will reveal errors at runtime, and only for tested cases. We can do it in buildtime, although it will not cover all the cases when error code is determined at runtime:
When error code is dynamically resolved, it will fall back to dynamic check described above:
This implementation will break when const, but not constexpr, error code is passed. |
| Comments |
| Comment by Sergei Golubchik [ 2020-08-11 ] | |||||||||||
| |||||||||||
| Comment by Sergei Golubchik [ 2020-08-11 ] | |||||||||||
|
Another, less C++y option would be to use macros like
and this way the compiler can see the format string and can verify that parameters are correct | |||||||||||
| Comment by Nikita Malyavin [ 2020-11-04 ] | |||||||||||
|
serg
But I think I can generate both codes,
| |||||||||||
| Comment by Nikita Malyavin [ 2020-11-09 ] | |||||||||||
|
Turns out:
If we're forcing compile-time type checking. serg, (1) still doesn't mean we can't do C-compatible wrappers at all. I see following in service_my_print_error.h:
So probably my_error is defined separately for plugins, and for non-plugin case we can collect all the messages in one place, namely errmsg-utf8.txt (currently, error messages are stored in several places more in the code). | |||||||||||
| Comment by Nikita Malyavin [ 2020-11-17 ] | |||||||||||
|
serg please review patches on bb-10.5-nikita regarding this ticket |