From 3bd7404423c8a89297b52ff9496fa10b86d64046 Mon Sep 17 00:00:00 2001 From: ttate Date: Thu, 11 Apr 2002 08:07:01 +0000 Subject: Add DL::Importable::Internal::Struct#alloc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/lib/dl/struct.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'ext/dl/lib/dl/struct.rb') diff --git a/ext/dl/lib/dl/struct.rb b/ext/dl/lib/dl/struct.rb index 57703801a6..faa1377c51 100644 --- a/ext/dl/lib/dl/struct.rb +++ b/ext/dl/lib/dl/struct.rb @@ -74,14 +74,19 @@ module DL return @names end - def new(size = nil) + # ptr must be a PtrData object. + def new(ptr) + ptr.struct!(@tys, *@names) + mem = Memory.new(ptr, @names, @ty, @len, @enc, @dec) + return mem + end + + def alloc(size = nil) if( !size ) size = @size end ptr = DL::malloc(size) - ptr.struct!(@tys, *@names) - mem = Memory.new(ptr, @names, @ty, @len, @enc, @dec) - return mem + return new(ptr) end def parse(contents) -- cgit v1.2.3