summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-20 10:41:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-20 10:41:46 +0000
commite2a43c9e09014903fde535ab01212459ac8ea563 (patch)
tree0333087a99e879213cabf031240eb01a2433debf /struct.c
parent53812198daa147f1e77e29b0b417cc0e9736c371 (diff)
* struct.c (rb_struct_new): get rid of too large alloca.
* struct.c (rb_struct_hash): use long. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/struct.c b/struct.c
index c1d9c42484..2962d400ca 100644
--- a/struct.c
+++ b/struct.c
@@ -129,7 +129,8 @@ static VALUE rb_struct_ref7(VALUE obj) {return RSTRUCT_PTR(obj)[7];}
static VALUE rb_struct_ref8(VALUE obj) {return RSTRUCT_PTR(obj)[8];}
static VALUE rb_struct_ref9(VALUE obj) {return RSTRUCT_PTR(obj)[9];}
-#define N_REF_FUNC (sizeof(ref_func) / sizeof(ref_func[0]))
+#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
+#define N_REF_FUNC numberof(ref_func)
static VALUE (*const ref_func[])(VALUE) = {
rb_struct_ref0,
@@ -342,7 +343,7 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
return st;
}
-static size_t
+static long
num_members(VALUE klass)
{
VALUE members;
@@ -412,12 +413,15 @@ rb_struct_alloc(VALUE klass, VALUE values)
VALUE
rb_struct_new(VALUE klass, ...)
{
- VALUE *mem;
+ VALUE tmpargs[N_REF_FUNC], *mem = tmpargs;
long size, i;
va_list args;
size = num_members(klass);
- mem = ALLOCA_N(VALUE, size);
+ if (size > numberof(tmpargs)) {
+ tmpargs[0] = rb_ary_tmp_new(size);
+ mem = RARRAY_PTR(tmpargs[0]);
+ }
va_start(args, klass);
for (i=0; i<size; i++) {
mem[i] = va_arg(args, VALUE);
@@ -809,7 +813,7 @@ static VALUE
rb_struct_hash(VALUE s)
{
long i;
- unsigned h;
+ unsigned long h;
VALUE n;
h = rb_hash_start(rb_hash(rb_obj_class(s)));