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

ruby-changes:51155

From: shyouhei <ko1@a...>
Date: Wed, 9 May 2018 11:36:40 +0900 (JST)
Subject: [ruby-changes:51155] shyouhei:r63362 (trunk): RSTRING_PTR is not guaranteed to be VALUE-aligned

shyouhei	2018-05-09 11:36:34 +0900 (Wed, 09 May 2018)

  New Revision: 63362

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

  Log:
    RSTRING_PTR is not guaranteed to be VALUE-aligned
    
    Don't abuse struct RString to hold arbitrary memory region.
    use rb_alloc_tmp_buffer for that purpose.

  Modified files:
    trunk/iseq.h
Index: iseq.h
===================================================================
--- iseq.h	(revision 63361)
+++ iseq.h	(revision 63362)
@@ -46,23 +46,25 @@ ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t https://github.com/ruby/ruby/blob/trunk/iseq.h#L46
 static inline VALUE *
 ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
 {
-    VALUE str = iseq->body->variable.original_iseq;
-    if (RTEST(str)) return (VALUE *)RSTRING_PTR(str);
+    rb_imemo_alloc_t *str = (void *)iseq->body->variable.original_iseq;
+    if (RTEST(str)) return str->ptr;
     return NULL;
 }
 
 static inline void
 ISEQ_ORIGINAL_ISEQ_CLEAR(const rb_iseq_t *iseq)
 {
-    RB_OBJ_WRITE(iseq, &iseq->body->variable.original_iseq, Qnil);
+    rb_free_tmp_buffer(&iseq->body->variable.original_iseq);
+    RB_OBJ_WRITE(iseq, &iseq->body->variable.original_iseq, Qfalse);
 }
 
 static inline VALUE *
 ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
 {
-    VALUE str = rb_str_tmp_new(size * sizeof(VALUE));
+    VALUE str;
+    VALUE *ptr = rb_alloc_tmp_buffer_with_count(&str, sizeof(VALUE), size);
     RB_OBJ_WRITE(iseq, &iseq->body->variable.original_iseq, str);
-    return (VALUE *)RSTRING_PTR(str);
+    return ptr;
 }
 
 #define ISEQ_TRACE_EVENTS (RUBY_EVENT_LINE  | \

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

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