Show experimental warning when namespace is enabled

This commit is contained in:
Satoshi Tagomori 2025-05-09 00:32:30 +09:00
parent 8ecc04dc04
commit 8199e6e1a6
4 changed files with 30 additions and 2 deletions

View File

@ -11041,6 +11041,7 @@ namespace.$(OBJEXT): $(top_srcdir)/internal/array.h
namespace.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h
namespace.$(OBJEXT): $(top_srcdir)/internal/class.h
namespace.$(OBJEXT): $(top_srcdir)/internal/compilers.h
namespace.$(OBJEXT): $(top_srcdir)/internal/error.h
namespace.$(OBJEXT): $(top_srcdir)/internal/eval.h
namespace.$(OBJEXT): $(top_srcdir)/internal/file.h
namespace.$(OBJEXT): $(top_srcdir)/internal/gc.h
@ -11053,6 +11054,7 @@ namespace.$(OBJEXT): $(top_srcdir)/internal/serial.h
namespace.$(OBJEXT): $(top_srcdir)/internal/set_table.h
namespace.$(OBJEXT): $(top_srcdir)/internal/st.h
namespace.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
namespace.$(OBJEXT): $(top_srcdir)/internal/string.h
namespace.$(OBJEXT): $(top_srcdir)/internal/variable.h
namespace.$(OBJEXT): $(top_srcdir)/internal/vm.h
namespace.$(OBJEXT): $(top_srcdir)/internal/warnings.h

16
doc/namespace.md Normal file
View File

@ -0,0 +1,16 @@
# Namespace - Ruby's in-process separation of Classes and Modules
Namespace is designed to provide separated spaces in a Ruby process, to isolate applications and libraries.
## Known issues
* Experimental warning is shown when ruby starts with `RUBY_NAMESPACE=1` (specify `-W:no-experimental` command line option to hide it)
## TODOs
## How to use
## Summary
## Specs

View File

@ -4,12 +4,12 @@
#include "ruby/ruby.h" /* for VALUE */
/**
* @author Satoshi Tagomori <tagomoris@gmail.com>
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @brief Internal header for Fiber.
* @brief Internal header for Namespace.
*/
struct rb_namespace_struct {
/*

View File

@ -3,6 +3,7 @@
#include "internal.h"
#include "internal/class.h"
#include "internal/eval.h"
#include "internal/error.h"
#include "internal/file.h"
#include "internal/gc.h"
#include "internal/hash.h"
@ -960,6 +961,8 @@ rb_namespace_require_relative(VALUE namespace, VALUE fname)
return rb_ensure(rb_require_relative_entrypoint, fname, namespace_both_pop, (VALUE)&arg);
}
static int namespace_experimental_warned = 0;
void
rb_initialize_main_namespace(void)
{
@ -968,6 +971,13 @@ rb_initialize_main_namespace(void)
rb_thread_t *th = GET_THREAD();
VALUE main_ns;
if (!namespace_experimental_warned) {
rb_category_warn(RB_WARN_CATEGORY_EXPERIMENTAL,
"Namespace is experimental, and the behavior may change in the future!\n"
"See doc/namespace.md for know issues, etc.");
namespace_experimental_warned = 1;
}
main_ns = rb_class_new_instance_pass_kw(0, NULL, rb_cNamespace);
ns = rb_get_namespace_t(main_ns);
ns->ns_object = main_ns;