summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--ext/dl/lib/dl/import.rb70
-rw-r--r--ext/dl/lib/dl/types.rb88
3 files changed, 94 insertions, 68 deletions
diff --git a/ChangeLog b/ChangeLog
index 5fb1e54db5..99336d227a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* ext/dl: Merge Nakada's patch.
diff --git a/ext/dl/lib/dl/import.rb b/ext/dl/lib/dl/import.rb
index 78f6a2b785..ee3070c90c 100644
--- a/ext/dl/lib/dl/import.rb
+++ b/ext/dl/lib/dl/import.rb
@@ -1,6 +1,7 @@
# -*- ruby -*-
require 'dl'
+require 'dl/types'
module DL
module Importable
@@ -153,74 +154,7 @@ module DL
end
def init_type
- @TYDEFS = [
- # 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],
- ]
+ @TYDEFS = TYPES.collect{|ty| ty[0..3]}
end
end # end of Internal
include Internal
diff --git a/ext/dl/lib/dl/types.rb b/ext/dl/lib/dl/types.rb
new file mode 100644
index 0000000000..c040f2cecc
--- /dev/null
+++ b/ext/dl/lib/dl/types.rb
@@ -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