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

ruby-changes:51166

From: shyouhei <ko1@a...>
Date: Wed, 9 May 2018 16:46:17 +0900 (JST)
Subject: [ruby-changes:51166] shyouhei:r63373 (trunk): RSTRING_PTR is not guaranteed to be VALUE-aligned

shyouhei	2018-05-09 16:46:11 +0900 (Wed, 09 May 2018)

  New Revision: 63373

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

  Log:
    RSTRING_PTR is not guaranteed to be VALUE-aligned
    
    Don't abuse struct RString to hold arbitrary memory region.
    Thanks to @mame we now have rb_imemo_alloc_auto_free_pointer
    so use it instead.

  Modified files:
    trunk/process.c
Index: process.c
===================================================================
--- process.c	(revision 63372)
+++ process.c	(revision 63373)
@@ -2355,6 +2355,16 @@ open_func(void *ptr) https://github.com/ruby/ruby/blob/trunk/process.c#L2355
     return NULL;
 }
 
+static void
+rb_execarg_allocate_dup2_tmpbuf(struct rb_execarg *eargp, long len)
+{
+    eargp->dup2_tmpbuf =
+        rb_imemo_tmpbuf_auto_free_pointer(
+            ruby_xmalloc(
+                run_exec_dup2_tmpbuf_size(
+                    len)));
+}
+
 static VALUE
 rb_execarg_parent_start1(VALUE execarg_obj)
 {
@@ -2409,10 +2419,7 @@ rb_execarg_parent_start1(VALUE execarg_o https://github.com/ruby/ruby/blob/trunk/process.c#L2419
 
     ary = eargp->fd_dup2;
     if (ary != Qfalse) {
-        size_t len = run_exec_dup2_tmpbuf_size(RARRAY_LEN(ary));
-        VALUE tmpbuf = hide_obj(rb_str_new(0, len));
-        rb_str_set_len(tmpbuf, len);
-        eargp->dup2_tmpbuf = tmpbuf;
+        rb_execarg_allocate_dup2_tmpbuf(eargp, RARRAY_LEN(ary));
     }
 
     unsetenv_others = eargp->unsetenv_others_given && eargp->unsetenv_others_do;
@@ -2775,10 +2782,10 @@ run_exec_dup2(VALUE ary, VALUE tmpbuf, s https://github.com/ruby/ruby/blob/trunk/process.c#L2782
     long n, i;
     int ret;
     int extra_fd = -1;
-    struct run_exec_dup2_fd_pair *pairs = 0;
+    struct rb_imemo_tmpbuf_struct *buf = (void *)tmpbuf;
+    struct run_exec_dup2_fd_pair *pairs = (void *)buf->ptr;
 
     n = RARRAY_LEN(ary);
-    pairs = (struct run_exec_dup2_fd_pair *)RSTRING_PTR(tmpbuf);
 
     /* initialize oldfd and newfd: O(n) */
     for (i = 0; i < n; i++) {
@@ -3155,10 +3162,7 @@ rb_execarg_run_options(const struct rb_e https://github.com/ruby/ruby/blob/trunk/process.c#L3162
     if (sargp) {
         VALUE ary = sargp->fd_dup2;
         if (ary != Qfalse) {
-            size_t len = run_exec_dup2_tmpbuf_size(RARRAY_LEN(ary));
-            VALUE tmpbuf = hide_obj(rb_str_new(0, len));
-            rb_str_set_len(tmpbuf, len);
-            sargp->dup2_tmpbuf = tmpbuf;
+            rb_execarg_allocate_dup2_tmpbuf(sargp, RARRAY_LEN(ary));
         }
     }
 

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

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