Skip to content

Cleanup includes#518

Closed
KostinPavel wants to merge 15 commits into
getml:mainfrom
KostinPavel:cleanup-includes
Closed

Cleanup includes#518
KostinPavel wants to merge 15 commits into
getml:mainfrom
KostinPavel:cleanup-includes

Conversation

@KostinPavel
Copy link
Copy Markdown
Contributor

No description provided.

KostinPavel and others added 15 commits October 8, 2025 15:22
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
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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 undertakes a significant refactoring effort focused on optimizing include directives across the rfl library and its associated benchmarks and tests. The changes aim to reduce compilation overhead by removing unused headers, enhance code quality through static analysis configuration, and improve the robustness of the Avro serialization implementation with better error handling. Additionally, build configurations have been refined, and type safety measures have been introduced in the Cap'n Proto module.

Highlights

  • Static Analysis Configuration: A new .clang-tidy configuration file has been added to the repository, enabling static analysis checks with specific exclusions for misc-, modernize-, and readability- related warnings.
  • Build System Enhancements: The CMakeLists.txt file has been updated to enable CMAKE_EXPORT_COMPILE_COMMANDS and expand compile options for the reflectcpp target. This includes adding more stringent warnings (-Wpedantic, -Wshadow, -Wconversion) for Debug builds and defining NDEBUG for Release builds across different compilers.
  • Extensive Include Cleanup: Numerous unnecessary C++ standard library headers (e.g., <array>, <iostream>, <optional>, <type_traits>, <algorithm>, <tuple>, <vector>) have been removed from various rfl library headers, benchmark files, and test files. This significantly reduces compilation dependencies and improves build performance.
  • Improved Avro Error Handling: The Avro serialization module (rfl/avro/Reader.hpp and rfl/avro/Writer.hpp) now includes more robust error checking for Avro C API calls, ensuring that failures are properly reported through rfl::error or std::runtime_error.
  • Cap'n Proto Type Safety: A SafeSizeToUInt helper function has been introduced in src/rfl/capnproto/Writer.cpp to safely convert size_t values to unsigned int for Cap'n Proto API calls, preventing potential data loss or overflow issues.
  • JSON Schema Default Initializers: Struct members within rfl/json/schema/Type.hpp have been updated to use default initializers ({}), enhancing code consistency and preventing uninitialized member warnings.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great cleanup of unused #include directives, which significantly improves build times and code hygiene. The introduction of a .clang-tidy configuration is also a welcome addition for maintaining code quality.

Most importantly, you've added critical error handling to the Avro integration, which fixes several potential crashes and resource leaks. These are excellent and much-needed improvements.

I've found a couple of issues that should be addressed:

  • A resource leak in the Avro reader.
  • Leftover debugging print statements in the Avro writer.
  • A potential resource leak in the Avro writer.

Once these are fixed, this will be a fantastic contribution to the project. Great work!

Comment thread include/rfl/avro/read.hpp
Comment on lines 41 to +42
avro_value_decref(&root);
return error(std::string("Could not read root value: ") + avro_strerror());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This error path is missing a call to avro_reader_free(avro_reader), which will result in a resource leak if avro_generic_value_new fails.

    avro_reader_free(avro_reader);
    avro_value_decref(&root);
    return error(std::string("Could not read root value: ") + avro_strerror());

Comment on lines +193 to 266
void set_value(const T& _var, avro_value_t* _val) const {
std::cout << "[DEBUG] set_value called with type: " << typeid(T).name() << std::endl;

if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
std::cout << "[DEBUG] Processing std::string: " << _var << std::endl;
int result = avro_value_set_string_len(_val, _var.c_str(), _var.size() + 1);
if (result != 0) {
std::cout << "[DEBUG] avro_value_set_string_len failed with result: " << result << std::endl;
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
}
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Bytestring>() ||
std::is_same<std::remove_cvref_t<T>,
rfl::Vectorstring>()) {
auto var = _var;
avro_value_set_bytes(_val, var.data(), var.size());

if (!var.data()) {
std::cout << "[DEBUG] Bytestring/Vectorstring has no data" << std::endl;
return;
}
std::cout << "[DEBUG] Processing Bytestring/Vectorstring of size: " << var.size() << std::endl;
int result = avro_value_set_bytes(_val, var.data(), var.size());
if (result != 0) {
std::cout << "[DEBUG] avro_value_set_bytes failed with result: " << result << std::endl;
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
}
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
avro_value_set_boolean(_val, _var);

std::cout << "[DEBUG] Processing bool: " << _var << std::endl;
int result = avro_value_set_boolean(_val, _var);
if (result != 0) {
std::cout << "[DEBUG] avro_value_set_boolean failed with result: " << result << std::endl;
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
}
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
avro_value_set_double(_val, static_cast<double>(_var));

std::cout << "[DEBUG] Processing floating point: " << _var << std::endl;
int result = avro_value_set_double(_val, static_cast<double>(_var));
if (result != 0) {
std::cout << "[DEBUG] avro_value_set_double failed with result: " << result << std::endl;
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
}
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
avro_value_set_long(_val, static_cast<std::int64_t>(_var));

std::cout << "[DEBUG] Processing integral: " << _var << std::endl;
int result = avro_value_set_long(_val, static_cast<std::int64_t>(_var));
if (result != 0) {
std::cout << "[DEBUG] avro_value_set_long failed with result: " << result << std::endl;
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
}
} else if constexpr (internal::is_literal_v<T>) {
avro_value_set_enum(_val, static_cast<int>(_var.value()));

std::cout << "[DEBUG] Processing literal enum: " << static_cast<int>(_var.value()) << std::endl;
int result = avro_value_set_enum(_val, static_cast<int>(_var.value()));
if (result != 0) {
std::cout << "[DEBUG] avro_value_set_enum failed with result: " << result << std::endl;
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
}
} else if constexpr (internal::is_validator_v<T>) {
std::cout << "[DEBUG] Processing validator type" << std::endl;
// Для валидаторов используем внутреннее значение
using ValueType = std::remove_cvref_t<typename T::ReflectionType>;
const auto val = _var.value();
set_value<ValueType>(val, _val);
} else if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Timestamp<"%Y-%m-%d">>()) {
std::cout << "[DEBUG] Processing Timestamp" << std::endl;
// Конвертируем Timestamp в строку
const auto str = _var.to_string();
set_value<std::string>(str, _val);
} else if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Email>()) {
std::cout << "[DEBUG] Processing Email" << std::endl;
// Email является паттерном на базе std::string, используем внутреннее значение
const auto& str = static_cast<const std::string&>(_var);
set_value<std::string>(str, _val);
} else {
std::cout << "[DEBUG] Unsupported type reached: " << typeid(T).name() << std::endl;
static_assert(rfl::always_false_v<T>, "Unsupported type.");
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This function contains many std::cout statements for debugging. These should be removed from production code to avoid performance overhead and log spam.

const auto writer = Writer(&root);
int result = avro_generic_value_new(_schema.iface(), &root);
if (result != 0) {
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To be consistent with read.hpp and to avoid a potential resource leak, you should call avro_value_decref(&root) here before throwing the exception.

    avro_value_decref(&root);
    throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): "  + avro_strerror());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant