git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ttate 2002-04-03 15:43:12 +00:00
Родитель 74b4c81396
Коммит b5856f738a
3 изменённых файлов: 94 добавлений и 68 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Wed Apr 3 15:37:24 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp>
* ext/dl: Add dl/types.rb.
Wed Apr 3 20:42:34 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp> Wed Apr 3 20:42:34 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp>
* ext/dl: Merge Nakada's patch. * ext/dl: Merge Nakada's patch.

Просмотреть файл

@ -1,6 +1,7 @@
# -*- ruby -*- # -*- ruby -*-
require 'dl' require 'dl'
require 'dl/types'
module DL module DL
module Importable module Importable
@ -153,74 +154,7 @@ module DL
end end
def init_type def init_type
@TYDEFS = [ @TYDEFS = TYPES.collect{|ty| ty[0..3]}
# for Windows
["DWORD", "unsigned long", nil, nil],
["PDWORD", "unsigned long *", nil, nil],
["WORD", "unsigned int", nil, nil],
["PWORD", "unsigned int *", nil, nil],
["BOOL", "ibool", nil, nil],
["ATOM", "int", nil, nil],
["BYTE", "unsigned char", nil, nil],
["PBYTE", "unsigned char *", nil, nil],
["UINT", "unsigned int", nil, nil],
["ULONG", "unsigned long", nil, nil],
["UCHAR", "unsigned char", nil, nil],
["HANDLE", "unsigned long", nil, nil],
["PHANDLE","void*", nil, nil],
["PVOID", "void*", nil, nil],
["LPCSTR", "char*", nil, nil],
# Others
["uint", "unsigned int", nil, nil],
["u_int", "unsigned int", nil, nil],
["ulong", "unsigned long", nil, nil],
["u_long", "unsigned long", nil, nil],
# DL::Importable primitive types
["ibool", "I",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false}],
["cbool", "C",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false}],
["lbool", "L",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false}],
["unsigned char", "I",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]}],
["unsigned int", "I",
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]}],
["unsigned char ref", "i",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]}],
["unsigned int ref", "i",
proc{|v| [v].pack("I").unpack("i")[0]},
proc{|v| [v].pack("i").unpack("I")[0]}],
["unsigned long ref", "l",
proc{|v| [v].pack("L").unpack("l")[0]},
proc{|v| [v].pack("l").unpack("L")[0]}],
["char ref", "c", nil, nil],
["short ref", "h", nil, nil],
["int ref", "i", nil, nil],
["long ref", "l", nil, nil],
["float ref", "f", nil, nil],
["double ref","d", nil, nil],
["char", "C", nil, nil],
["short", "H", nil, nil],
["int", "I", nil, nil],
["long", "L", nil, nil],
["float", "F", nil, nil],
["double", "D", nil, nil],
[/.+\*/, "P", nil, nil],
[/.+\[\]/, "a", nil, nil],
["void", "0", nil, nil],
]
end end
end # end of Internal end # end of Internal
include Internal include Internal

88
ext/dl/lib/dl/types.rb Normal file
Просмотреть файл

@ -0,0 +1,88 @@
# -*- ruby -*-
require 'dl'
module DL
TYPES = [
# FORMAT:
# ["alias name", "type name",
# encoding_method, decoding_method, for function prototypes
# encoding_method, decoding_method] for structures (not implemented)
# for Windows
["DWORD", "unsigned long", nil, nil, nil, nil],
["PDWORD", "unsigned long *", nil, nil, nil, nil],
["WORD", "unsigned int", nil, nil, nil, nil],
["PWORD", "unsigned int *", nil, nil, nil, nil],
["BOOL", "ibool", nil, nil, nil, nil],
["ATOM", "int", nil, nil, nil, nil],
["BYTE", "unsigned char", nil, nil, nil, nil],
["PBYTE", "unsigned char *", nil, nil, nil, nil],
["UINT", "unsigned int", nil, nil, nil, nil],
["ULONG", "unsigned long", nil, nil, nil, nil],
["UCHAR", "unsigned char", nil, nil, nil, nil],
["HANDLE", "unsigned long", nil, nil, nil, nil],
["PHANDLE","void*", nil, nil, nil, nil],
["PVOID", "void*", nil, nil, nil, nil],
["LPCSTR", "char*", nil, nil, nil, nil],
# Others
["uint", "unsigned int", nil, nil, nil, nil],
["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],
["cbool", "C",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false},
nil, nil],
["lbool", "L",
proc{|v| v ? 1 : 0},
proc{|v| (v != 0) ? true : false},
nil, nil],
["unsigned char", "I",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]},
nil, nil],
["unsigned int", "I",
proc{|v| [v].pack("I").unpack("i")[0]},
proc{|v| [v].pack("i").unpack("I")[0]},
nil, nil],
["unsigned long", "L",
proc{|v| [v].pack("L").unpack("l")[0]},
proc{|v| [v].pack("l").unpack("L")[0]},
nil, nil],
["unsigned char ref", "i",
proc{|v| [v].pack("C").unpack("c")[0]},
proc{|v| [v].pack("c").unpack("C")[0]},
nil, nil],
["unsigned int ref", "i",
proc{|v| [v].pack("I").unpack("i")[0]},
proc{|v| [v].pack("i").unpack("I")[0]},
nil, nil],
["unsigned long ref", "l",
proc{|v| [v].pack("L").unpack("l")[0]},
proc{|v| [v].pack("l").unpack("L")[0]},
nil, nil],
["char ref", "c", nil, nil, nil, nil],
["short ref", "h", nil, nil, nil, nil],
["int ref", "i", nil, nil, nil, nil],
["long ref", "l", nil, nil, nil, nil],
["float ref", "f", nil, nil, nil, nil],
["double ref","d", nil, nil, nil, nil],
["char", "C", nil, nil, nil, nil],
["short", "H", nil, nil, nil, nil],
["int", "I", nil, nil, nil, nil],
["long", "L", nil, nil, nil, nil],
["float", "F", nil, nil, nil, nil],
["double", "D", nil, nil, nil, nil],
[/.+\*/, "P", nil, nil, nil, nil],
[/.+\[\]/, "a", nil, nil, nil, nil],
["void", "0", nil, nil, nil, nil],
]
end