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

ruby-changes:34545

From: nobu <ko1@a...>
Date: Mon, 30 Jun 2014 23:59:50 +0900 (JST)
Subject: [ruby-changes:34545] nobu:r46626 (trunk): string.c: rb_fstring_new

nobu	2014-06-30 23:59:44 +0900 (Mon, 30 Jun 2014)

  New Revision: 46626

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

  Log:
    string.c: rb_fstring_new
    
    * string.c (rb_fstring_new): create fstring from pointer and
      length.

  Modified files:
    trunk/internal.h
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 46625)
+++ string.c	(revision 46626)
@@ -225,6 +225,27 @@ rb_fstring(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L225
     return fstr;
 }
 
+static VALUE
+setup_fake_str(struct RString *fake_str, const char *name, long len)
+{
+    fake_str->basic.flags = T_STRING|RSTRING_NOEMBED|ELTS_SHARED;
+    /* SHARED to be allocated by the callback */
+
+    RBASIC_SET_CLASS((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;
+}
+
+VALUE
+rb_fstring_new(const char *ptr, long len)
+{
+    struct RString fake_str;
+
+    return rb_fstring(setup_fake_str(&fake_str, ptr, len));
+}
+
 static int
 fstring_set_class_i(st_data_t key, st_data_t val, st_data_t arg)
 {
Index: internal.h
===================================================================
--- internal.h	(revision 46625)
+++ internal.h	(revision 46626)
@@ -899,6 +899,7 @@ size_t rb_strftime(char *s, size_t maxsi https://github.com/ruby/ruby/blob/trunk/internal.h#L899
 
 /* string.c */
 VALUE rb_fstring(VALUE);
+VALUE rb_fstring_new(const char *ptr, long len);
 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/

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