aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-13 05:51:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-13 05:51:14 +0000
commit3dbf227ed0423c71e5a3f9b2952dcd8a1b3ccc58 (patch)
treeebf06c792f5262ffd9164fa946f0bb6ddea1d127 /include
parent0e76c1408517b943a855240489c1afdb502284dc (diff)
downloadruby-3dbf227ed0423c71e5a3f9b2952dcd8a1b3ccc58.tar.gz
ruby.h: safe_level check
* include/ruby/ruby.h (RUBY_SAFE_LEVEL_CHECK): check constant safe level at compile time. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r--include/ruby/ruby.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 18539e8548..4ec4e7f192 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -556,9 +556,20 @@ VALUE rb_get_path(VALUE);
VALUE rb_get_path_no_checksafe(VALUE);
#define FilePathStringValue(v) ((v) = rb_get_path_no_checksafe(v))
+#define RUBY_SAFE_LEVEL_MAX 3
void rb_secure(int);
int rb_safe_level(void);
void rb_set_safe_level(int);
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+int ruby$safe_level$4(void) __attribute__((error("$SAFE=4 is obsolete")));
+#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) \
+ (RUBY_SAFE_LEVEL_INVALID_P(level) ? ruby$safe_level$4() : 0)
+#define rb_secure(level) (RUBY_SAFE_LEVEL_CHECK(level), rb_secure(level))
+#define rb_set_safe_level(level) (RUBY_SAFE_LEVEL_CHECK(level), rb_set_safe_level(level))
+#endif
void rb_set_safe_level_force(int);
void rb_secure_update(VALUE);
NORETURN(void rb_insecure_operation(void));