29 Commits
Author SHA1 Message Date
Hiroshi SHIBATAandClaude Fable 5 f4f2dfb3c7 Defer unloading box-local extension DLLs on Windows
box_entry_free could run before other T_DATA objects are finalized in
rb_objspace_call_finalizer, and FreeLibrary there unmapped the
rb_data_type_t and dfree functions that later finalization still
dereferences, crashing any boxed process that leaves extension objects
alive at exit. Keep the copied DLLs loaded until ruby_vm_destruct, then
unload and delete them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-10-13 16:13:54 -07:00
Hiroshi SHIBATAandClaude Opus 5 0f17de3708 [Bug #22339] Skip classes already freed while freeing a box
`RUBY_FREE_AT_EXIT=1` frees every object in an arbitrary order, so a
class a box refers to can go before the box itself, and freeing a class
already frees its classext for that box.  The box then reached rb_bug
with a T_NONE object, and the report crashed and looped in the signal
handler instead of aborting, so the process spun at exit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-09 16:06:56 -07:00
Satoshi Tagomori 655f89dbd3 [Box] Unroll the changes using features for 4.1 2026-06-22 09:57:10 -07:00
Nobuyoshi Nakada 2be8de43e8 Make rb_load_entrypoint accept two arguments directly
`rb_load_entrypoint` is used only by `rb_box_load`; it checks that the
argument has two-elements (implicitly assuming it is an array),
extracts its contents, and then simply discards the argument.
2026-06-22 09:57:10 -07:00
Peter Zhu 3b119e4f19 Don't use obj_id in Box classext_cow_classes
Using obj_id in classext_cow_classes is slow and also is a problem when
freeing classes because the lookup requires the EC, which is not available
if it is running on a GC thread. This will cause it to crash on MMTk.

We don't need to use the obj_id as the key in the classext_cow_classes
st_table because the class itself is pinned and won't move so we can use
it as the key instead.
2026-06-22 09:57:10 -07:00
Satoshi Tagomori 99aac00fa1 [Bug #21881] Separate the master and root box
This change separates the master box from the root box, as the single
master copy of boxes.
Before this change, the root box is the source of copies, and also
it runs builtin classes' code. Builtin code makes changes by
requiring files, thus the source of copies is mutable, be different
from the past one. This causes different internal states of boxes,
depending on when it is created.
After this change, all boxes are created from the master box, and
the master box never runs code, so it realizes the immutable source
of copies.

This also makes is possible to separate RubyGems (and other default
gems) from each boxes. All boxes will have their own copies of RubyGems.
RubyGems has its internal state, but it'll be separated between boxes
after this change.
2026-06-22 09:57:10 -07:00
Satoshi Tagomori f7b48456eb Box: show the fully qualified URL of the Ruby::Box doc 2025-12-24 15:10:25 +09:00
Nobuyoshi Nakada d8b33993e1 Box: Fix an unused variable warning 2025-12-21 20:31:30 +09:00
Nobuyoshi Nakada dd2f7d6ae6 [Bug #21794] Fix for platforms where O_CLOEXEC is not available 2025-12-19 19:48:43 +09:00
Luke Gruber aace29d485 Check for NULL fields in TYPEDDATA memsize functions (#15633)
Some TYPEDDATA objects allocate struct fields using the GC right after
they get created, and in that case the VM can try to perform a GC and join
a barrier if another ractor started one. If we're dumping the heap in another
ractor, this acquires a barrier and it will call the `rb_obj_memsize` function on this
object. We can't assume these struct fields are non-null. This also goes for C extensions,
which may cause problems with heap dumping from a ractor if their memsize functions aren't
coded correctly to check for NULL fields. Because dumping the heap from a ractor is likely a
rare scenario and it has only recently been introduced, we'll have to see how this works in
practice and if it causes bugs.
2025-12-18 15:42:49 -05:00
Nobuyoshi Nakada 5f09e1f046 Box: [DOC] fix the class name in rdoc
Also remove a stale TODO.
2025-12-16 16:53:13 +09:00
Nobuyoshi Nakada 8db3642ab5 Box: fix the class name in inspect 2025-12-16 16:53:13 +09:00
Nobuyoshi Nakada 5a4faaaeb1 Merge root_box_data into root_box
* Make invariant `root_box` an array consist of only `root_box_data`.
* Remove the unnecessary initializer list that is just overwritten in
  `initialize_root_box()` and missing `classext_cow_classes`.
* Shrink the scope using another local `root_box`.
* Make the data type constants static.
2025-12-15 16:05:21 +09:00
Nobuyoshi Nakada 3636277dc5 Add NUM2PTR and PTR2NUM macros
These macros have been defined here and there, so collect them.
2025-12-10 12:09:50 +09:00
Nobuyoshi Nakada 573896a40a Box: remove copied extension files 2025-12-09 23:41:50 +09:00
Nobuyoshi Nakada 8d1eafa7a7 Remove duplicate path names in error message 2025-12-09 20:50:35 +09:00
Nobuyoshi Nakada ee6784f289 Refine copy_ext_file
- Define the error constants.
- Use system calls to copy files if available.
- Simplify fallback copying.
- Copy without stdio buffering.
2025-12-09 20:50:35 +09:00
Satoshi Tagomori 9eafeaed67 Box: Free rb_classext_t struct for a box when the box is GCed 2025-12-02 23:49:49 +09:00
Satoshi Tagomori 75f8a116c9 Box: Fix data type name 2025-12-02 23:49:49 +09:00
Daisuke Fujimura (fd0) 9aa9cf8ea0 Fix switch fall-through in copy_ext_file_error 2025-11-30 21:03:00 +09:00
Stan Lo 4cd6661e18 Reorganize page documentations (#15154)
Re-organize page docs
2025-11-27 20:12:24 +00:00
Nobuyoshi Nakada 1738255f6d [Misc #21688] [DOC] Include box.md in Ruby::Box documentation 2025-11-23 19:04:17 +09:00
Nobuyoshi Nakada 4a0e01d768 [Misc #21688] Teach RDoc about the toplevel module Ruby
Re-open the exising module by calling `rb_define_module`.
RDoc (`RDoc::Parser::C#do_classes_and_modules`) does not recognize
`rb_path2class` as a class/module definition.
2025-11-23 19:01:16 +09:00
Nobuyoshi Nakada 3a5e7e9580 Constify 2025-11-08 20:51:04 +09:00
Satoshi Tagomori 19d4663d2f Use RUBY_BOX environment variable instead of RUBY_NAMESPACE 2025-11-07 13:14:54 +09:00
Satoshi Tagomori c4691ef061 Rename Namespace to Ruby::Box 2025-11-07 13:14:54 +09:00
Satoshi Tagomori d2a587c791 renaming internal data structures and functions from namespace to box 2025-11-07 13:14:54 +09:00
Satoshi Tagomori aaa1234702 update referenced filenames from namespace to box 2025-11-07 13:14:54 +09:00
Satoshi Tagomori 50b9d9d355 rename namespace.c (and others) to box.c 2025-11-07 13:14:54 +09:00