summaryrefslogtreecommitdiff
path: root/namespace.c
AgeCommit message (Collapse)Author
2025-11-07rename namespace.c (and others) to box.cSatoshi Tagomori
2025-11-03Fix incorrect RUBY_DEBUG rangeSatoshi Tagomori
2025-11-03Make Namespace.root visible not only for debuggingSatoshi Tagomori
There are many APIs that expects application codes overwrite global methods. For example, warn() expects Warning.warn() is overwritten to hook warning messages. If we enable namespace, Warning.warn defined in the app code is visible only in the namespace, and invisible from warn() defined in the root namespace. So we have to enable users to overwrite Warning.warn in the root namespace. This is ugly and temporal workaround. We need to define better APIs to enable users to hook such behaviors in the different way from defining global methods.
2025-11-03Fix use of inappropriate debug flagSatoshi Tagomori
2025-10-31namespace.c: Fix -Wunused-function warningsTakashi Kokubun
2025-10-31Specify RUBY_DEBUG flag in the right waySatoshi Tagomori
2025-10-23Make Namespace::Root TypedData inherit from Namespace::EntryPeter Zhu
The two types of TypedData objects should be treated the same except for the free function. Since Namespace::Root did not inherit from Namespace::Entry, all the TypedData_Get_Struct calls for Namespace::Root would raise "wrong argument type Namespace::Root (expected Namespace::Entry)".
2025-10-21Fix memory leak of darray in loaded_features_indexPeter Zhu
2025-10-20Fix extension file permissions on Cygwin in namespace featureDaisuke Fujimura (fd0)
2025-10-18Free loaded_features_index in namespacePeter Zhu
2025-10-18Fix memory leak of TypedData data in NamespacePeter Zhu
2025-10-18Add rb_root_namespace_data_typePeter Zhu
2025-10-14Define main.to_s even in namespacesSatoshi Tagomori
It just shows "main" just like the main object without namespace. All main objects in namespaces will show "main" and it is impossible to determine a main from main objects if it returns "main". But it's not a problem because we don't define anything on main objects usually.
2025-10-14Remove a debug method that is useless nowSatoshi Tagomori
2025-10-09[DOC] Mark `Namespace` debug methods to be "nodoc"Nobuyoshi Nakada
2025-10-07Stop displaying current namespace when it crashedSatoshi Tagomori
To avoid crashes during displaying crash reports.
2025-10-07Add namespace debug methods and assertionsSatoshi Tagomori
2025-10-07Initialize the main namespace after loading builtin librariesSatoshi Tagomori
* For having the common set of loaded libraries between root and main namespaces * To have the consistent $LOADED_FEATURES in the main namespace
2025-10-07ns_id of main is already initialized in Namespace.newSatoshi Tagomori
2025-09-29[DOC] Mark `Namespace` debug methods to be "nodoc"yui-knk
These methods are debug methods and no RDoc is provided. Mark these methods as "nodoc" to fix "Miscellaneous checks" CI job. Failed CI job: https://github.com/ruby/ruby/actions/runs/18081591948/job/51445635741
2025-09-29Add methods for debugging only when RUBY_DEBUGSatoshi Tagomori
2025-09-29calling free() here causes free for un-malloced memorySatoshi Tagomori
2025-09-29re-implement free/memsize for rb_namespace_t correctlySatoshi Tagomori
2025-09-29delete unused codeSatoshi Tagomori
2025-09-29Stop using C23 spec: initialization with an empty structSatoshi Tagomori
2025-09-29Update Namespace#eval to use control frames instead of namespace_push/popSatoshi Tagomori
With this change, the argument code of Namespace#eval cannot refer local variables around the calling line, but it should not be able to refer these values. The code is evaluated in the receiver namespace, independently from the local context.
2025-09-29Skip CFUNC frames in the current namespace detectionSatoshi Tagomori
* The current namespace should be based on the Ruby-level location (file, line no in .rb) and we can get it by LEP(ep) basically (VM_ENV_FLAG_LOCAL flag is set) * But the control frame with VM_FRAME_MAGIC_CFUNC is also a LOCAL frame because it's a visible Ruby-level frame without block handlers * So, for the namespace detection, LEP(ep) is not enough and we need to skip CFUNC frames to fetch the caller of such frames
2025-09-29Define a debug method Kernel#dump_classext only when RUBY_DEBUG is setSatoshi Tagomori
2025-09-29Follow the usual naming rule for singleton methodsSatoshi Tagomori
2025-09-29Fix wrong way to check an object is an instance of rb_cNamespaceSatoshi Tagomori
2025-09-29There is no longer needs to evict ivars thanks to fieldsSatoshi Tagomori
See 8b5ac5abf258270b32ef63a6acb4eb0d191f79d9
2025-09-29Fix Namespace.current to show its caller's namespaceSatoshi Tagomori
Calling rb_current_namespace() in rb_namespace_current() means to show the definition namespace of Namespace.current itself (it's the root always) but the users' expectation is to show the namespace of the place where the Namespace.current is called.
2025-09-29Update current namespace management by using control frames and lexical contextsSatoshi Tagomori
to fix inconsistent and wrong current namespace detections. This includes: * Moving load_path and related things from rb_vm_t to rb_namespace_t to simplify accessing those values via namespace (instead of accessing either vm or ns) * Initializing root_namespace earlier and consolidate builtin_namespace into root_namespace * Adding VM_FRAME_FLAG_NS_REQUIRE for checkpoints to detect a namespace to load/require files * Removing implicit refinements in the root namespace which was used to determine the namespace to be loaded (replaced by VM_FRAME_FLAG_NS_REQUIRE) * Removing namespaces from rb_proc_t because its namespace can be identified by lexical context * Starting to use ep[VM_ENV_DATA_INDEX_SPECVAL] to store the current namespace when the frame type is MAGIC_TOP or MAGIC_CLASS (block handlers don't exist in this case)
2025-09-13Stop at max dlext sizeNobuyoshi Nakada
2025-09-13Get rid of `strcpy`Nobuyoshi Nakada
On OpenBSD: ``` ld: warning: namespace.c:731(namespace.o:(rb_namespace_local_extension)): warning: strcpy() is almost always misused, please use strlcpy() ```
2025-08-04[DOC] Fill undocumented documentsNobuyoshi Nakada
2025-07-26Adjust indents [ci skip]Nobuyoshi Nakada
2025-06-26Introduce Namespace#evalAaron Patterson
This commit adds an `eval` method to `Namespace` that takes a string and evaluates the string as Ruby code within the context of that namespace. For example: ```ruby n = Namespace.new n.eval("class TestClass; def hello; 'from namespace'; end; end") instance = n::TestClass.new instance.hello # => "from namespace" ``` [Feature #21365]
2025-06-23Mark RClass instance that may be namespaced with RCLASS_NAMESPACEABLEJean Boussier
2025-06-23Optimize `rb_namespace_available`Jean Boussier
Rather than to lazily check the env using a trinary value, we can more straightforwardly check for the env during the VM boot. This allow `rb_namespace_available` to just be a pointer dereference.
2025-06-12Fix class instance variable inside namespacesJean Boussier
Now that classes fields are delegated to an object with its own shape_id, we no longer need to mark all classes as TOO_COMPLEX. Notes: Merged: https://github.com/ruby/ruby/pull/13595
2025-06-07Delete useless Namespace#current_detailsSatoshi Tagomori
The implementation of Namespace#current_details shows warning about use of snprintf directive arguments (only in gcc environments?). This method will be useless when the current namespace management will be updated. Notes: Merged: https://github.com/ruby/ruby/pull/13554
2025-05-25Use RB_VM_LOCKINGNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13439
2025-05-19Fix typos: misspell -w -error -source=text namespace.cHiroshi SHIBATA
2025-05-13Fix a typoKazuhiro NISHIYAMA
2025-05-13Prevent namespace inspected strings from GCNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13307
2025-05-11Fix -Wmaybe-uninitializedTakashi Kokubun
../namespace.c: In function ‘current_namespace’: ../namespace.c:221:48: warning: ‘proc_ns’ may be used uninitialized [-Wmaybe-uninitialized] 221 | if (permit_calling_builtin || (proc_ns && NAMESPACE_USER_P(proc_ns))) | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../namespace.c:204:31: note: ‘proc_ns’ was declared here 204 | const rb_namespace_t *proc_ns; | ^~~~~~~ In function ‘copy_ext_file’, inlined from ‘rb_namespace_local_extension’ at ../namespace.c:855:18: ../namespace.c:768:21: warning: ‘written’ may be used uninitialized [-Wmaybe-uninitialized] 768 | wrote = fwrite(buffer+written, 1, read-written, dst); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../namespace.c: In function ‘rb_namespace_local_extension’: ../namespace.c:748:25: note: ‘written’ was declared here 748 | size_t read, wrote, written; | ^~~~~~~ In function ‘copy_ext_file’, inlined from ‘rb_namespace_local_extension’ at ../namespace.c:855:18: ../namespace.c:768:21: warning: ‘read’ may be used uninitialized [-Wmaybe-uninitialized] 768 | wrote = fwrite(buffer+written, 1, read-written, dst); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../namespace.c: In function ‘rb_namespace_local_extension’: ../namespace.c:748:12: note: ‘read’ was declared here 748 | size_t read, wrote, written; | ^~~~
2025-05-11Fix `Namespace#inspect` to display its internal idJean Boussier
2025-05-11RUBY_TYPED_WB_PROTECTED should be specified with write barrier protection on ↵Satoshi Tagomori
this object. https://github.com/tagomoris/ruby/pull/7 RUBY_TYPED_FREE_IMMEDIATELY can be added because namespace_entry_free does no IO nor things to block.
2025-05-11Fix `namespace_initialize` to not crash on bootJean Boussier
``` /opt/rubies/head-namespaces/bin/ruby(sigsegv+0x84) [0x104e897e8] /usr/lib/system/libsystem_platform.dylib(_sigtramp+0x38) [0x18de56de4] /opt/rubies/head-namespaces/bin/ruby(object_id+0x80) [0x104d7d420] /opt/rubies/head-namespaces/bin/ruby(object_id+0x80) [0x104d7d420] /opt/rubies/head-namespaces/bin/ruby(rb_initialize_main_namespace+0xe4) [0x104ddaa20] /opt/rubies/head-namespaces/bin/ruby(ruby_opt_init+0x120) [0x104e7f524] /opt/rubies/head-namespaces/bin/ruby(ruby_process_options+0x1370) [0x104e7e31c] /opt/rubies/head-namespaces/bin/ruby(ruby_options+0xb0) [0x104d69844] /opt/rubies/head-namespaces/bin/ruby(main+0x64) [0x104ca8d54] ``` I'm not too sure why `rb_obj_id` crashes, but I suspect it's called too early. Either way I don't think generating an object_id for namespaces is a good idea. If all we need is a unique number we can do that for much cheaper.