summaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-25 14:45:47 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-25 14:45:47 +0000
commit78ef4198f400cd2c6ddd28353531aaba996b6697 (patch)
treebbd266343c5cc2c1ec4d1e26897f01a34db5f0bd /variable.c
parent13fee949b6b8905a0a64b8ad6879c0f573243c4a (diff)
downloadruby-78ef4198f400cd2c6ddd28353531aaba996b6697.tar.gz
ruby-78ef4198f400cd2c6ddd28353531aaba996b6697.tar.xz
ruby-78ef4198f400cd2c6ddd28353531aaba996b6697.zip
merges r24488, r24489 and r24493 from trunk into ruby_1_9_1.
-- * marshal.c (class2path, w_unique, w_extended, w_class, w_uclass): deal with non-ascii class path. [ruby-core:24790] * marshal.c (r_unique, path2class, path2module, obj_alloc_by_path), (r_object0): ditto. * variable.c (rb_path_to_class): new encoding-aware function to get a class from its name. -- * marshal.c (must_not_be_anonymous): fixed silly miss. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@25474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/variable.c b/variable.c
index 03efd1de1..a7f8fe7a6 100644
--- a/variable.c
+++ b/variable.c
@@ -14,6 +14,7 @@
#include "ruby/ruby.h"
#include "ruby/st.h"
#include "ruby/util.h"
+#include "ruby/encoding.h"
#include "node.h"
void rb_vm_change_state(void);
@@ -246,19 +247,23 @@ rb_set_class_path(VALUE klass, VALUE under, const char *name)
}
VALUE
-rb_path2class(const char *path)
+rb_path_to_class(VALUE pathname)
{
- const char *pbeg, *p;
+ rb_encoding *enc = rb_enc_get(pathname);
+ const char *pbeg, *p, *path = RSTRING_PTR(pathname);
ID id;
VALUE c = rb_cObject;
+ if (!rb_enc_asciicompat(enc)) {
+ rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
+ }
+ pbeg = p = path;
if (path[0] == '#') {
rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path);
}
- pbeg = p = path;
while (*p) {
while (*p && *p != ':') p++;
- id = rb_intern2(pbeg, p-pbeg);
+ id = rb_intern3(pbeg, p-pbeg, enc);
if (p[0] == ':') {
if (p[1] != ':') goto undefined_class;
p += 2;
@@ -281,6 +286,12 @@ rb_path2class(const char *path)
return c;
}
+VALUE
+rb_path2class(const char *path)
+{
+ return rb_path_to_class(rb_usascii_str_new_cstr(path));
+}
+
void
rb_name_class(VALUE klass, ID id)
{