Added complete call-seq documentation for 7 missing public methods in the
random gem, improving documentation coverage from 25% to 100%.
Documentation added:
- Random.new: Create new random number generator with optional seed
- Random#rand: Generate random numbers (float, integer, or range)
- Random#srand: Seed the random number generator
- Random#bytes: Generate random byte strings
- Random.rand/rand: Class method and Kernel method for default generator
- Random.srand/srand: Class method and Kernel method for seeding
- Random.bytes: Class method for random bytes using default generator
Each method now includes:
- Clear method signatures with parameter and return types
- Detailed descriptions of random number generation behavior
- Practical examples showing different usage patterns
- Notes about default vs instance generators
- Cross-references between class methods and Kernel methods
- Range and numeric type handling explanations
The existing Array methods (shuffle, shuffle!, sample) were already
well-documented and remain unchanged. This completes the documentation
for all random number generation functionality in mruby, covering both
the Random class API and the traditional Kernel methods.
This significantly improves usability for developers working with
random number generation, cryptographic applications, and statistical
sampling in embedded Ruby environments.
Co-authored-by: Atlassian Rovo Dev
Added complete call-seq documentation for all 3 public methods in the
pack gem, improving documentation coverage from 0% to 100%.
Documentation added:
- Array#pack: Pack array elements into binary string using template
- String#unpack: Unpack binary string into array using template
- String#unpack1: Unpack first value from binary string using template
Each method now includes:
- Clear method signatures with parameter and return types
- Comprehensive template directive reference table covering all supported formats
- Detailed descriptions of binary data packing/unpacking behavior
- Practical examples showing common usage patterns for different data types
- Notes about endianness, data type sizes, and string handling
- Cross-references between related methods
Template directives documented include:
- Integer types: C, c, S, s, L, l, Q, q (various sizes and signedness)
- Network/endian specific: n, N, v, V (network and little endian)
- Floating point: f, d (single and double precision)
- String types: A, a, Z (ASCII with different padding)
- Hex and binary: H, h (hex strings with nibble order)
- Special: x, X, @ (null bytes, positioning)
Co-authored-by: Atlassian Rovo Dev
Added complete call-seq documentation for all 39 public methods in the
Time class, improving documentation coverage from 0% to 100%.
Documentation added includes:
Class methods (6):
- Time.now: Get current system time
- Time.at: Create time from epoch seconds
- Time.gm/utc: Create UTC time from components
- Time.local/mktime: Create local time from components
Instance methods (33):
- Arithmetic: +, -, <=> for time calculations and comparisons
- Accessors: year, month, day, hour, min, sec, usec, wday, yday
- Timezone: zone, utc, localtime, getutc, getlocal, utc?, gmt?, dst?
- Conversion: to_i, to_f, to_s, inspect, asctime, ctime, hash
- Initialization: new, initialize_copy
- Weekday helpers: sunday?, monday?, tuesday?, wednesday?, thursday?, friday?, saturday?
Each method now includes:
- Clear method signatures with parameter and return types
- Detailed descriptions of time handling behavior
- Practical examples showing common usage patterns
- Notes about timezone handling and precision
- Consistent formatting following mruby documentation standards
This represents a major improvement in maintainability and usability of
time functionality for developers working with date/time operations in
embedded Ruby environments. The Time class is now fully documented with
comprehensive examples covering all aspects of time manipulation.
Co-authored-by: Atlassian Rovo Dev
Added complete call-seq documentation for public methods and corrected
internal method documentation structure:
Public API methods
- SystemCallError.new: Create SystemCallError with message/errno
- SystemCallError#errno: Get errno number from exception
- SystemCallError._sys_fail: Internal method to raise errno exceptions
- Errno exception classes#new: Create specific errno exceptions
Fixed documentation structure to follow mruby conventions where internal
methods starting with __ should not have call-seq documentation but only
brief explanatory comments.
Each public method now includes:
- Clear method signatures with parameter and return types
- Descriptions of errno handling behavior
- Practical examples showing exception creation and handling
- Consistent formatting following mruby documentation standards
Co-authored-by: Atlassian Rovo Dev
Added comprehensive call-seq documentation for the 2 missing public
methods in the encoding gem, improving documentation coverage from
33% to 100%.
Documentation added:
- String#encoding: Returns the encoding of a string (UTF-8 or ASCII-8BIT)
- String#force_encoding: Changes string encoding in place
Each method now includes:
- Clear method signatures with parameter and return types
- Descriptions of encoding behavior specific to mruby's limitations
- Practical examples showing usage patterns
- Notes about mruby's simplified encoding support (UTF-8, ASCII-8BIT, BINARY)
This complements the existing String#valid_encoding? documentation and
provides complete coverage for mruby's "poorman's encoding" functionality,
making it easier for developers to understand encoding operations in
embedded Ruby environments.
Co-authored-by: Atlassian Rovo Dev
Added complete call-seq documentation for all 17 public methods in the
CMath module, improving documentation coverage from 0% to 100%.
Documentation includes:
- Method signatures with parameter and return types
- Clear descriptions of mathematical operations
- Branch cut information for complex functions
- Practical examples showing real and complex number usage
- Consistent formatting following mruby documentation standards
Methods documented:
- Exponential and logarithmic: exp, log, log2, log10, sqrt
- Trigonometric: sin, cos, tan, asin, acos, atan
- Hyperbolic: sinh, cosh, tanh, asinh, acosh, atanh
This significantly improves maintainability and usability of the complex
math functionality for developers working with mathematical computations
in embedded Ruby environments.
Co-authored-by: Atlassian Rovo Dev
- Add complete call-seq documentation for 4 missing public methods:
* Proc#lambda?: returns true if proc is a lambda, false if regular proc
* Proc#source_location: returns [filename, line] or nil for native procs
* Proc#to_s/inspect: returns string representation with location info
* Kernel#proc: equivalent to Proc.new, creates proc from block
- Add helpful comment for internal mrb_proc_source_location helper function
- Improve TODO comment clarity for cfunc aspec limitation
- Achieves 100% public API documentation coverage (5/5 methods documented)
- Improves code maintainability and follows mruby documentation standards
Co-authored-by: Atlassian Rovo Dev
During mrb_state initialization, especially when defining core classes and methods,
the method cache is repeatedly cleared. This causes significant overhead in
scenarios like mrbtest where mrb_state is initialized multiple times.
This commit introduces a `bootstrapping` flag in `struct mrb_state`.
When this flag is TRUE (during mrb_open_core), method cache clears
triggered by `mrb_define_method_raw` and `include_module_at` are suppressed.
The cache is cleared only once at the very end of `mrb_open_core` after
all core methods are defined, and the flag is then set to FALSE.
This optimization significantly reduces the number of method cache clears
during initialization, improving performance for repeated mrb_state creations.
Co-authored-by: Gemini <gemini@google.com>
Prevent SystemStackError when comparing structs with circular
references. Uses the same recursion detection mechanism as Hash and
Array equality methods.
Co-authored-by: Claude <noreply@anthropic.com>
Prevent SystemStackError when comparing arrays with circular references.
Uses the same recursion detection mechanism as Hash equality methods.
Co-authored-by: Claude <noreply@anthropic.com>
Add more general __method_recursive?(method_name[, arg]) method that can
check recursion for any method, not just inspect. This provides a more
useful API for Ruby code while cleaning up the implementation.
Co-authored-by: Claude <noreply@anthropic.com>
Replace custom inspect_recursive_p implementation with the new
generalized mrb_recursive_method_p for better code reuse and
consistency.
Co-authored-by: Claude <noreply@anthropic.com>
Add generalized recursion detection system and integrate it into Hash#==
and Hash#eql? to prevent infinite recursion with mutually recursive hash
structures. Uses call stack inspection for minimal memory overhead.
Co-authored-by: Claude <noreply@anthropic.com>
Move Hash#eql? implementation from Ruby to C to improve performance and
consistency with other core methods. The C implementation uses mrb_eql
for value comparison, providing proper eql? semantics.
Co-authored-by: Claude <noreply@anthropic.com>
Move Hash#== implementation from Ruby to C to improve performance
and consistency with other core methods. The C implementation
provides the same functionality while being more efficient.
Co-authored-by: Claude <noreply@anthropic.com>
This commit introduces memory prefetching to the `bsearch_idx` functions
in `src/class.c` and `src/variable.c` to improve performance.
A new macro `MRB_MEM_PREFETCH` is defined in `include/mruby/variable.h`
which uses `__builtin_prefetch` if available.
Co-authored-by: Gemini <gemini@google.com>
mruby does not provide `begin ... end while cond` that behave at-least-once
loop, like CRuby does. It remains in TODO.md for long time. But finally we have
implemented the behavior.
This commit introduces NODE_BEGIN as a distinct AST node type for
explicit begin...end blocks, separate from NODE_STMTS which represents
general statement sequences. This distinction will be essential for
implementing CRuby-compatible begin...end while/until constructs.
Key changes:
- Added NODE_BEGIN enum in node.h
- Added new_begin() function in parse.y using optimized cons() structure
- Modified begin...end grammar rule to generate NODE_BEGIN nodes
- Added NODE_BEGIN codegen support in codegen.c
- Added NODE_BEGIN to parser dump functionality
NODE_BEGIN uses a simpler cons() structure instead of list2() for
better memory efficiency, as it only contains a single body node.
Co-Authored-By: Claude <noreply@anthropic.com>
Modify new_stmts to flatten unnecessary nesting by returning existing
NODE_STMTS directly instead of wrapping them. This reduces memory usage
and AST complexity when multiple parentheses levels are used.
Before: (((expr1; expr2))) creates nested NODE_STMTS
After: (((expr1; expr2))) creates single NODE_STMTS with statements
Co-authored-by: Claude <noreply@anthropic.com>
Rename NODE_BEGIN to NODE_STMTS to better reflect its purpose as a
container for statement sequences, not specifically begin-end blocks.
This prepares for adding a dedicated node type for explicit begin-end
constructs.
- Rename NODE_BEGIN enum to NODE_STMTS in node.h
- Update all references in parse.y and codegen.c
- Rename new_begin function to new_stmts
Co-Authored-By: Claude <noreply@anthropic.com>
This commit adds `call-seq` documentation to the following methods
in `mruby-numeric-ext` to improve code clarity and maintainability:
- `Integer#even?`
- `Integer#odd?`
- `Integer.sqrt`
- `Float#remainder`
Additionally, it adds a comment to the internal `isqrt` function
to explain its implementation.
Co-authored-by: Gemini <gemini@google.com>
The `XXX` comment in `sprintf.c` suggested that not validating
the number of arguments for positional format specifiers was a bug.
However, CRuby's `sprintf` also ignores extra arguments in this
case, making the existing behavior correct.
This commit removes the confusing comment and the disabled code
block that went with it, clarifying the intended behavior and
cleaning up the code.
Co-authored-by: Gemini <gemini@google.com>
The `mruby-hash-ext` gem already had `call-seq` comments for its
public methods, but the internal helper functions `slice_bang_i` and
`hash_key_i` were undocumented.
This commit adds detailed comments to these functions, explaining their
purpose, parameters, and return values. This improves the
maintainability and readability of the code.
Co-authored-by: Gemini <gemini@google.com>
Fixed critical resource leaks by pre-allocating mruby objects before system
calls. Since mrb_str_resize to smaller size and mrb_ary_push within
pre-allocated size cannot fail, moving allocations before socket creation
eliminates all leak potential with minimal code changes.
Co-authored-by: Atlassian Rovo Dev
Added call-seq documentation for 7 public methods (2 in C, 5 in Ruby)
improving documentation coverage from ~1% to complete. Includes method
signatures, clear descriptions, and practical examples for cover?, size,
max, min, overlap?, first, and last. Added simple description for internal
__empty_range? helper method.
Co-authored-by: Atlassian Rovo Dev
Fixes a null pointer dereference in `find_visibility_scope` when defining a
singleton method inside `instance_eval`.
This was caused by `ci->u.env` being `NULL` in this context. The fix adds a
`NULL` check to prevent the crash.
Co-authored-by: Gemini <gemini@google.com>
This commit optimizes instance variable lookups by replacing the
search algorithm with the same branch-free binary search recently
introduced for method lookups. This improves performance by
avoiding CPU branch mispredictions.
This commit replaces the method table search algorithm with a
branch-free binary search. This avoids conditional branches,
which can prevent CPU pipeline stalls from branch misprediction,
leading to faster method lookups.
The new `bsearch_idx` function is used for finding, inserting,
and deleting methods in the method table.
Merged the separate "Array#-" and "Array#- with large arrays" test
blocks into a single comprehensive test. The unified test covers both
basic functionality (type checking, simple subtraction) and the
hash-based implementation for large arrays (>32 elements).
Co-authored-by: Atlassian Rovo Dev
Add detailed comments to all functions in class.c including:
- Function purpose and behavior descriptions
- Parameter documentation with types and meanings
- Return value explanations with all possible outcomes
- Error conditions and exception documentation
- Helper function and structure documentation
This improves code maintainability and follows Ruby documentation
conventions with proper call-seq formatting.
Co-authored-by: Atlassian Rovo Dev