aboutsummaryrefslogtreecommitdiffstats
path: root/process.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-10 23:18:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-10 23:18:07 +0000
commitb346ea7a0102e80d392f85227e6ffa5545e204b5 (patch)
tree170df825c6d2b6069527d685f7d9bcce793ca025 /process.c
parent8639b93dfb7d992338870c4de1a6e961aca360e3 (diff)
downloadruby-b346ea7a0102e80d392f85227e6ffa5545e204b5.tar.gz
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/process.c b/process.c
index 9191051f99..27a12f8635 100644
--- a/process.c
+++ b/process.c
@@ -172,7 +172,7 @@ static void check_gid_switch(void);
# 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);
# 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
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
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);