Skip to content

Commit b0ce1fd

Browse files
committed
Combine rb_imemo_tmpbuf_auto_free_pointer and rb_imemo_tmpbuf_new
1 parent 70210ac commit b0ce1fd

File tree

5 files changed

+11
-22
lines changed

5 files changed

+11
-22
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ rb_dir_getwd_ospath(void)
14801480
VALUE cwd;
14811481
VALUE path_guard;
14821482

1483-
path_guard = rb_imemo_tmpbuf_auto_free_pointer();
1483+
path_guard = rb_imemo_tmpbuf_new();
14841484
path = ruby_getcwd();
14851485
rb_imemo_tmpbuf_set_ptr(path_guard, path);
14861486
#ifdef __APPLE__

imemo.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,14 @@ rb_imemo_new(enum imemo_type type, VALUE v0, size_t size)
4848
return (VALUE)obj;
4949
}
5050

51-
static rb_imemo_tmpbuf_t *
52-
rb_imemo_tmpbuf_new(void)
53-
{
54-
return IMEMO_NEW(rb_imemo_tmpbuf_t, imemo_tmpbuf, 0);
55-
}
56-
5751
void *
5852
rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t size, size_t cnt)
5953
{
60-
void *ptr;
61-
rb_imemo_tmpbuf_t *tmpbuf;
62-
6354
/* Keep the order; allocate an empty imemo first then xmalloc, to
6455
* get rid of potential memory leak */
65-
tmpbuf = rb_imemo_tmpbuf_new();
56+
rb_imemo_tmpbuf_t *tmpbuf = (rb_imemo_tmpbuf_t *)rb_imemo_tmpbuf_new();
6657
*store = (VALUE)tmpbuf;
67-
ptr = ruby_xmalloc(size);
58+
void *ptr = ruby_xmalloc(size);
6859
tmpbuf->ptr = ptr;
6960
tmpbuf->cnt = cnt;
7061

@@ -97,7 +88,7 @@ rb_free_tmp_buffer(volatile VALUE *store)
9788
rb_imemo_tmpbuf_t *
9889
rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt)
9990
{
100-
rb_imemo_tmpbuf_t *tmpbuf = rb_imemo_tmpbuf_new();
91+
rb_imemo_tmpbuf_t *tmpbuf = (rb_imemo_tmpbuf_t *)rb_imemo_tmpbuf_new();
10192
tmpbuf->ptr = buf;
10293
tmpbuf->next = old_heap;
10394
tmpbuf->cnt = cnt;

internal/imemo.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ static inline enum imemo_type imemo_type(VALUE imemo);
138138
static inline int imemo_type_p(VALUE imemo, enum imemo_type imemo_type);
139139
static inline bool imemo_throw_data_p(VALUE imemo);
140140
static inline struct vm_ifunc *rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data);
141-
static inline VALUE rb_imemo_tmpbuf_auto_free_pointer(void);
142141
static inline void *RB_IMEMO_TMPBUF_PTR(VALUE v);
143142
static inline void *rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr);
144-
static inline VALUE rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str);
145143
static inline void MEMO_V1_SET(struct MEMO *m, VALUE v);
146144
static inline void MEMO_V2_SET(struct MEMO *m, VALUE v);
147145

@@ -201,7 +199,7 @@ rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data)
201199
}
202200

203201
static inline VALUE
204-
rb_imemo_tmpbuf_auto_free_pointer(void)
202+
rb_imemo_tmpbuf_new(void)
205203
{
206204
return rb_imemo_new(imemo_tmpbuf, 0, sizeof(rb_imemo_tmpbuf_t));
207205
}
@@ -220,7 +218,7 @@ rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr)
220218
}
221219

222220
static inline VALUE
223-
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
221+
rb_imemo_tmpbuf_new_from_an_RString(VALUE str)
224222
{
225223
const void *src;
226224
VALUE imemo;
@@ -230,7 +228,7 @@ rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
230228

231229
StringValue(str);
232230
/* create tmpbuf to keep the pointer before xmalloc */
233-
imemo = rb_imemo_tmpbuf_auto_free_pointer();
231+
imemo = rb_imemo_tmpbuf_new();
234232
tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
235233
len = RSTRING_LEN(str);
236234
src = RSTRING_PTR(str);

process.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,7 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, VAL
26352635
}
26362636
rb_str_buf_cat(argv_str, (char *)&null, sizeof(null)); /* terminator for execve. */
26372637
eargp->invoke.cmd.argv_str =
2638-
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(argv_str);
2638+
rb_imemo_tmpbuf_new_from_an_RString(argv_str);
26392639
}
26402640
RB_GC_GUARD(execarg_obj);
26412641
}
@@ -2726,7 +2726,7 @@ open_func(void *ptr)
27262726
static void
27272727
rb_execarg_allocate_dup2_tmpbuf(struct rb_execarg *eargp, long len)
27282728
{
2729-
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
2729+
VALUE tmpbuf = rb_imemo_tmpbuf_new();
27302730
rb_imemo_tmpbuf_set_ptr(tmpbuf, ruby_xmalloc(run_exec_dup2_tmpbuf_size(len)));
27312731
eargp->dup2_tmpbuf = tmpbuf;
27322732
}
@@ -2830,7 +2830,7 @@ rb_execarg_parent_start1(VALUE execarg_obj)
28302830
p = NULL;
28312831
rb_str_buf_cat(envp_str, (char *)&p, sizeof(p));
28322832
eargp->envp_str =
2833-
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(envp_str);
2833+
rb_imemo_tmpbuf_new_from_an_RString(envp_str);
28342834
eargp->envp_buf = envp_buf;
28352835

28362836
/*

util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ ruby_strdup(const char *str)
529529
char *
530530
ruby_getcwd(void)
531531
{
532-
VALUE guard = rb_imemo_tmpbuf_auto_free_pointer();
532+
VALUE guard = rb_imemo_tmpbuf_new();
533533
int size = 200;
534534
char *buf = xmalloc(size);
535535

0 commit comments

Comments
 (0)