refactor: Refactor CompileParseRules.cc for type safety, modern C++, and documentation#13196
Open
grahamsedman wants to merge 1 commit into
Open
Conversation
- Replace C-style file I/O (fopen, fprintf, fclose) with std::ofstream for RAII-based file handling - Use fixed-width integer types (uint32_t, uint8_t) instead of unsigned int and char for portability and clarity - Refactor uint_to_binary function to use std::string instead of static buffer for thread safety - Add comprehensive Doxygen documentation for the file, functions, and arrays - Remove @section license License from file header to prevent Doxygen warnings about multiple use of section label, as @section is intended for major structured documentation sections, not repetitive boilerplate - Remove obsolete COMPILE_PARSE_RULES macro and ink_string.h dependency - Improve output formatting using std::setw, std::setfill, and std::hex for consistent alignment - Replace int loop variables with uint16_t for better type safety - Add static_cast for explicit type conversions
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📌 Summary
This PR refactors
src/tscore/CompileParseRules.ccto address compilation errors, type safety issues, modern C++ best practices, and documentation gaps. The changes ensure compatibility across 32-bit and 64-bit targets, fix narrowing conversion warnings, and improve code clarity and maintainability.✅ Problems Addressed
charis signed on x86, causing negative values (e.g.,-128) for ASCII >127, which cannot be narrowed tounsigned charon 32-bit targets.uint8_tfor character arrays and explicitly cast tounsignedwhen writing to files.#include "tscore/ink_string.h"is included but never used.uint_to_binarystatic char buf[33], making it unsafe for concurrent use.std::string(RAII-managed, thread-safe).FILE*andfprintf, which are less type-safe and require manual resource management.std::ofstream(RAII-based, type-safe).@section licensecauses warnings due to duplicate labels across files.@sectionand kept the license text directly in the file header.#define COMPILE_PARSE_RULESis defined but never used.unsigned intandcharinstead of fixed-width types (uint8_t,uint32_t).<cstdint>types for portability and clarity.🔧 Key Changes
1. File Header & Includes
#define COMPILE_PARSE_RULES,#include "tscore/ink_string.h".<cstdint>,<fstream>,<iomanip>,<string>.2. Data Types
unsigned inttouint32_tfor explicit size and future-proofing.chartouint8_tto guarantee an unsigned range (0-255) and avoid sign-extension issues.inttouint16_toruint8_tfor semantic clarity.3.
uint_to_binaryFunctionstatic char buf[33](non-thread-safe).std::string(thread-safe, RAII-managed).unsigned inttouint32_tfor explicit size.4. File I/O
FILE*andfprintf(C-style, manual resource management).std::ofstream(RAII-based, type-safe, modern C++).%dwithstatic_cast<unsigned>to avoid sign-extension issues when printinguint8_tvalues.5. Doxygen Documentation
parseRulesCType,tparseRulesCType, etc.).uint_to_binaryfunction.mainfunction (including its steps and classification functions).🧪 Testing
char) and ARM (unsignedchar) targets.ParseRulesCType,ParseRulesCTypeToUpper,ParseRulesCTypeToLower) contain correct values (no negative numbers for ASCII >127).uint_to_binaryis now thread-safe.