ruby-changes:46537
From: nobu <ko1@a...>
Date: Thu, 11 May 2017 08:18:13 +0900 (JST)
Subject: [ruby-changes:46537] nobu:r58658 (trunk): process.c: temporary string for buffer
nobu 2017-05-11 08:18:07 +0900 (Thu, 11 May 2017) New Revision: 58658 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58658 Log: process.c: temporary string for buffer * process.c (obj2uid, obj2gid): use temporary string as the buffer instead of `rb_alloc_tmp_buffer`, which is `NODE_ALLOCA` since r51492. [ruby-core:81084] [Bug #13554] Modified files: trunk/process.c Index: process.c =================================================================== --- process.c (revision 58657) +++ process.c (revision 58658) @@ -172,7 +172,7 @@ static void check_gid_switch(void); https://github.com/ruby/ruby/blob/trunk/process.c#L172 # define PREPARE_GETPWNAM \ VALUE getpw_buf = 0 # define FINISH_GETPWNAM \ - ALLOCV_END(getpw_buf) + (getpw_buf ? (void)rb_str_resize(getpw_buf, 0) : (void)0) # define OBJ2UID1(id) obj2uid((id), &getpw_buf) # define OBJ2UID(id) obj2uid0(id) static rb_uid_t obj2uid(VALUE id, VALUE *getpw_buf); @@ -214,7 +214,7 @@ static rb_uid_t obj2uid(VALUE id); https://github.com/ruby/ruby/blob/trunk/process.c#L214 # define PREPARE_GETGRNAM \ VALUE getgr_buf = 0 # define FINISH_GETGRNAM \ - ALLOCV_END(getgr_buf) + (getgr_buf ? (void)rb_str_resize(getgr_buf, 0) : (void)0) # define OBJ2GID1(id) obj2gid((id), &getgr_buf) # define OBJ2GID(id) obj2gid0(id) static rb_gid_t obj2gid(VALUE id, VALUE *getgr_buf); @@ -5033,18 +5033,17 @@ obj2uid(VALUE id https://github.com/ruby/ruby/blob/trunk/process.c#L5033 if (!*getpw_tmp) { getpw_buf_len = GETPW_R_SIZE_INIT; if (getpw_buf_len < 0) getpw_buf_len = GETPW_R_SIZE_DEFAULT; - getpw_buf = rb_alloc_tmp_buffer(getpw_tmp, getpw_buf_len); - } - else { - getpw_buf = RSTRING_PTR(*getpw_tmp); - getpw_buf_len = rb_str_capacity(*getpw_tmp); + *getpw_tmp = rb_str_tmp_new(getpw_buf_len); } + getpw_buf = RSTRING_PTR(*getpw_tmp); + getpw_buf_len = rb_str_capacity(*getpw_tmp); + rb_str_set_len(*getpw_tmp, getpw_buf_len); errno = ERANGE; /* gepwnam_r() on MacOS X doesn't set errno if buffer size is insufficient */ while (getpwnam_r(usrname, &pwbuf, getpw_buf, getpw_buf_len, &pwptr)) { int e = errno; if (e != ERANGE || getpw_buf_len >= GETPW_R_SIZE_LIMIT) { - rb_free_tmp_buffer(getpw_tmp); + rb_str_resize(*getpw_tmp, 0); rb_syserr_fail(e, "getpwnam_r"); } rb_str_modify_expand(*getpw_tmp, getpw_buf_len); @@ -5112,18 +5111,17 @@ obj2gid(VALUE id https://github.com/ruby/ruby/blob/trunk/process.c#L5111 if (!*getgr_tmp) { getgr_buf_len = GETGR_R_SIZE_INIT; if (getgr_buf_len < 0) getgr_buf_len = GETGR_R_SIZE_DEFAULT; - getgr_buf = rb_alloc_tmp_buffer(getgr_tmp, getgr_buf_len); - } - else { - getgr_buf = RSTRING_PTR(*getgr_tmp); - getgr_buf_len = rb_str_capacity(*getgr_tmp); + *getgr_tmp = rb_str_tmp_new(getgr_buf_len); } + getgr_buf = RSTRING_PTR(*getgr_tmp); + getgr_buf_len = rb_str_capacity(*getgr_tmp); + rb_str_set_len(*getgr_tmp, getgr_buf_len); errno = ERANGE; /* gegrnam_r() on MacOS X doesn't set errno if buffer size is insufficient */ while (getgrnam_r(grpname, &grbuf, getgr_buf, getgr_buf_len, &grptr)) { int e = errno; if (e != ERANGE || getgr_buf_len >= GETGR_R_SIZE_LIMIT) { - rb_free_tmp_buffer(getgr_tmp); + rb_str_resize(*getgr_tmp, 0); rb_syserr_fail(e, "getgrnam_r"); } rb_str_modify_expand(*getgr_tmp, getgr_buf_len); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/