summaryrefslogtreecommitdiff
path: root/ext/dl/lib/dl/struct.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/dl/lib/dl/struct.rb')
-rw-r--r--ext/dl/lib/dl/struct.rb13
1 files changed, 9 insertions, 4 deletions
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)