1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix the conversion method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ttate 2002-12-09 04:08:22 +00:00
parent f9e0693360
commit f51bd1d018
3 changed files with 34 additions and 11 deletions

View file

@ -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",

View file

@ -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 )

View file

@ -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':