summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro Matz Matsumoto <[email protected]>2012-12-03 23:35:37 +0900
committerYukihiro Matz Matsumoto <[email protected]>2012-12-03 23:35:37 +0900
commit674c55eb7d0a4338d4500516b6a3e9aba56ee61e (patch)
treef73382eedd534560c090bfee36f2f67b4bf8fb60 /src
parent30d7c60cfd124cb86e9691f1d87f3478957afd4d (diff)
parent25153d204d3800cbd302c83cf8e9798677af40ba (diff)
downloadmruby-674c55eb7d0a4338d4500516b6a3e9aba56ee61e.tar.gz
mruby-674c55eb7d0a4338d4500516b6a3e9aba56ee61e.zip
Merge branch 'master' of github.com:mruby/mruby
Diffstat (limited to 'src')
-rw-r--r--src/class.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/class.c b/src/class.c
index 618a6d1f6..dcd0ae492 100644
--- a/src/class.c
+++ b/src/class.c
@@ -7,6 +7,7 @@
#include "mruby.h"
#include <stdarg.h>
#include <stdio.h>
+#include <ctype.h>
#include "mruby/class.h"
#include "mruby/proc.h"
#include "mruby/string.h"
@@ -1442,11 +1443,25 @@ mrb_sym_value(mrb_state *mrb, mrb_value val)
return mrb_symbol(val);
}
+static void
+check_const_name(mrb_state *mrb, mrb_sym id)
+{
+ const char *s;
+ int len;
+
+ s = mrb_sym2name_len(mrb, id, &len);
+ if (len < 1 || !ISUPPER(*s)) {
+ mrb_name_error(mrb, id, "wrong constant name %s", s);
+ }
+}
+
mrb_value
mrb_mod_const_defined(mrb_state *mrb, mrb_value mod)
{
mrb_value sym;
mrb_get_args(mrb, "o", &sym);
+
+ check_const_name(mrb, mrb_sym_value(mrb,sym));
if(mrb_const_defined(mrb, mod, mrb_sym_value(mrb, sym))) {
return mrb_true_value();
}
@@ -1458,6 +1473,8 @@ mrb_mod_const_get(mrb_state *mrb, mrb_value mod)
{
mrb_value sym;
mrb_get_args(mrb, "o", &sym);
+
+ check_const_name(mrb, mrb_sym_value(mrb,sym));
return mrb_const_get(mrb, mod, mrb_sym_value(mrb, sym));
}
@@ -1466,6 +1483,8 @@ mrb_mod_const_set(mrb_state *mrb, mrb_value mod)
{
mrb_value sym, value;
mrb_get_args(mrb, "oo", &sym, &value);
+
+ check_const_name(mrb, mrb_sym_value(mrb,sym));
mrb_const_set(mrb, mod, mrb_sym_value(mrb, sym), value);
return value;
}