67 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 8956c5abb5 mruby.h: include mruby/presym.h for all source files
Since presym is now mandatory, mruby.h includes presym.h so that
MRB_SYM() macros are available everywhere without explicit include.
Remove redundant #include <mruby/presym.h> from all source files.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-09 16:50:58 +09:00
Yukihiro "Matz" Matsumoto 00905566ac mruby-dir: combine variable declaration with initialization 2025-11-08 14:27:44 +09:00
Yukihiro "Matz" Matsumoto ad51bf848b mrbgem.rake: simplify hal selection logic
remove redundant visualcpp and mingw checks since for_windows? already
detects all windows builds including visual c++ and mingw.

ref #6653

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-27 11:11:27 +09:00
dearblue ea215bc19c Fixed HAL auto-detection order
Because MinGW was not recognized as Windows during cross-builds.
2025-10-25 21:06:16 +09:00
Yukihiro "Matz" Matsumoto 4d235444c0 mruby-dir: use hal-win-dir for mingw
mingw provides dirent.h for directory reading but filesystem functions
like mkdir use windows signatures (1 argument) not posix (2 arguments).
chroot is also unavailable on mingw. removed mingw from linux/bsd
pattern to let for_windows? predicate select hal-win-dir instead.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 23:28:27 +09:00
Yukihiro "Matz" Matsumoto feca90ceab hal: fix selection to use toolchain instead of RUBY_PLATFORM
when building with MSVC on Windows, RUBY_PLATFORM (from the Ruby
installation running rake) may indicate "mingw" if Ruby was installed
via RubyInstaller, causing incorrect selection of POSIX HALs instead
of Windows HALs.

fixed by checking spec.build.primary_toolchain first:
- if toolchain is "visualcpp", select Windows HALs
- otherwise fall through to existing platform checks

this ensures MSVC builds use hal-win-* gems even when Ruby itself
was installed with MinGW.

affected gems:
- mruby-dir
- mruby-io
- mruby-socket
- mruby-task

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 18:20:32 +09:00
Yukihiro "Matz" Matsumoto 1efaaa5570 mruby-io,mruby-dir: improve mingw detection for native builds
add mingw pattern to RUBY_PLATFORM check. native mingw builds were
falling through to windows hal because previous detection only worked
for cross-compilation. now checks RUBY_PLATFORM for mingw along with
linux/darwin/bsd.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 17:38:37 +09:00
Yukihiro "Matz" Matsumoto 91922e05af mruby-io,mruby-dir: use posix hal for mingw instead of windows hal
mingw provides posix-compatible functions (readlink, symlink, opendir, etc.)
so it should use hal-posix-io/dir instead of hal-win-io/dir. detect mingw by
checking if host_target or compiler command contains "mingw". check posix
platforms first so mingw is caught before for_windows check.

this fixes test failures on mingw where readlink returned absolute paths
instead of relative paths, and symlink/socket tests failed due to api
differences between windows native apis and posix apis.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 16:05:49 +09:00
Yukihiro "Matz" Matsumoto b424dfa331 mruby-dir: increase buffer size to prevent truncation warning
increase sandbox path buffer from 1024 to 2048 bytes to accommodate
full path with suffix without truncation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 15:49:45 +09:00
Yukihiro "Matz" Matsumoto 43695029bc mruby-dir: add missing unistd.h include for posix systems
mkdtemp() requires unistd.h on posix systems like macos and linux.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 15:44:51 +09:00
Yukihiro "Matz" Matsumoto 06eba9653b mruby-dir: use hal functions in test code for cross-platform compatibility
replace posix directory functions with hal interface functions in dirtest.c
to fix windows linking errors. test code now uses mrb_hal_dir_open/read/close
instead of opendir/readdir/closedir, and mrb_hal_dir_* for filesystem
operations.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 15:27:19 +09:00
Yukihiro "Matz" Matsumoto 610ff67906 HAL: rename functions to mrb_hal_<feature>_<name> convention
rename all HAL functions from mrb_<feature>_hal_<name>() to
mrb_hal_<feature>_<name>() for better grouping and clarity. this makes all
HAL functions immediately identifiable with the mrb_hal_* prefix.

