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:
parent
f9e0693360
commit
f51bd1d018
3 changed files with 34 additions and 11 deletions
|
@ -32,11 +32,19 @@ module DL
|
||||||
instance_eval [
|
instance_eval [
|
||||||
"def #{name}",
|
"def #{name}",
|
||||||
" v = @ptr[\"#{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",
|
" return v",
|
||||||
"end",
|
"end",
|
||||||
"def #{name}=(v)",
|
"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",
|
" @ptr[\"#{name}\"] = v",
|
||||||
" return v",
|
" return v",
|
||||||
"end",
|
"end",
|
||||||
|
|
|
@ -34,36 +34,43 @@ module DL
|
||||||
["u_int", "unsigned int", nil, nil, nil, nil],
|
["u_int", "unsigned int", nil, nil, nil, nil],
|
||||||
["ulong", "unsigned long", nil, nil, nil, nil],
|
["ulong", "unsigned long", nil, nil, nil, nil],
|
||||||
["u_long", "unsigned long", nil, nil, nil, nil],
|
["u_long", "unsigned long", nil, nil, nil, nil],
|
||||||
|
|
||||||
# DL::Importable primitive types
|
# DL::Importable primitive types
|
||||||
["ibool", "I",
|
["ibool", "I",
|
||||||
proc{|v| v ? 1 : 0},
|
proc{|v| v ? 1 : 0},
|
||||||
proc{|v| (v != 0) ? true : false},
|
proc{|v| (v != 0) ? true : false},
|
||||||
nil, nil],
|
proc{|v| v ? 1 : 0 },
|
||||||
|
proc{|v| (v != 0) ? true : false} ],
|
||||||
["cbool", "C",
|
["cbool", "C",
|
||||||
proc{|v| v ? 1 : 0},
|
proc{|v| v ? 1 : 0},
|
||||||
proc{|v| (v != 0) ? true : false},
|
proc{|v| (v != 0) ? true : false},
|
||||||
nil, nil],
|
proc{|v,len| v ? 1 : 0},
|
||||||
|
proc{|v,len| (v != 0) ? true : false}],
|
||||||
["lbool", "L",
|
["lbool", "L",
|
||||||
proc{|v| v ? 1 : 0},
|
proc{|v| v ? 1 : 0},
|
||||||
proc{|v| (v != 0) ? true : false},
|
proc{|v| (v != 0) ? true : false},
|
||||||
nil, nil],
|
proc{|v,len| v ? 1 : 0},
|
||||||
|
proc{|v,len| (v != 0) ? true : false}],
|
||||||
["unsigned char", "I",
|
["unsigned char", "I",
|
||||||
proc{|v| [v].pack("C").unpack("c")[0]},
|
proc{|v| [v].pack("C").unpack("c")[0]},
|
||||||
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",
|
["unsigned short", "H",
|
||||||
proc{|v| [v].pack("S").unpack("s")[0]},
|
proc{|v| [v].pack("S").unpack("s")[0]},
|
||||||
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",
|
["unsigned int", "I",
|
||||||
proc{|v| [v].pack("I").unpack("i")[0]},
|
proc{|v| [v].pack("I").unpack("i")[0]},
|
||||||
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",
|
["unsigned long", "L",
|
||||||
proc{|v| [v].pack("L").unpack("l")[0]},
|
proc{|v| [v].pack("L").unpack("l")[0]},
|
||||||
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",
|
["unsigned char ref", "i",
|
||||||
proc{|v| [v].pack("C").unpack("c")[0]},
|
proc{|v| [v].pack("C").unpack("c")[0]},
|
||||||
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) )
|
if( t1.is_a?(String) )
|
||||||
t1 = Regexp.new("^" + t1 + "$")
|
t1 = Regexp.new("^" + t1 + "$")
|
||||||
end
|
end
|
||||||
if( ty =~ t1 )
|
if( t1 =~ ty )
|
||||||
ty = ty.gsub(t1,t2)
|
ty = ty.gsub(t1,t2)
|
||||||
if( enc )
|
if( enc )
|
||||||
if( c1 )
|
if( c1 )
|
||||||
|
|
|
@ -660,6 +660,7 @@ cary2ary(void *ptr, char t, int len)
|
||||||
ptr = (char *)ptr + sizeof(long);
|
ptr = (char *)ptr + sizeof(long);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
|
case 'S':
|
||||||
elem = rb_dlptr_new(*((void**)ptr),0, 0);
|
elem = rb_dlptr_new(*((void**)ptr),0, 0);
|
||||||
ptr = (char *)ptr + sizeof(void*);
|
ptr = (char *)ptr + sizeof(void*);
|
||||||
break;
|
break;
|
||||||
|
@ -697,6 +698,7 @@ cary2ary(void *ptr, char t, int len)
|
||||||
ptr = (char *)ptr + sizeof(long);
|
ptr = (char *)ptr + sizeof(long);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
|
case 'S':
|
||||||
elem = rb_dlptr_new(*((void**)ptr), 0, 0);
|
elem = rb_dlptr_new(*((void**)ptr), 0, 0);
|
||||||
ptr = (char *)ptr + sizeof(void*);
|
ptr = (char *)ptr + sizeof(void*);
|
||||||
break;
|
break;
|
||||||
|
@ -764,6 +766,7 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
|
||||||
DLALIGN(data->ptr,offset,LONG_ALIGN);
|
DLALIGN(data->ptr,offset,LONG_ALIGN);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
|
case 'S':
|
||||||
DLALIGN(data->ptr,offset,VOIDP_ALIGN);
|
DLALIGN(data->ptr,offset,VOIDP_ALIGN);
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
|
@ -790,6 +793,7 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
|
||||||
offset += sizeof(long) * data->ssize[i];
|
offset += sizeof(long) * data->ssize[i];
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
|
case 'S':
|
||||||
offset += sizeof(void*) * data->ssize[i];
|
offset += sizeof(void*) * data->ssize[i];
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
|
@ -895,6 +899,7 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
|
||||||
DLALIGN(data->ptr,offset,LONG_ALIGN);
|
DLALIGN(data->ptr,offset,LONG_ALIGN);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
|
case 'S':
|
||||||
DLALIGN(data->ptr,offset,VOIDP_ALIGN);
|
DLALIGN(data->ptr,offset,VOIDP_ALIGN);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
|
@ -926,6 +931,8 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
case 'p':
|
case 'p':
|
||||||
|
case 'S':
|
||||||
|
case 's':
|
||||||
offset += sizeof(void*) * data->ssize[i];
|
offset += sizeof(void*) * data->ssize[i];
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
|
@ -961,6 +968,7 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
|
||||||
memsize = sizeof(long) * data->ssize[i];
|
memsize = sizeof(long) * data->ssize[i];
|
||||||
break;
|
break;
|
||||||
case 'P': case 'p':
|
case 'P': case 'p':
|
||||||
|
case 'S': case 's':
|
||||||
memsize = sizeof(void*) * data->ssize[i];
|
memsize = sizeof(void*) * data->ssize[i];
|
||||||
break;
|
break;
|
||||||
case 'F': case 'f':
|
case 'F': case 'f':
|
||||||
|
|
Loading…
Reference in a new issue