ruby-changes:59774
From: Jeremy <ko1@a...>
Date: Thu, 23 Jan 2020 02:10:15 +0900 (JST)
Subject: [ruby-changes:59774] e91c39f1c0 (master): Remove special handling of $SAFE and related C-APIs
https://git.ruby-lang.org/ruby.git/commit/?id=e91c39f1c0 From e91c39f1c0f7d5e670266d9593d533fd444957f6 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Fri, 17 Jan 2020 11:36:52 -0800 Subject: Remove special handling of $SAFE and related C-APIs These were all deprecated in Ruby 2.7. diff --git a/NEWS.md b/NEWS.md index 4485a64..51d9dc7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,8 @@ sufficient information, see the ChangeLog file or Redmine https://github.com/ruby/ruby/blob/trunk/NEWS.md#L10 ## Language changes +* $SAFE is now a normal global variable with no special behavior. [Feature #16131] + ## Command line options ## Core classes updates (outstanding ones only) diff --git a/bootstraptest/test_proc.rb b/bootstraptest/test_proc.rb index 1e38441..6d2c557 100644 --- a/bootstraptest/test_proc.rb +++ b/bootstraptest/test_proc.rb @@ -225,19 +225,6 @@ assert_equal %q{[[nil, []], [1, []], [1, [2]], [1, [2, 3]]]}, %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_proc.rb#L225 ] } assert_equal %q{1}, %q{ - pr = proc{ - $SAFE - } - $SAFE = 1 - pr.call -} -assert_equal %q{[1, 1]}, %q{ - pr = proc{ - $SAFE += 1 - } - [pr.call, $SAFE] -} -assert_equal %q{1}, %q{ def m(&b) b end diff --git a/common.mk b/common.mk index 86ec9c5..b685e8f 100644 --- a/common.mk +++ b/common.mk @@ -127,7 +127,6 @@ COMMONOBJS = array.$(OBJEXT) \ https://github.com/ruby/ruby/blob/trunk/common.mk#L127 regparse.$(OBJEXT) \ regsyntax.$(OBJEXT) \ ruby.$(OBJEXT) \ - safe.$(OBJEXT) \ signal.$(OBJEXT) \ sprintf.$(OBJEXT) \ st.$(OBJEXT) \ @@ -3570,39 +3569,6 @@ ruby.$(OBJEXT): {$(VPATH)}thread_native.h https://github.com/ruby/ruby/blob/trunk/common.mk#L3569 ruby.$(OBJEXT): {$(VPATH)}util.h ruby.$(OBJEXT): {$(VPATH)}vm_core.h ruby.$(OBJEXT): {$(VPATH)}vm_opts.h -safe.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h -safe.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h -safe.$(OBJEXT): $(CCAN_DIR)/list/list.h -safe.$(OBJEXT): $(CCAN_DIR)/str/str.h -safe.$(OBJEXT): $(hdrdir)/ruby.h -safe.$(OBJEXT): $(hdrdir)/ruby/ruby.h -safe.$(OBJEXT): $(top_srcdir)/internal/array.h -safe.$(OBJEXT): $(top_srcdir)/internal/compilers.h -safe.$(OBJEXT): $(top_srcdir)/internal/gc.h -safe.$(OBJEXT): $(top_srcdir)/internal/imemo.h -safe.$(OBJEXT): $(top_srcdir)/internal/serial.h -safe.$(OBJEXT): $(top_srcdir)/internal/static_assert.h -safe.$(OBJEXT): $(top_srcdir)/internal/stdbool.h -safe.$(OBJEXT): $(top_srcdir)/internal/vm.h -safe.$(OBJEXT): $(top_srcdir)/internal/warnings.h -safe.$(OBJEXT): {$(VPATH)}assert.h -safe.$(OBJEXT): {$(VPATH)}config.h -safe.$(OBJEXT): {$(VPATH)}defines.h -safe.$(OBJEXT): {$(VPATH)}id.h -safe.$(OBJEXT): {$(VPATH)}intern.h -safe.$(OBJEXT): {$(VPATH)}internal.h -safe.$(OBJEXT): {$(VPATH)}method.h -safe.$(OBJEXT): {$(VPATH)}missing.h -safe.$(OBJEXT): {$(VPATH)}node.h -safe.$(OBJEXT): {$(VPATH)}ruby_assert.h -safe.$(OBJEXT): {$(VPATH)}ruby_atomic.h -safe.$(OBJEXT): {$(VPATH)}safe.c -safe.$(OBJEXT): {$(VPATH)}st.h -safe.$(OBJEXT): {$(VPATH)}subst.h -safe.$(OBJEXT): {$(VPATH)}thread_$(THREAD_MODEL).h -safe.$(OBJEXT): {$(VPATH)}thread_native.h -safe.$(OBJEXT): {$(VPATH)}vm_core.h -safe.$(OBJEXT): {$(VPATH)}vm_opts.h setproctitle.$(OBJEXT): $(hdrdir)/ruby.h setproctitle.$(OBJEXT): $(hdrdir)/ruby/ruby.h setproctitle.$(OBJEXT): {$(VPATH)}assert.h diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index ada86da..6086b46 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -626,42 +626,6 @@ VALUE rb_get_path(VALUE); https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L626 VALUE rb_get_path_no_checksafe(VALUE); #define FilePathStringValue(v) ((v) = rb_get_path(v)) -/* Remove in 3.0 */ -#define RUBY_SAFE_LEVEL_MAX 1 -void rb_secure(int); -int rb_safe_level(void); -void rb_set_safe_level(int); -#if GCC_VERSION_SINCE(4,4,0) -int ruby_safe_level_2_error(void) __attribute__((error("$SAFE=2 to 4 are obsolete"))); -int ruby_safe_level_2_warning(void) __attribute__((const,warning("$SAFE=2 to 4 are obsolete"))); -# ifdef RUBY_EXPORT -# define ruby_safe_level_2_warning() ruby_safe_level_2_error() -# endif -# if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) -# define RUBY_SAFE_LEVEL_INVALID_P(level) \ - __extension__(\ - __builtin_choose_expr(\ - __builtin_constant_p(level), \ - ((level) < 0 || RUBY_SAFE_LEVEL_MAX < (level)), 0)) -# define RUBY_SAFE_LEVEL_CHECK(level, type) \ - __extension__(__builtin_choose_expr(RUBY_SAFE_LEVEL_INVALID_P(level), ruby_safe_level_2_##type(), (level))) -# else -/* in gcc 4.8 or earlier, __builtin_choose_expr() does not consider - * __builtin_constant_p(variable) a constant expression. - */ -# define RUBY_SAFE_LEVEL_INVALID_P(level) \ - __extension__(__builtin_constant_p(level) && \ - ((level) < 0 || RUBY_SAFE_LEVEL_MAX < (level))) -# define RUBY_SAFE_LEVEL_CHECK(level, type) \ - (RUBY_SAFE_LEVEL_INVALID_P(level) ? ruby_safe_level_2_##type() : (level)) -# endif -# define rb_secure(level) rb_secure(RUBY_SAFE_LEVEL_CHECK(level, warning)) -# define rb_set_safe_level(level) rb_set_safe_level(RUBY_SAFE_LEVEL_CHECK(level, error)) -#endif -void rb_set_safe_level_force(int); -void rb_secure_update(VALUE); -NORETURN(void rb_insecure_operation(void)); - VALUE rb_errinfo(void); void rb_set_errinfo(VALUE); diff --git a/inits.c b/inits.c index b313d1d..91c916d 100644 --- a/inits.c +++ b/inits.c @@ -37,7 +37,6 @@ rb_call_inits(void) https://github.com/ruby/ruby/blob/trunk/inits.c#L37 CALL(String); CALL(Exception); CALL(eval); - CALL(safe); CALL(jump); CALL(Numeric); CALL(Bignum); diff --git a/safe.c b/safe.c deleted file mode 100644 index a6b4905..0000000 --- a/safe.c +++ /dev/null @@ -1,145 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/inits.c#L0 -/********************************************************************** - - safe.c - - - $Author$ - created at: Tue Sep 23 09:44:32 JST 2008 - - Copyright (C) 2008 Yukihiro Matsumoto - -**********************************************************************/ - -#define SAFE_LEVEL_MAX RUBY_SAFE_LEVEL_MAX - -#include "ruby/ruby.h" -#include "vm_core.h" - -/* $SAFE accessor */ - -#undef rb_secure -#undef rb_set_safe_level -#undef ruby_safe_level_2_warning - -int -ruby_safe_level_2_warning(void) -{ - rb_warn("rb_safe_level_2_warning will be removed in Ruby 3.0"); - return 2; -} - -int -rb_safe_level(void) -{ - rb_warn("rb_safe_level will be removed in Ruby 3.0"); - return GET_VM()->safe_level_; -} - -void -rb_set_safe_level_force(int safe) -{ - rb_warn("rb_set_safe_level_force will be removed in Ruby 3.0"); - GET_VM()->safe_level_ = safe; -} - -void -rb_set_safe_level(int level) -{ - rb_vm_t *vm = GET_VM(); - - rb_warn("rb_set_safe_level will be removed in Ruby 3.0"); - if (level > SAFE_LEVEL_MAX) { - rb_raise(rb_eArgError, "$SAFE=2 to 4 are obsolete"); - } - else if (level < 0) { - rb_raise(rb_eArgError, "$SAFE should be >= 0"); - } - else { - int line; - const char *path = rb_source_location_cstr(&line); - - if (0) fprintf(stderr, "%s:%d $SAFE %d -> %d\n", - path ? path : "-", line, vm->safe_level_, level); - - vm->safe_level_ = level; - } -} - -static VALUE -safe_getter(ID _x, VALUE *_y) -{ - rb_warn("$SAFE will become a normal global variable in Ruby 3.0"); - return INT2NUM(GET_VM()->safe_level_); -} - -static void -safe_setter(VALUE val, ID _x, VALUE *_y) -{ - int level = NUM2INT(val); - rb_vm_t *vm = GET_VM(); - - rb_warn("$SAFE will become a normal global variable in Ruby 3.0"); - if (level > SAFE_LEVEL_MAX) { - rb_raise(rb_eArgError, "$SAFE=2 to 4 are obsolete"); - } - else if (level < 0) { - rb_raise(rb_eArgError, "$SAFE should be >= 0"); - } - else { - int line; - const char *path = rb_source_location_cstr(&line); - - if (0) fprintf(stderr, "%s:%d $SAFE %d -> %d\n", - path ? path : "-", line, vm->safe_level_, level); - - vm->safe_level_ = level; - } -} - -void -rb_secure(int level) -{ - rb_warn("rb_secure will be removed in Ruby 3.0"); - if (level <= GET_VM()->safe_level_) { - ID caller_name = rb_frame_callee(); - if (caller_name) { - rb_raise(rb_eSecurityError, "Insecure operation `%"PRIsVALUE"' at level %d", - rb_id2str(caller_name), GET_VM()->safe_level_); - } - else { - rb_raise(rb_eSecurityError, "Insecure operation at level %d", - GET_VM()->safe_level_); - } - } -} - -void -rb_secure_update(VALUE obj) -{ - rb_warn("rb_secure_update will be removed in Ruby 3.0"); -} - -void -rb_insecure_operation(void) -{ - rb_warn("rb_insecure_operation will be removed in Ruby 3.0"); - ID caller_name = rb_frame_callee(); - if (caller_name) { - rb_raise(rb_eSecurityError, "Insecure operation - %"PRIsVALUE, - rb_id2str(caller_name)); - } - else { - rb_raise(rb_eSecurityError, "Insecure operation: -r"); - } -} - -void -rb_check_safe_obj(VALUE x) -{ - rb_warn("rb_check_safe_obj will be removed in Ruby 3.0"); -} - -void -Init_safe(void) -{ - rb_define_virtual_variable("$SAFE", safe_getter, safe_setter); -} -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/