affected gems:
- mruby-task: mrb_task_hal_* -> mrb_hal_task_*
- mruby-io: mrb_io_hal_* -> mrb_hal_io_*
- mruby-socket: mrb_socket_hal_* -> mrb_hal_socket_*
- mruby-dir: mrb_dir_hal_* -> mrb_hal_dir_*

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 09:59:03 +09:00
Yukihiro "Matz" Matsumoto 74c0fb9c6e mruby-dir: introduce HAL for platform abstraction
platform-specific directory operations separated into hal-posix-dir and
hal-win-dir gems. this allows mruby-dir to support embedded platforms and
simplifies platform-specific implementations.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 08:17:43 +09:00
Yukihiro "Matz" Matsumoto c54d5abdaf mruby-dir: unify int and mrb_int types for consistency
Change int variables to mrb_int in mrb_dir_getwd and mrb_dir_chroot
to maintain consistent use of mruby's integer type internally.
Keep explicit casts only at system interface boundaries where
different types are required by system calls.

Eliminates VC warning C4267 while following the same type
unification approach used in pack.c.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-03 19:46:02 +09:00
Yukihiro "Matz" Matsumoto 0ce99e442d mruby-dir: fix C4244 warning in mrb_dir_getwd function
use mrb_int for size variable and cast to size_t only when calling getcwd.
this maintains consistency with mruby type system while avoiding
conversion warnings on windows vc compiler.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-22 18:20:47 +09:00
Yukihiro "Matz" Matsumoto 2113b7cd23 mruby-dir: implement Dir.children in c for improved performance
Moved Dir.children from Ruby to C implementation to eliminate
Ruby loop overhead and string comparison inefficiencies.
Uses existing skip_name_p helper to filter out "." and ".." entries
efficiently in C.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-19 10:06:16 +09:00
Yukihiro "Matz" Matsumoto c699b211d7 mruby-dir: implement Dir.entries in c for improved performance
Moved Dir.entries from Ruby to C implementation to eliminate
Ruby loop overhead and array allocation inefficiencies.
Builds result array directly in C for better performance.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-19 10:06:16 +09:00
Yukihiro "Matz" Matsumoto 785d3b81d5 mruby-dir: add comprehensive call-seq documentation for Ruby and C methods
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
2025-08-14 10:52:45 +09:00
dearblue 1326017d1d Omit the _WIN64 definition check
Checking the official MSVC documentation, if `_WIN64` is defined, then `_WIN32` is also defined.
https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros

