-
Notifications
You must be signed in to change notification settings - Fork 142
Cleanup includes #515
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
base: main
Are you sure you want to change the base?
Cleanup includes #515
Conversation
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ast.hpp и неиспользуемые include из Result.hpp - Удален #include <bit> из include/rfl/internal/ptr_cast.hpp (не используется в коде) - Удалены неиспользуемые include из include/rfl/Result.hpp: - #include <algorithm> (не используется) - #include <iostream> (не используется) - #include <optional> (не используется)
Этап 2: Базовые типы (средний риск) Удалены неиспользуемые include из файла Tuple.hpp: - <algorithm> - не используется в коде - <bit> - не используется в коде - <cstdint> - не используется в коде - <limits> - не используется в коде - <memory> - не используется в коде - <optional> - не используется в коде Оставлены только необходимые заголовки: - <array> - используется для std::array - <tuple> - используется для std::tuple - <type_traits> - используется для различных type traits - <utility> - используется для std::integer_sequence и других утилит Все остальные файлы (Literal.hpp, Field.hpp, Object.hpp, Variant.hpp) уже имели оптимальный набор include файлов без неиспользуемых зависимостей. Компиляция проекта проверена и проходит успешно.
…вки <string>, <version>, упрощен оператор сравнения spaceship
unused arguments shaded variables
Summary of ChangesHello @KostinPavel, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a comprehensive cleanup and enhancement of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This is a great cleanup pull request that improves code hygiene by removing unused includes and strengthens the build process with more compiler warnings and clang-tidy
integration. The added error and null checks in rfl/avro/Writer.hpp
are very important for robustness. However, I've found some critical issues with the current error handling within noexcept
functions, which could lead to silent data corruption or loss. I've left specific comments on these areas. I've also made a suggestion to improve the std::hash
specialization for rfl::Ref
. Lastly, I noticed several headers are commented out (e.g., //#include ...
). If these are no longer needed, it would be cleaner to remove them entirely. If they are needed for specific build configurations, using preprocessor guards (#ifdef ...
) would be a more robust solution.
int result = avro_value_append(&_parent->val_, &new_value, nullptr); | ||
if (result != 0) { | ||
return OutputVarType{_parent->val_}; | ||
} |
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 error handling for avro_value_append
appears to be incorrect. When result != 0
, an error has occurred, but the function returns OutputVarType{_parent->val_}
. This returns the parent container as if it were the newly added value, which is misleading and can lead to silent data corruption. The caller has no way of knowing that the append operation failed because the function is marked noexcept
.
This pattern is repeated in add_value_to_map
, add_value_to_object
, and add_value_to_union
.
A noexcept
function that encounters an error it cannot handle should either terminate (e.g., std::terminate()
) or have a mechanism to signal the error state to the caller without exceptions. Simply returning an incorrect value silently is dangerous.
Consider changing the write
pipeline to propagate errors, perhaps by removing noexcept
and returning a rfl::Result
. If noexcept
must be preserved, the Writer
could maintain an internal error state that can be checked after the write operation is complete.
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.
what code will solve the problem?
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.
@KostinPavel , handling these errors properly would require us to get rid of all of the noexcept and start throwing exceptions. It would make sense in my view, because these would truly be exceptional circumstances (such as running out of disc space or memory).
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.
Are exceptions allowed?
example: throw std::runtime_error(std::format("avro_value_append error: {:s}", avro_strerror()));
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.
@KostinPavel , sure. Just remove all the noexcepts so this won't result in a crash.
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.
@KostinPavel , by the way, I am not sure that std::format is supported by all the compiler versions we test for. I think some of the older versions don't support it yet.
include/rfl/avro/Writer.hpp
Outdated
const char* cstr = _var.c_str(); | ||
if (!cstr) { | ||
return; | ||
} | ||
avro_value_set_string_len(_val, cstr, _var.size() + 1); |
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 null check for _var.c_str()
results in a silent return, causing data to be dropped without any notification to the caller. This can lead to silent data loss, which can be very difficult to debug. The same issue exists for rfl::Bytestring
and rfl::Vectorstring
on lines 206-208.
Since this function is noexcept
, you cannot throw an exception. Consider one of the following approaches:
- Change the
write
pipeline to allow for error propagation (e.g., by removingnoexcept
and returningrfl::Result
). - If
noexcept
is a hard requirement, have theWriter
class maintain an error state that can be checked after the operation. - As a last resort, log the error before returning to make the silent failure observable.
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.
@KostinPavel , why do we need this check? How would std::string.c_str() ever be a nullptr?
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.
Its my bug.
No, checking for nullptr in this line is not necessary. That's why:
Guarantees of std::string::c_str():
The c_str() method for non-null std::string always returns a valid pointer to a null-terminated string.
Even for an empty string, c_str() returns a pointer to a valid null byte ('\0'), not nullptr.
Compilation condition:
The code is executed only when T is std::string (checking std::is_same<std::remove_cvref_t, std::string>())
This ensures that _var is indeed an std::string and has a valid c_str()
@KostinPavel , excellent work, thank you so much! |
This is for everyone's benefit. I just removed the unnecessary stuff. I didn't ruin anything. We're all waiting for C++26. |
@KostinPavel , yeah, when C++ 26 is out, I will refactor this library to support both the C++ 26 reflection features, but continue supporting the old C++ 20 approaches. |
No description provided.