summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-09 04:08:22 +0000
committerttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-09 04:08:22 +0000
commitf51bd1d018f16c0da82f05973879e2080d9cc783 (patch)
tree01c0a0622d79e0c4d86cc4dbbaab748015ceea14 /ext
parentf9e069336095b3dbcb6826177d3437f410c9a310 (diff)
Fix the conversion method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/dl/lib/dl/struct.rb12
-rw-r--r--ext/dl/lib/dl/types.rb25
-rw-r--r--ext/dl/ptr.c8
3 files changed, 34 insertions, 11 deletions
diff --git a/ext/dl/lib/dl/struct.rb b/ext/dl/lib/dl/struct.rb
index efa9118..2c52d50 100644
--- a/ext/dl/lib/dl/struct.rb
+++ b/ext/dl/lib/dl/struct.rb
@@ -32,11 +32,19 @@ module DL
instance_eval [
"def #{name}",
" v = @ptr[\"#{name}\"]",
- " v = @dec[\"#{name}\"].call(v,@len[\"#{name}\"]) if @dec[\"#{name}\"]",
+ " if( @len[\"#{name}\"] )",
+ " v = v.collect{|x| @dec[\"#{name}\"].call(x) if @dec[\"#{name}\"] }",
+ " else",
+ " v = @dec[\"#{name}\"].call(v) if @dec[\"#{name}\"]",
+ " end",
" return v",
"end",
"def #{name}=(v)",
- " v = @enc[\"#{name}\"].call(v,@len[\"#{name}\"]) if @enc[\"#{name}\"]",
+ " if( @len[\"#{name}\"] )",
+ " v = v.collect{|x| @enc[\"#{name}\"].call(x) if @enc[\"#{name}\"] }",
+ " else",
+ " v = @enc[\"#{name}\"].call(v) if @enc[\"#{name}\"]",
+ " end",
" @ptr[\"#{name}\"] = v",
" return v",
"end",
diff --git a/ext/dl/lib/dl/types.rb b/ext/dl/lib/dl/types.rb
index 53680ac..e4d79ec 100644
--- a/ext/dl/lib/dl/types.rb
+++ b/ext/dl/lib/dl/types.rb
@@ -34,36 +34,43 @@ module DL
["u_int", "unsigned int", nil, nil, nil, nil],
["ulong", "unsigned long", nil, nil, nil, nil],
["u_long", "unsigned long", nil, nil, nil, nil],
-
+
# DL::Importable primitive types
["ibool", "I",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false},
- nil, nil],
+ proc{|v| v ? 1 : 0 },
+ proc{|v| (v != 0) ? true : false} ],
["cbool", "C",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false},
- nil, nil],
+ proc{|v,len| v ? 1 : 0},
+ proc{|v,len| (v != 0) ? true : false}],
["lbool", "L",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false},
- nil, nil],
+ proc{|v,len| v ? 1 : 0},
+ proc{|v,len| (v != 0) ? true : false}],
["unsigned char", "I",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]},
- nil, nil],
+ proc{|v| [v].pack("C").unpack("c")[0]},
+ proc{|v| [v].pack("c").unpack("C")[0]}],
["unsigned short", "H",
proc{|v| [v].pack("S").unpack("s")[0]},
proc{|v| [v].pack("s").unpack("S")[0]},
- nil, nil],
+ proc{|v| [v].pack("S").unpack("s")[0]},
+ proc{|v| [v].pack("s").unpack("S")[0]}],
["unsigned int", "I",
proc{|v| [v].pack("I").unpack("i")[0]},
proc{|v| [v].pack("i").unpack("I")[0]},
- nil, nil],
+ proc{|v| [v].pack("I").unpack("i")[0]},
+ proc{|v| [v].pack("i").unpack("I")[0]}],
["unsigned long", "L",
proc{|v| [v].pack("L").unpack("l")[0]},
proc{|v| [v].pack("l").unpack("L")[0]},
- nil, nil],
+ proc{|v| [v].pack("L").unpack("l")[0]},
+ proc{|v| [v].pack("l").unpack("L")[0]}],
["unsigned char ref", "i",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]},
@@ -116,7 +123,7 @@ module DL
if( t1.is_a?(String) )
t1 = Regexp.new("^" + t1 + "$")
end
- if( ty =~ t1 )
+ if( t1 =~ ty )
ty = ty.gsub(t1,t2)
if( enc )
if( c1 )
diff --git a/ext/dl/ptr.c b/ext/dl/ptr.c
index ac50f80..d90054c 100644
--- a/ext/dl/ptr.c
+++ b/ext/dl/ptr.c
@@ -660,6 +660,7 @@ cary2ary(void *ptr, char t, int len)
ptr = (char *)ptr + sizeof(long);
break;
case 'P':
+ case 'S':
elem = rb_dlptr_new(*((void**)ptr),0, 0);
ptr = (char *)ptr + sizeof(void*);
break;
@@ -697,6 +698,7 @@ cary2ary(void *ptr, char t, int len)
ptr = (char *)ptr + sizeof(long);
break;
case 'P':
+ case 'S':
elem = rb_dlptr_new(*((void**)ptr), 0, 0);
ptr = (char *)ptr + sizeof(void*);
break;
@@ -764,6 +766,7 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
DLALIGN(data->ptr,offset,LONG_ALIGN);
break;
case 'P':
+ case 'S':
DLALIGN(data->ptr,offset,VOIDP_ALIGN);
break;
case 'F':
@@ -790,6 +793,7 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
offset += sizeof(long) * data->ssize[i];
break;
case 'P':
+ case 'S':
offset += sizeof(void*) * data->ssize[i];
break;
case 'F':
@@ -895,6 +899,7 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
DLALIGN(data->ptr,offset,LONG_ALIGN);
break;
case 'P':
+ case 'S':
DLALIGN(data->ptr,offset,VOIDP_ALIGN);
break;
case 'D':
@@ -926,6 +931,8 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
break;
case 'P':
case 'p':
+ case 'S':
+ case 's':
offset += sizeof(void*) * data->ssize[i];
break;
case 'D':
@@ -961,6 +968,7 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
memsize = sizeof(long) * data->ssize[i];
break;
case 'P': case 'p':
+ case 'S': case 's':
memsize = sizeof(void*) * data->ssize[i];
break;
case 'F': case 'f':