summaryrefslogtreecommitdiff
path: root/ext/-test-/symbol
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-20 06:01:57 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-20 06:01:57 +0000
commitaba824fece59d1afffa78d145a4f301f7fdc3688 (patch)
tree89173d1abb36ebd286ea8f1bbb33fad496a4b0f3 /ext/-test-/symbol
parent035917adc127083ac851394e56ba3636b58e4823 (diff)
parse.y: junk sigil only names
* parse.y (intern_str): sigil only names are junk, at least one identifier character is needed. [ruby-dev:47723] [Bug #8928] * parse.y (rb_enc_symname_type): fix out of bound access. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-/symbol')
-rw-r--r--ext/-test-/symbol/type.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/ext/-test-/symbol/type.c b/ext/-test-/symbol/type.c
new file mode 100644
index 0000000..37406d3
--- /dev/null
+++ b/ext/-test-/symbol/type.c
@@ -0,0 +1,34 @@
+#include "ruby.h"
+
+#ifdef HAVE_RB_IS_CONST_NAME
+# define get_symbol_type(type, t, name) do { \
+ ID id = rb_check_id(&name); \
+ t = (id ? rb_is_##type##_id(id) : rb_is_##type##_name(name)); \
+ } while (0)
+#else
+# define get_symbol_type(type, t, name) do { \
+ t = rb_is_##type##_id(rb_to_id(name)); \
+ } while (0)
+#endif
+
+#define define_symbol_type_p(type) \
+static VALUE \
+bug_sym_##type##_p(VALUE self, VALUE name) \
+{ \
+ int t; \
+ get_symbol_type(type, t, name); \
+ return (t ? Qtrue : Qfalse); \
+}
+
+#define declare_symbol_type_p(type) \
+ rb_define_singleton_method(klass, #type"?", bug_sym_##type##_p, 1);
+
+#define FOREACH_ID_TYPES(x) x(const) x(class) x(global) x(instance) x(attrset) x(local) x(junk)
+
+FOREACH_ID_TYPES(define_symbol_type_p)
+
+void
+Init_type(VALUE klass)
+{
+ FOREACH_ID_TYPES(declare_symbol_type_p)
+}