Replace mrb_funcall_id call with direct mrb_ary_join function call
in error message generation to comply with VM callback restrictions.
This prevents re-entrant VM execution which can cause crashes and
undefined behavior, following mruby's policy of avoiding VM callbacks
from C code.
Co-authored-by: Atlassian Rovo Dev
Replace mrb_intern_lit calls with MRB_SYM and MRB_IVSYM macros for
better performance and consistency. Convert mrb_funcall with string
literals to mrb_funcall_id with MRB_SYM for the keyword_init feature
and other method calls.
Key optimizations:
- keyword_init symbol access using MRB_SYM(keyword_init)
- Instance variable access using MRB_IVSYM(__keyword_init__)
- Method calls using mrb_funcall_id with MRB_SYM(join)
This improves runtime performance by avoiding symbol table lookups
for commonly used symbols and follows mruby's presym conventions.
Co-authored-by: Atlassian Rovo Dev
Updated README.md and C documentation to reflect the new keyword_init
feature added in commit 512d25607b.
Changes include:
- README.md: Added comprehensive examples showing keyword initialization
usage, including basic usage, partial initialization, and error cases
- struct.c: Updated call-seq documentation for Struct.new to include
keyword_init parameter and added examples of keyword-based struct
creation and initialization
The keyword_init option allows structs to accept keyword arguments
instead of positional arguments, providing a more explicit and
Ruby-like interface for struct initialization.
Examples added:
- Basic keyword initialization with keyword_init: true
- Partial initialization with missing keys defaulting to nil
- Error handling for mixed positional/keyword arguments
- Empty initialization behavior
Co-authored-by: Atlassian Rovo Dev
Fix incomplete digit processing in power-of-2 base string conversion:
- Add handling for remaining bits after processing all limbs
- Ensure all significant bits are converted to digits
- Maintain correct conversion for large numbers with partial bit patterns
- Add comments clarifying the conversion process
This fixes cases where the last few bits of a number might not be
converted when the total bit count doesn't align perfectly with the
base's bit width, ensuring complete and correct string representation.
Co-authored-by: Claude <noreply@anthropic.com>
Replace expensive pow() calls with pre-computed lookup tables for powers of 10.
Use integer arithmetic during parsing to avoid floating-point precision loss.
Add overflow detection for large numbers while maintaining compatibility.
Co-authored-by: Claude <noreply@anthropic.com>
Replace the traditional Euclidean GCD algorithm with Stein's binary GCD algorithm
for improved performance on large numbers:
- Implement binary GCD (Stein's algorithm) avoiding expensive division operations
- Use bit shifts and subtraction instead of modulo operations
- Handle special cases (zero values) efficiently
- Preserve common factors of 2 for correct results
- Maintain full compatibility with existing rational number functionality
Binary GCD is significantly faster for large numbers as it avoids the costly
division operations used in the Euclidean algorithm, using only bit operations,
addition, and subtraction.
Co-authored-by: Claude <noreply@anthropic.com>
Add overflow protection and memory safety improvements to bigint operations:
- Add overflow check in mpz_realloc to prevent integer overflow in size calculations
- Fix zero-initialization loop by preserving original size during reallocation
- Improve mpz_clear to prevent double-free by nullifying pointer after free
- Add bounds checking to mpz_get_str for string conversion buffer allocation
- Add documentation comments clarifying memory allocation strategies
- Add helper macros MPZ_TMP_INIT/CLEAR for safer temporary variable management
These changes prevent potential memory corruption, buffer overflows, and crashes
while maintaining full compatibility with existing bigint functionality.
Co-authored-by: Claude <noreply@anthropic.com>
The "manual" stage in pre-commit refers to a specific hook stage designed for hooks that are not intended to run automatically during a standard git commit operation. Instead, these hooks are meant to be triggered explicitly by a user, typically when performing a full repository scan or a specific check.
This speeds up the standard `pre-commit run --all-files` run by not running these two hooks.
Both hooks are time consuming
Can run the manual hooks with:
`pre-commit run --all-files --hook-stage manual`
Add pre-commit manual stage run on CI to keep full coverage
When `ci->n == CALL_MAXARGS`, the correct value is `argv[1] = argv[1]`.
However, it was always `args[1] = args[ci->n]`, which caused objects outside the range to be picked up.
fixed#6584
Instances cannot be created with `MRB_TT_FALSE`.
_**Compatibility Note**_
This change may cause runtime errors.
However, that is probably because it is not set correctly by `MRB_SET_INSTANCE_TT()`.
The purpose is to force the setting of the type tag.
This is in preparation for subsequent commits that will prevent the creation of instances with `MRB_TT_FALSE`.
Added complete call-seq documentation for proc binding functionality across
both source and test files:
## Core Implementation (src/proc_binding.c):
### Main Method:
- binding: returns Binding object capturing proc's execution context,
includes comprehensive examples showing local variable access, parameter
binding, and scope retention with practical usage patterns
### Helper Functions:
- mrb_mruby_proc_binding_gem_init: initializes gem by adding binding method
to Proc class, explains method signature and return type behavior
Co-authored-by: Atlassian Rovo Dev
Enhanced documentation for Binding class methods with detailed examples:
- local_variable_defined?: Added examples showing usage within methods and at
top-level, including interaction with local_variable_set
- local_variable_get: Added examples demonstrating retrieval of different data
types, variable modification tracking, and NameError behavior
- local_variable_set: Added examples showing variable assignment and creation
- local_variables: Added examples showing array of local variable names
- receiver: Added examples showing bound receiver object access
- binding (Kernel method): Added examples showing binding creation and usage
Co-authored-by: Atlassian Rovo Dev