From 93711e5bd35203e6622f89fe72b38b13478b9313 Mon Sep 17 00:00:00 2001 From: ttate Date: Sun, 6 Feb 2005 06:54:12 +0000 Subject: added DL::Importer.sizeof(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/lib/dl/import.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ext/dl/lib/dl/import.rb') diff --git a/ext/dl/lib/dl/import.rb b/ext/dl/lib/dl/import.rb index 2f21e9195c..2ad805598a 100644 --- a/ext/dl/lib/dl/import.rb +++ b/ext/dl/lib/dl/import.rb @@ -62,6 +62,38 @@ module DL @type_alias[alias_type] = orig_type end + def sizeof(ty) + case ty + when String + ty = parse_ctype(ty, @type_alias).abs() + case ty + when TYPE_CHAR + return SIZEOF_CHAR + when TYPE_SHORT + return SIZEOF_SHORT + when TYPE_INT + return SIZEOF_INT + when TYPE_LONG + return SIZEOF_LONG + when TYPE_LONG_LONG + return SIZEOF_LONG_LON + when TYPE_FLOAT + return SIZEOF_FLOAT + when TYPE_DOUBLE + return SIZEOF_DOUBLE + when TYPE_VOIDP + return SIZEOF_VOIDP + else + raise(DLError, "unknown type: #{ty}") + end + when Class + if( ty.instance_methods().include?("to_ptr") ) + return ty.size() + end + end + return CPtr[ty].size() + end + def parse_bind_options(opts) h = {} prekey = nil -- cgit v1.2.3