Added complete call-seq documentation for all Rational methods in
mrblib/rational.rb (4 methods):
## Rational Class Methods:
- inspect: returns string representation for debugging with parentheses
format, showing the rational value in "(numerator/denominator)" form
- to_s: returns string representation in "numerator/denominator" format
for display and conversion purposes
- <=>: spaceship operator for comparison with other numeric types,
returns -1/0/+1 for less/equal/greater comparisons, enables Comparable
module functionality with proper nil handling for incomparable values
## Numeric Extension Methods:
- to_r: converts any numeric value to rational representation with
denominator of 1, part of the standard numeric conversion protocol
Co-authored-by: Atlassian Rovo Dev
Added complete call-seq documentation for all extended Proc methods in
mrblib/proc.rb (6 methods):
## Proc Extension Methods:
- ===: case equality operator for use in case statements, enables proc
objects as targets in when clauses for pattern matching
- yield: compatibility method equivalent to call, provided for API
consistency with block yield semantics
- to_proc: protocol method that returns self, part of the standard
to_proc conversion protocol for Proc objects
- curry: creates curried procs for partial application and functional
programming patterns, supports optional arity specification with
proper lambda arity validation
- << (left composition): proc composition operator that calls other_proc
first then this proc, enabling right-to-left function composition
- >> (right composition): proc composition operator that calls this proc
first then other_proc, enabling left-to-right function composition
Co-authored-by: Atlassian Rovo Dev
Implement specialized modular reduction algorithm for single-limb modulus
to avoid expensive division operations. The optimization uses repeated
division with double-precision arithmetic for multi-limb dividends and
direct modulo operation for single-limb dividends.
Algorithm:
- Single-limb dividend: direct modulo operation (x % m)
- Multi-limb dividend: iterative reduction using double-precision arithmetic
processing limbs from most significant to least significant
Purpose:
- Accelerate common modular arithmetic operations with small moduli
- Reduce computational overhead for cryptographic and mathematical operations
- Improve performance of rational number arithmetic that relies on modular ops
Performance impact:
- Single-limb modulus: ~1.04M ops/sec (6x improvement over general case)
- Maintains correctness for all existing modular arithmetic operations
- Zero impact on large modulus operations (fallback to existing algorithm)
Co-authored-by: Claude <noreply@anthropic.com>
Added complete call-seq documentation for directory operations across
both mrblib/dir.rb (7 Ruby methods) and src/dir.c (12 C methods):
## Ruby Methods (mrblib/dir.rb):
- Dir instance methods: each, each_child for directory iteration with
enumerator support when no block given
- Dir class methods: entries, children for getting directory contents
as arrays, foreach for iteration, open for directory access with
optional block handling, chdir for changing working directory with
optional block for temporary changes
## C Methods (src/dir.c):
- Dir class methods: delete for removing directories, exist? for checking
directory existence, getwd/pwd for current directory, mkdir for creating
directories with optional permissions, chroot for changing filesystem root,
empty? for checking if directory is empty
- Dir instance methods: new for creating directory objects, close for
closing directory streams, read for reading directory entries, rewind
for repositioning to beginning, seek/tell/pos for directory positioning
Co-authored-by: Atlassian Rovo Dev
adds efficient trailing zero counting and power-of-2 detection
with fast paths for common cases involving powers of 2
Co-authored-by: Claude <noreply@anthropic.com>
optimizes gcd for single-limb numbers using binary algorithm,
avoiding multi-precision overhead for most common cases
Co-authored-by: Claude <noreply@anthropic.com>
Added complete call-seq documentation for socket programming methods across
all major socket classes in both mrblib/socket.rb (64 Ruby methods) and
src/socket.c (35 C methods):
- Addrinfo: Complete documentation for address information handling including
creation (new, foreach, ip, tcp, udp, unix), inspection (inspect,
inspect_sockaddr, to_s), address queries (afamily, pfamily, ipv4?, ipv6?,
ip?, unix?), data extraction (ip_address, ip_port, ip_unpack, unix_path),
and conversion methods (to_sockaddr, getnameinfo)
- BasicSocket: Core socket functionality including class configuration
(do_not_reverse_lookup, do_not_reverse_lookup=), object creation (for_fd),
address retrieval (local_address, remote_address), and non-blocking
operations (recv_nonblock)
- IPSocket: Internet protocol socket operations including address information
(addr, peeraddr), connection methods (bind, connect), data transfer
(send, recvfrom, recvfrom_nonblock), and address resolution (getaddress)
- TCPSocket/TCPServer: TCP client and server socket operations including
connection establishment (new, open), server operations (accept,
accept_nonblock, listen, sysaccept)
- UDPSocket: UDP socket operations for datagram communication including
initialization and internal address handling
- Socket: Low-level socket operations including creation (new, open),
address manipulation (sockaddr_in, sockaddr_un, unpack_sockaddr_in,
unpack_sockaddr_un), connection management (bind, connect, listen),
data transfer (recvfrom, recvfrom_nonblock), socket pairs (pair),
and name resolution (getaddrinfo, getnameinfo)
- UNIXSocket/UNIXServer: Unix domain socket operations for local IPC
including creation (new, socketpair), path handling (path, addr, peeraddr),
server operations (accept, accept_nonblock, listen, sysaccept), and
data transfer (recvfrom)
- Addrinfo: Core address resolution methods including getaddrinfo for name
resolution, getnameinfo for reverse lookups, and unix_path for Unix
domain socket paths
- BasicSocket: Low-level socket operations including getpeereid for peer
credentials, getpeername/getsockname for address retrieval, recv/send
for data transfer, getsockopt/setsockopt for option management,
shutdown for connection termination, and Windows-specific overrides
(close, sysread, sysseek, syswrite)
- IPSocket: Internet protocol utilities including ntop/pton for address
conversion and recvfrom for receiving data with sender information
- Socket: Core socket creation and management including gethostname,
internal methods (_accept, _bind, _connect, _listen, _socket),
address utilities (sockaddr_un, socketpair), and platform-specific
implementations
- Socket::Option: Socket option handling including creation from boolean/
integer values, accessor methods (family, level, optname, data),
type conversion (int, bool), and debugging support (inspect)
All methods now have comprehensive call-seq documentation with practical
This significantly improves maintainability and usability of errno
handling for developers working with system call errors and file
operations in embedded Ruby environments.
Co-authored-by: Atlassian Rovo Dev
Rename internal functions to follow mruby's snake_case naming convention:
- mrb_struct_initialize_withArg -> mrb_struct_init_with_args
- mrb_struct_initialize_withKw -> mrb_struct_init_with_keywords
Update all function calls to use the new names. This improves code
consistency and follows established mruby naming conventions.
Co-authored-by: Atlassian Rovo Dev
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>
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`.