[前][次][番号順一覧][スレッド一覧]

ruby-changes:35116

From: nobu <ko1@a...>
Date: Sat, 16 Aug 2014 12:36:53 +0900 (JST)
Subject: [ruby-changes:35116] nobu:r47198 (trunk): string.c: rb_setup_fake_str

nobu	2014-08-16 12:36:47 +0900 (Sat, 16 Aug 2014)

  New Revision: 47198

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47198

  Log:
    string.c: rb_setup_fake_str
    
    * string.c (rb_setup_fake_str): setup fake string from C pointer,
      length, and encoding.

  Modified files:
    trunk/internal.h
    trunk/string.c
    trunk/symbol.c
Index: symbol.c
===================================================================
--- symbol.c	(revision 47197)
+++ symbol.c	(revision 47198)
@@ -411,17 +411,6 @@ must_be_dynamic_symbol(VALUE x) https://github.com/ruby/ruby/blob/trunk/symbol.c#L411
 }
 
 static VALUE
-setup_fake_str(struct RString *fake_str, const char *name, long len)
-{
-    fake_str->basic.flags = T_STRING|RSTRING_NOEMBED;
-    RBASIC_SET_CLASS_RAW((VALUE)fake_str, rb_cString);
-    fake_str->as.heap.len = len;
-    fake_str->as.heap.ptr = (char *)name;
-    fake_str->as.heap.aux.capa = len;
-    return (VALUE)fake_str;
-}
-
-static VALUE
 dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc)
 {
     const VALUE dsym = rb_newobj_of(klass, T_SYMBOL | FL_WB_PROTECTED);
@@ -527,8 +516,7 @@ rb_intern_cstr_without_pindown(const cha https://github.com/ruby/ruby/blob/trunk/symbol.c#L516
 {
     st_data_t id;
     struct RString fake_str;
-    VALUE str = setup_fake_str(&fake_str, name, len);
-    rb_enc_associate(str, enc);
+    VALUE str = rb_setup_fake_str(&fake_str, name, len, enc);
     OBJ_FREEZE(str);
 
     if (st_lookup(global_symbols.str_id, str, &id)) {
@@ -1045,8 +1033,7 @@ rb_check_id_cstr(const char *ptr, long l https://github.com/ruby/ruby/blob/trunk/symbol.c#L1033
 {
     ID id;
     struct RString fake_str;
-    const VALUE name = setup_fake_str(&fake_str, ptr, len);
-    rb_enc_associate(name, enc);
+    const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
 
     sym_check_asciionly(name);
 
@@ -1069,8 +1056,7 @@ rb_check_symbol_cstr(const char *ptr, lo https://github.com/ruby/ruby/blob/trunk/symbol.c#L1056
 {
     VALUE sym;
     struct RString fake_str;
-    const VALUE name = setup_fake_str(&fake_str, ptr, len);
-    rb_enc_associate(name, enc);
+    const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
 
     sym_check_asciionly(name);
 
@@ -1095,8 +1081,9 @@ attrsetname_to_attr(VALUE name) https://github.com/ruby/ruby/blob/trunk/symbol.c#L1081
 	ID id;
 	struct RString fake_str;
 	/* make local name by chopping '=' */
-	const VALUE localname = setup_fake_str(&fake_str, RSTRING_PTR(name), RSTRING_LEN(name) - 1);
-	rb_enc_copy(localname, name);
+	const VALUE localname = rb_setup_fake_str(&fake_str,
+						  RSTRING_PTR(name), RSTRING_LEN(name) - 1,
+						  rb_enc_get(name));
 	OBJ_FREEZE(localname);
 
 	if ((id = lookup_str_id(localname)) != 0) {
Index: string.c
===================================================================
--- string.c	(revision 47197)
+++ string.c	(revision 47198)
@@ -248,6 +248,12 @@ setup_fake_str(struct RString *fake_str, https://github.com/ruby/ruby/blob/trunk/string.c#L248
 }
 
 VALUE
+rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc)
+{
+    return setup_fake_str(fake_str, name, len, rb_enc_to_index(enc));
+}
+
+VALUE
 rb_fstring_new(const char *ptr, long len)
 {
     struct RString fake_str;
Index: internal.h
===================================================================
--- internal.h	(revision 47197)
+++ internal.h	(revision 47198)
@@ -893,6 +893,9 @@ size_t rb_strftime(char *s, size_t maxsi https://github.com/ruby/ruby/blob/trunk/internal.h#L893
 /* string.c */
 VALUE rb_fstring(VALUE);
 VALUE rb_fstring_new(const char *ptr, long len);
+#ifdef RUBY_ENCODING_H
+VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc);
+#endif
 int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
 int rb_str_symname_p(VALUE);
 VALUE rb_str_quote_unprintable(VALUE);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]