I could not find any documentation on MinGW, but I assume it is not a problem.
2024-12-07 22:47:28 +09:00
dearblue 3aa9a5ee68 Perform GC before deleting directories
In some environments, the test will fail because the directory in use cannot be deleted.
This problem was encountered when building 32-bit binary with mingw32 on FreeBSD and running on wine.
2024-09-10 21:17:10 +09:00
Yukihiro "Matz" Matsumoto 3628d093f4 mruby-dir: use presym for initialization 2024-06-14 00:27:13 +09:00
Yukihiro "Matz" Matsumoto c635456f16 mruby-dir: fix indentation 2024-05-16 07:06:59 +09:00
Yukihiro "Matz" Matsumoto 7865593823 mruby-dir: enumerating methods should return enumerators; #6265 2024-05-14 09:42:38 +09:00
dearblue 12030b3f41 Fixes Dir.children and Dir.each_child
The two methods exclude "." and "..".
2024-05-10 21:54:59 +09:00
Yukihiro "Matz" Matsumoto 87b358a342 Including header files in include/* by <> 2024-03-26 13:59:59 +09:00
Yukihiro "Matz" Matsumoto 5de3be1bee mruby-dir/dir.c (mrb_di_getwd): reduce buffer allocation size
Instead of allocating `MAXPATHLEN` buffer string at the beginning,
allocate smaller (64 bytes) buffer, then resize it if needed. The
allocating max size is safe but consumes more memory.
2023-08-08 11:24:14 +09:00
Ray Chason 23e9befbc0 Changes to cross-compile with DJGPP 2023-06-17 17:20:33 -04:00
Yukihiro "Matz" Matsumoto f1a3cfbd3b add a space between if and ( 2023-05-22 11:55:21 +09:00
Yukihiro "Matz" Matsumoto c32f7915fb reformat else clause indentation style 2023-05-20 00:21:01 +09:00
John Bampton 63e170170e mrbgems: standardize spec.authors for whitespace and author name 2023-05-06 06:06:29 +10:00
Yukihiro "Matz" Matsumoto b4c936b533 use new E_EXCEPTION and E_STANDARD_ERROR; ref #5924 2023-02-10 15:21:38 +09:00
John Bampton 07a7d2a6cb md/yml: remove unneeded blank lines and whitespace 2023-02-10 14:02:57 +10:00
Yukihiro "Matz" Matsumoto 1bba8cf53b mruby-dir: remove files needed for an independent gem 2023-01-10 10:53:15 +09:00
dearblue 72ab1821de Avoid IOError when returning from Dir.open
Ignore `IOError` if `Dir#close` was done in the block.
2023-01-01 17:40:50 +09:00
Yukihiro "Matz" Matsumoto bb3f403511 Merge pull request #5876 from dearblue/dir-foreach
Close the directory object with the `Dir.foreach` method
2022-12-26 13:27:53 +09:00
Yukihiro "Matz" Matsumoto 3518d15d04 Merge pull request #5875 from dearblue/dir-cstr
Get argument of the `Dir` method takes a C string directly
2022-12-26 13:26:56 +09:00
Yukihiro "Matz" Matsumoto 2656a92380 Merge pull request #5874 from dearblue/dir-funcs
Hide substance functions of methods in `mruby-dir`
2022-12-26 12:58:44 +09:00
dearblue 50b24c124f Close the directory object with the Dir.foreach method 2022-12-25 21:25:30 +09:00
dearblue 1fb19ca046 Get argument of the Dir method takes a C string directly 2022-12-25 21:25:30 +09:00
dearblue 71df263bdf Hide substance functions of methods in mruby-dir 2022-12-25 21:25:30 +09:00
dearblue 35490c2c32 Define also the exception class IOError in mruby-dir
Since `IOError` is a standard exception class in Ruby, there is no need to assume different superclasses.
The Ruby specification allows repeated class definitions as long as the superclass is the same.

This also avoids using the `mruby/ext/io.h` file to reference `E_IO_ERROR`.
2022-12-25 21:25:21 +09:00
dearblue fec74cd040 Avoid uses mruby/src/error.h file 2022-12-25 17:31:53 +09:00
Yukihiro "Matz" Matsumoto 7821462571 mruby-dir/dirtest.c: need to include <io.h> for mktemp() on Windows 2022-12-22 22:07:07 +09:00
Yukihiro "Matz" Matsumoto 67addd7da3 mruby-dir/dirtest.c: avoid string allocations for mrb_raisef 2022-12-22 11:36:03 +09:00
Yukihiro "Matz" Matsumoto 1d174404b3 mruby-dir/dirtest.c: refactor mkdir in mrb_dirtest_setup 2022-12-22 11:33:44 +09:00
Yukihiro "Matz" Matsumoto d51d5825ad mruby-dir/dir.c: update compatibility macros for Windows 2022-12-22 11:13:50 +09:00
Yukihiro "Matz" Matsumoto 084871abf3 mruby-dir/dirtest.c: use _mktemp instead of mktemp for Windows 2022-12-22 11:12:32 +09:00
Yukihiro "Matz" Matsumoto c737519d02 mruby-dir/dirtest.c: add compatibility macro for getcwd 2022-12-22 11:11:49 +09:00
Yukihiro "Matz" Matsumoto 4cbcf743a7 mruby-dir/dirtest.c: wrap function prototypes by extern "C" 2022-12-22 11:11:18 +09:00
Yukihiro "Matz" Matsumoto 783e62e582 mruby-dir/dirtest.c: copy some of dirent header information
Instead of including whole "dirent.c" file.
2022-12-22 09:53:16 +09:00