Commit Graph

17268 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 3d90ce7191 mruby-bigint: add power-of-2 optimizations for gcd operations
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>
2025-08-14 10:52:44 +09:00
Yukihiro "Matz" Matsumoto 1c6e061cc5 mruby-bigint: add single-limb fast path for gcd operations
optimizes gcd for single-limb numbers using binary algorithm,
avoiding multi-precision overhead for most common cases

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:44 +09:00
Yukihiro "Matz" Matsumoto b817e2e7e2 mruby-socket: add comprehensive call-seq documentation for Ruby and C methods
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
2025-08-14 10:52:44 +09:00
Yukihiro "Matz" Matsumoto caf1ae3b20 mruby-struct: rename functions to use snake_case convention
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
2025-08-14 10:52:44 +09:00
Yukihiro "Matz" Matsumoto 6864eae728 mruby-struct: replace mrb_funcall with mrb_ary_join to avoid VM callbacks
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
2025-08-14 10:52:44 +09:00
Yukihiro "Matz" Matsumoto 4a7c64fbf8 mruby-struct: optimize symbol usage with MRB_SYM and MRB_IVSYM
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
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto bc16457f29 mruby-struct: update documentation for keyword_init support
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
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto 0fcfa7677d mruby-bigint: fix power-of-2 base string conversion for remaining bits
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>
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto cb298607b1 readfloat: improve accuracy and performance with lookup tables and integer arithmetic
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>
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto de2e8838ae mruby-bigint: replace euclidean gcd with binary gcd algorithm
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>
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto d7ef4355a9 mruby-bigint: improve memory management with bounds checking and safety
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>
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto 8c764156e5 Merge pull request #6609 from mruby/dependabot/github_actions/actions/checkout-5 2025-08-12 07:33:17 +09:00
dependabot[bot] 14024d9072 build(deps): bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-11 20:58:54 +00:00
Yukihiro "Matz" Matsumoto 6af9ea32e4 Merge pull request #6607 from Asmod4n/patch-3 2025-08-10 23:35:54 +09:00
Hendrik d7edd3dbc1 fix bigint on raspberry pi
this fixes an issue where base can be out of range on a raspberry pi.
2025-08-10 09:21:38 +02:00
Yukihiro "Matz" Matsumoto 82722e47a1 Merge pull request #6600 from sizious/update-build-config-dreamcast-kos 2025-08-08 11:23:43 +09:00
Yukihiro "Matz" Matsumoto abc12cab3f Merge pull request #6602 from dearblue/iseq 2025-08-06 13:50:16 +09:00
Yukihiro "Matz" Matsumoto 61a7970291 Merge pull request #6604 from jbampton/pre-commit-autoupdate 2025-08-06 13:48:46 +09:00
John Bampton a6b8400fc3 pre-commit config updates
https://nodejs.org/en/download
2025-08-05 04:37:24 +10:00
SiZiOUS 8f85f41775 dreamcast_shelf build config: better handling for DreamSDK 2025-08-02 02:00:57 +02:00
dearblue 8064d4587f Improved iseq annotations for new and != 2025-08-01 23:04:32 +09:00
Yukihiro "Matz" Matsumoto 69db78420d Merge pull request #6601 from buty4649/fix/build-config-path-detection 2025-08-01 15:09:02 +09:00
buty4649 8381a5e403 refactor: use inline conditional for build config path assignment
Suggested by Gemini code assistant for better readability.
2025-08-01 14:15:21 +09:00
buty4649 7cfbcc3599 fix: skip local build_config.rb when working in MRUBY_ROOT
Only use local build_config.rb when current directory != MRUBY_ROOT.
2025-08-01 14:09:08 +09:00
SiZiOUS c8510fa5c6 dreamcast_shelf build config: renaming KOS_WRAPPERS to KOS_WRAPPERS_BASE 2025-08-01 00:43:42 +02:00
SiZiOUS 676af02024 dreamcast_shelf build config: minor fix for KOS_BASE check 2025-08-01 00:07:28 +02:00
SiZiOUS 55bcd35bed dreamcast_shelf build config: use KallistiOS wrappers
See: https://dreamcast.wiki/Using_Ruby_for_Sega_Dreamcast_development
2025-07-31 23:40:42 +02:00
SiZiOUS bfee6871aa dreamcast_shelf build config: updating file header 2025-07-31 22:12:54 +02:00
Yukihiro "Matz" Matsumoto 8e074f185b Merge pull request #6583 from buty4649/improve/build-config-file-detection 2025-07-30 19:14:43 +09:00
Yukihiro "Matz" Matsumoto e4fc7f36c4 Merge pull request #6591 from jbampton/patch-2 2025-07-29 10:35:02 +09:00
John Bampton e09893daa9 mruby-eval fix license link in README 2025-07-29 01:27:49 +10:00
Yukihiro "Matz" Matsumoto 2d054d5e91 Merge pull request #6588 from jbampton/add-codeql-for-actions 2025-07-27 18:23:11 +09:00
buty4649 b3038d4d49 refactor: use ternary operator for readability 2025-07-27 11:23:09 +09:00
John Bampton ab379e1229 Add CodeQL Analysis for GitHub Actions
https://docs.github.com/en/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning-with-codeql#about-codeql
2025-07-27 01:08:23 +10:00
Yukihiro "Matz" Matsumoto 867c93d5e2 Merge pull request #6587 from mruby/ry422b-codex/add-tests-for-set#hash-method 2025-07-26 15:27:43 +09:00
Yukihiro "Matz" Matsumoto 8ebe0d3a15 test(set): ensure hash consistency 2025-07-25 18:12:48 +09:00
Yukihiro "Matz" Matsumoto c8b4843416 Merge pull request #6585 from mruby/2fb0n1-codex/fix-spelling-in-mruby3.2.md 2025-07-25 16:37:31 +09:00
Yukihiro "Matz" Matsumoto 8e8ba281b2 Fix typo in mruby3.2 documentation 2025-07-25 16:10:03 +09:00
buty4649 501c237f50 improve: prioritize local build_config.rb over default configuration
Add fallback to check for ./build_config.rb before using default.rb
2025-07-25 14:24:37 +09:00
Yukihiro "Matz" Matsumoto 54ee91156a Merge pull request #6582 from dearblue/type-tag 2025-07-22 08:26:14 +09:00
Yukihiro "Matz" Matsumoto 7b56f136bb Merge pull request #6581 from dearblue/iv_inspect 2025-07-22 08:20:33 +09:00
dearblue bd0f111397 Stricter type tag in mrb_obj_alloc()
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()`.
2025-07-21 22:44:39 +09:00
dearblue 8b20f346f3 Setting the type tag with boot_defclass()
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`.
2025-07-21 22:43:27 +09:00
dearblue 91f2dca111 Merge mrb_obj_iv_inspect() into mrb_obj_inspect()
`mrb_obj_iv_inspect()` is an internal implementation function and is not called by any function other than `mrb_obj_inspect()`.
2025-07-21 20:54:50 +09:00
Yukihiro "Matz" Matsumoto 9e8e816d08 Merge pull request #6578 from mruby/dependabot/github_actions/super-linter/super-linter-8.0.0 2025-07-19 19:09:21 +09:00
dependabot[bot] 037a3dbf38 build(deps): bump super-linter/super-linter from 7.4.0 to 8.0.0
Bumps [super-linter/super-linter](https://github.com/super-linter/super-linter) from 7.4.0 to 8.0.0.
- [Release notes](https://github.com/super-linter/super-linter/releases)
- [Changelog](https://github.com/super-linter/super-linter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/super-linter/super-linter/compare/v7.4.0...v8.0.0)

---
updated-dependencies:
- dependency-name: super-linter/super-linter
  dependency-version: 8.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-18 14:34:40 +00:00
Yukihiro "Matz" Matsumoto a5ac9f3671 Merge pull request #6575 from mruby/codex 2025-07-18 15:13:29 +09:00
Yukihiro "Matz" Matsumoto b7e3b2be72 fix io file time accessor typo 2025-07-18 15:00:44 +09:00
Yukihiro "Matz" Matsumoto 479711700e mruby-set: add comprehensive call-seq documentation for all Ruby methods
Added complete call-seq documentation for all 17 Ruby methods in mrblib/set.rb:

- initialize: Added examples showing set creation with and without blocks
- merge: Added examples showing element merging and self-modification
- replace: Added examples showing complete set replacement
- subtract: Added examples showing element removal from enumerable
- intersection (&): Added examples showing common elements between sets
- union (|, +): Added examples showing set combination operations
- difference (-): Added examples showing set subtraction operations
- ^ (exclusive or): Added examples showing symmetric difference
- each: Added examples showing iteration with blocks and enumerators
- delete_if: Added examples showing conditional element deletion
- keep_if: Added examples showing conditional element retention
- collect!/map!: Added examples showing in-place element transformation
- reject!: Added examples showing conditional deletion with nil return
- select!/filter!: Added examples showing conditional retention with nil return
- classify: Added examples showing element classification into hash
- divide: Added examples showing set division into subsets

Co-authored-by: Atlassian Rovo Dev
2025-07-17 14:46:41 +09:00
Yukihiro "Matz" Matsumoto 2ac600dd8b mruby-proc-binding: add comprehensive call-seq documentation and helper function comments
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
2025-07-17 12:53:58 +09:00