From 4bf76b4e6c85db9177f1501843b8161ddfae222b Mon Sep 17 00:00:00 2001 From: ttate Date: Mon, 20 May 2002 15:35:48 +0000 Subject: rename PtrData::alloc and Struct#alloc to malloc respectively. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/dl.c | 8 +------- ext/dl/dl.h | 3 ++- ext/dl/lib/dl/struct.rb | 2 +- ext/dl/ptr.c | 26 +++++++++++++++++--------- ext/dl/sample/libc.rb | 4 ++-- 5 files changed, 23 insertions(+), 20 deletions(-) (limited to 'ext/dl') diff --git a/ext/dl/dl.c b/ext/dl/dl.c index cb370ae252..99df0ba193 100644 --- a/ext/dl/dl.c +++ b/ext/dl/dl.c @@ -457,13 +457,7 @@ rb_dl_dlopen(int argc, VALUE argv[], VALUE self) VALUE rb_dl_malloc(VALUE self, VALUE size) { - void *ptr; - long s; - - s = DLNUM2LONG(size); - ptr = dlmalloc((size_t)s); - memset(ptr,0,(size_t)s); - return rb_dlptr_new(ptr, s, dlfree); + return rb_dlptr_malloc(DLNUM2LONG(size), dlfree); } VALUE diff --git a/ext/dl/dl.h b/ext/dl/dl.h index bfe83087cd..9554ea91ba 100644 --- a/ext/dl/dl.h +++ b/ext/dl/dl.h @@ -296,7 +296,8 @@ void dlptr_free(struct ptr_data *data); void dlptr_init(VALUE val); VALUE rb_dlptr_new(void *ptr, long size, freefunc_t func); -VALUE rb_dlptr_alloc(long size, freefunc_t func); +VALUE rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func); +VALUE rb_dlptr_malloc(long size, freefunc_t func); void *rb_dlptr2cptr(VALUE val); VALUE rb_dlsym_new(void (*func)(), const char *name, const char *type); diff --git a/ext/dl/lib/dl/struct.rb b/ext/dl/lib/dl/struct.rb index faa1377c51..efa9118c11 100644 --- a/ext/dl/lib/dl/struct.rb +++ b/ext/dl/lib/dl/struct.rb @@ -81,7 +81,7 @@ module DL return mem end - def alloc(size = nil) + def malloc(size = nil) if( !size ) size = @size end diff --git a/ext/dl/ptr.c b/ext/dl/ptr.c index a6af30112d..60b7f71860 100644 --- a/ext/dl/ptr.c +++ b/ext/dl/ptr.c @@ -83,7 +83,7 @@ dlptr_init(VALUE val) } VALUE -rb_dlptr_new(void *ptr, long size, freefunc_t func) +rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func) { struct ptr_data *data; VALUE val; @@ -91,7 +91,7 @@ rb_dlptr_new(void *ptr, long size, freefunc_t func) if( ptr ){ val = rb_dlmem_aref(ptr); if( val == Qnil ){ - val = Data_Make_Struct(rb_cDLPtrData, struct ptr_data, + val = Data_Make_Struct(klass, struct ptr_data, 0, dlptr_free, data); data->ptr = ptr; data->free = func; @@ -119,9 +119,19 @@ rb_dlptr_new(void *ptr, long size, freefunc_t func) } VALUE -rb_dlptr_alloc(long size, freefunc_t func) +rb_dlptr_new(void *ptr, long size, freefunc_t func) +{ + return rb_dlptr_new2(rb_cDLPtrData, ptr, size, func); +} + +VALUE +rb_dlptr_malloc(long size, freefunc_t func) { - return rb_dlptr_new(dlmalloc((size_t)size), size, func); + void *ptr; + + ptr = dlmalloc((size_t)size); + memset(ptr,0,(size_t)size); + return rb_dlptr_new(ptr, size, func); } void * @@ -177,7 +187,7 @@ rb_dlptr_s_new(int argc, VALUE argv[], VALUE klass) } static VALUE -rb_dlptr_s_alloc(int argc, VALUE argv[], VALUE klass) +rb_dlptr_s_malloc(int argc, VALUE argv[], VALUE klass) { VALUE size, sym, obj; int s; @@ -195,9 +205,7 @@ rb_dlptr_s_alloc(int argc, VALUE argv[], VALUE klass) rb_bug("rb_dlptr_s_new"); }; - obj = rb_dlptr_alloc(s,f); - - rb_obj_call_init(obj, argc, argv); + obj = rb_dlptr_malloc(s,f); return obj; } @@ -996,7 +1004,7 @@ Init_dlptr() { rb_cDLPtrData = rb_define_class_under(rb_mDL, "PtrData", rb_cData); rb_define_singleton_method(rb_cDLPtrData, "new", rb_dlptr_s_new, -1); - rb_define_singleton_method(rb_cDLPtrData, "alloc", rb_dlptr_s_alloc, -1); + rb_define_singleton_method(rb_cDLPtrData, "malloc", rb_dlptr_s_malloc, -1); rb_define_method(rb_cDLPtrData, "initialize", rb_dlptr_init, -1); rb_define_method(rb_cDLPtrData, "free=", rb_dlptr_free_set, 1); rb_define_method(rb_cDLPtrData, "free", rb_dlptr_free_get, 0); diff --git a/ext/dl/sample/libc.rb b/ext/dl/sample/libc.rb index cb16aa043f..7d1de2601d 100644 --- a/ext/dl/sample/libc.rb +++ b/ext/dl/sample/libc.rb @@ -57,8 +57,8 @@ ptr = ary.to_ptr LIBC.qsort(ptr, ary.length, DL.sizeof('P'), $cb1) p ptr.to_a('S', ary.length) -tv = LIBC::Timeval.alloc -tz = LIBC::Timezone.alloc +tv = LIBC::Timeval.malloc +tz = LIBC::Timezone.malloc LIBC.gettimeofday(tv, tz) p Time.at(tv.tv_sec) -- cgit v1.2.3