Skip to content

Commit 4b4da98

Browse files
committed
Avoid and simplify rb_alloc_tmp_buffer_with_count
There's no reason to ever call this and the "count" value is ignored. Because this is part of the public API I left it as a stub, but it could likely be removed.
1 parent 7a36808 commit 4b4da98

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

imemo.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,27 @@ rb_imemo_tmpbuf_new(void)
6363
}
6464

6565
void *
66-
rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t size, size_t cnt)
66+
rb_alloc_tmp_buffer(volatile VALUE *store, long len)
6767
{
68+
if (len < 0) {
69+
rb_raise(rb_eArgError, "negative buffer size (or size too big)");
70+
}
71+
6872
/* Keep the order; allocate an empty imemo first then xmalloc, to
6973
* get rid of potential memory leak */
7074
rb_imemo_tmpbuf_t *tmpbuf = (rb_imemo_tmpbuf_t *)rb_imemo_tmpbuf_new();
7175
*store = (VALUE)tmpbuf;
72-
void *ptr = ruby_xmalloc(size);
76+
void *ptr = ruby_xmalloc(len);
7377
tmpbuf->ptr = ptr;
74-
tmpbuf->size = size;
78+
tmpbuf->size = len;
7579

7680
return ptr;
7781
}
7882

7983
void *
80-
rb_alloc_tmp_buffer(volatile VALUE *store, long len)
84+
rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t size, size_t cnt)
8185
{
82-
long cnt;
83-
84-
if (len < 0 || (cnt = (long)roomof(len, sizeof(VALUE))) < 0) {
85-
rb_raise(rb_eArgError, "negative buffer size (or size too big)");
86-
}
87-
88-
return rb_alloc_tmp_buffer_with_count(store, len, cnt);
86+
return rb_alloc_tmp_buffer(store, (long)size);
8987
}
9088

9189
void

include/ruby/internal/memory.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,7 @@ static inline void *
741741
rb_alloc_tmp_buffer2(volatile VALUE *store, long count, size_t elsize)
742742
{
743743
const size_t total_size = rbimpl_size_mul_or_raise(RBIMPL_CAST((size_t)count), elsize);
744-
const size_t cnt = (total_size + sizeof(VALUE) - 1) / sizeof(VALUE);
745-
return rb_alloc_tmp_buffer_with_count(store, total_size, cnt);
744+
return rb_alloc_tmp_buffer(store, (long)total_size);
746745
}
747746

748747
RBIMPL_SYMBOL_EXPORT_BEGIN()

0 commit comments

Comments
 (0)