ffi 1.0.7 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (37) hide show
  1. data/Rakefile +3 -3
  2. data/ext/ffi_c/AbstractMemory.c +40 -3
  3. data/ext/ffi_c/AbstractMemory.h +2 -2
  4. data/ext/ffi_c/Buffer.c +28 -0
  5. data/ext/ffi_c/DynamicLibrary.c +17 -6
  6. data/ext/ffi_c/Function.c +20 -10
  7. data/ext/ffi_c/MemoryPointer.c +17 -27
  8. data/ext/ffi_c/Platform.c +17 -7
  9. data/ext/ffi_c/Pointer.c +103 -12
  10. data/ext/ffi_c/Pointer.h +9 -0
  11. data/ext/ffi_c/Struct.c +43 -1
  12. data/ext/ffi_c/StructLayout.c +2 -1
  13. data/lib/ffi/enum.rb +1 -3
  14. data/lib/ffi/platform.rb +1 -1
  15. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  16. data/lib/ffi/platform/i386-linux/types.conf +100 -0
  17. data/lib/ffi/platform/i386-openbsd/types.conf +126 -0
  18. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  19. data/lib/ffi/platform/i386-windows/types.conf +105 -0
  20. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  21. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  22. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  23. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  24. data/lib/ffi/platform/x86_64-darwin/types.conf +100 -0
  25. data/lib/ffi/platform/x86_64-linux/types.conf +100 -0
  26. data/lib/ffi/platform/x86_64-openbsd/types.conf +126 -0
  27. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  28. data/lib/ffi/struct.rb +1 -1
  29. data/lib/ffi/tools/generator.rb +1 -1
  30. data/lib/ffi/types.rb +2 -1
  31. data/spec/ffi/dup_spec.rb +65 -0
  32. data/spec/ffi/enum_spec.rb +28 -0
  33. data/spec/ffi/strptr_spec.rb +11 -2
  34. data/spec/ffi/struct_spec.rb +2 -2
  35. data/tasks/extension.rake +1 -1
  36. metadata +33 -24
  37. data/lib/ffi_c.bundle +0 -0
@@ -0,0 +1,100 @@
1
+ rbx.platform.typedef.__u_char = uchar
2
+ rbx.platform.typedef.__u_short = ushort
3
+ rbx.platform.typedef.__u_int = uint
4
+ rbx.platform.typedef.__u_long = ulong
5
+ rbx.platform.typedef.__int8_t = char
6
+ rbx.platform.typedef.__uint8_t = uchar
7
+ rbx.platform.typedef.__int16_t = short
8
+ rbx.platform.typedef.__uint16_t = ushort
9
+ rbx.platform.typedef.__int32_t = int
10
+ rbx.platform.typedef.__uint32_t = uint
11
+ rbx.platform.typedef.__int64_t = long
12
+ rbx.platform.typedef.__uint64_t = ulong
13
+ rbx.platform.typedef.__quad_t = long
14
+ rbx.platform.typedef.__u_quad_t = ulong
15
+ rbx.platform.typedef.__dev_t = ulong
16
+ rbx.platform.typedef.__uid_t = uint
17
+ rbx.platform.typedef.__gid_t = uint
18
+ rbx.platform.typedef.__ino_t = ulong
19
+ rbx.platform.typedef.__ino64_t = ulong
20
+ rbx.platform.typedef.__mode_t = uint
21
+ rbx.platform.typedef.__nlink_t = ulong
22
+ rbx.platform.typedef.__off_t = long
23
+ rbx.platform.typedef.__off64_t = long
24
+ rbx.platform.typedef.__pid_t = int
25
+ rbx.platform.typedef.__clock_t = long
26
+ rbx.platform.typedef.__rlim_t = ulong
27
+ rbx.platform.typedef.__rlim64_t = ulong
28
+ rbx.platform.typedef.__id_t = uint
29
+ rbx.platform.typedef.__time_t = long
30
+ rbx.platform.typedef.__useconds_t = uint
31
+ rbx.platform.typedef.__suseconds_t = long
32
+ rbx.platform.typedef.__daddr_t = int
33
+ rbx.platform.typedef.__swblk_t = long
34
+ rbx.platform.typedef.__key_t = int
35
+ rbx.platform.typedef.__clockid_t = int
36
+ rbx.platform.typedef.__timer_t = pointer
37
+ rbx.platform.typedef.__blksize_t = long
38
+ rbx.platform.typedef.__blkcnt_t = long
39
+ rbx.platform.typedef.__blkcnt64_t = long
40
+ rbx.platform.typedef.__fsblkcnt_t = ulong
41
+ rbx.platform.typedef.__fsblkcnt64_t = ulong
42
+ rbx.platform.typedef.__fsfilcnt_t = ulong
43
+ rbx.platform.typedef.__fsfilcnt64_t = ulong
44
+ rbx.platform.typedef.__ssize_t = long
45
+ rbx.platform.typedef.__loff_t = long
46
+ rbx.platform.typedef.*__qaddr_t = long
47
+ rbx.platform.typedef.*__caddr_t = char
48
+ rbx.platform.typedef.__intptr_t = long
49
+ rbx.platform.typedef.__socklen_t = uint
50
+ rbx.platform.typedef.u_char = uchar
51
+ rbx.platform.typedef.u_short = ushort
52
+ rbx.platform.typedef.u_int = uint
53
+ rbx.platform.typedef.u_long = ulong
54
+ rbx.platform.typedef.quad_t = long
55
+ rbx.platform.typedef.u_quad_t = ulong
56
+ rbx.platform.typedef.loff_t = long
57
+ rbx.platform.typedef.ino_t = ulong
58
+ rbx.platform.typedef.dev_t = ulong
59
+ rbx.platform.typedef.gid_t = uint
60
+ rbx.platform.typedef.mode_t = uint
61
+ rbx.platform.typedef.nlink_t = ulong
62
+ rbx.platform.typedef.uid_t = uint
63
+ rbx.platform.typedef.off_t = long
64
+ rbx.platform.typedef.pid_t = int
65
+ rbx.platform.typedef.id_t = uint
66
+ rbx.platform.typedef.ssize_t = long
67
+ rbx.platform.typedef.daddr_t = int
68
+ rbx.platform.typedef.key_t = int
69
+ rbx.platform.typedef.time_t = long
70
+ rbx.platform.typedef.clockid_t = int
71
+ rbx.platform.typedef.timer_t = pointer
72
+ rbx.platform.typedef.size_t = ulong
73
+ rbx.platform.typedef.ulong = ulong
74
+ rbx.platform.typedef.ushort = ushort
75
+ rbx.platform.typedef.uint = uint
76
+ rbx.platform.typedef.int8_t = char
77
+ rbx.platform.typedef.int16_t = short
78
+ rbx.platform.typedef.int32_t = int
79
+ rbx.platform.typedef.int64_t = long_long
80
+ rbx.platform.typedef.u_int8_t = uchar
81
+ rbx.platform.typedef.u_int16_t = ushort
82
+ rbx.platform.typedef.u_int32_t = uint
83
+ rbx.platform.typedef.u_int64_t = ulong_long
84
+ rbx.platform.typedef.register_t = long
85
+ rbx.platform.typedef.__sig_atomic_t = int
86
+ rbx.platform.typedef.suseconds_t = long
87
+ rbx.platform.typedef.__fd_mask = long
88
+ rbx.platform.typedef.fd_mask = long
89
+ rbx.platform.typedef.blkcnt_t = long
90
+ rbx.platform.typedef.fsblkcnt_t = ulong
91
+ rbx.platform.typedef.fsfilcnt_t = ulong
92
+ rbx.platform.typedef.pthread_t = ulong
93
+ rbx.platform.typedef.pthread_key_t = uint
94
+ rbx.platform.typedef.pthread_once_t = int
95
+ rbx.platform.typedef.socklen_t = uint
96
+ rbx.platform.typedef.sa_family_t = ushort
97
+ rbx.platform.typedef.rlim_t = ulong
98
+ rbx.platform.typedef.__rlimit_resource_t = int
99
+ rbx.platform.typedef.__rusage_who_t = int
100
+ rbx.platform.typedef.__priority_which_t = int
@@ -0,0 +1,126 @@
1
+ rbx.platform.typedef.__int8_t = char
2
+ rbx.platform.typedef.__uint8_t = uchar
3
+ rbx.platform.typedef.__int16_t = short
4
+ rbx.platform.typedef.__uint16_t = ushort
5
+ rbx.platform.typedef.__int32_t = int
6
+ rbx.platform.typedef.__uint32_t = uint
7
+ rbx.platform.typedef.__int64_t = long_long
8
+ rbx.platform.typedef.__uint64_t = ulong_long
9
+ rbx.platform.typedef.__int_least8_t = char
10
+ rbx.platform.typedef.__uint_least8_t = uchar
11
+ rbx.platform.typedef.__int_least16_t = short
12
+ rbx.platform.typedef.__uint_least16_t = ushort
13
+ rbx.platform.typedef.__int_least32_t = int
14
+ rbx.platform.typedef.__uint_least32_t = uint
15
+ rbx.platform.typedef.__int_least64_t = long_long
16
+ rbx.platform.typedef.__uint_least64_t = ulong_long
17
+ rbx.platform.typedef.__int_fast8_t = int
18
+ rbx.platform.typedef.__uint_fast8_t = uint
19
+ rbx.platform.typedef.__int_fast16_t = int
20
+ rbx.platform.typedef.__uint_fast16_t = uint
21
+ rbx.platform.typedef.__int_fast32_t = int
22
+ rbx.platform.typedef.__uint_fast32_t = uint
23
+ rbx.platform.typedef.__int_fast64_t = long_long
24
+ rbx.platform.typedef.__uint_fast64_t = ulong_long
25
+ rbx.platform.typedef.__intptr_t = long
26
+ rbx.platform.typedef.__uintptr_t = ulong
27
+ rbx.platform.typedef.__intmax_t = long_long
28
+ rbx.platform.typedef.__uintmax_t = ulong_long
29
+ rbx.platform.typedef.__register_t = int
30
+ rbx.platform.typedef.__vaddr_t = ulong
31
+ rbx.platform.typedef.__paddr_t = ulong
32
+ rbx.platform.typedef.__vsize_t = ulong
33
+ rbx.platform.typedef.__psize_t = ulong
34
+ rbx.platform.typedef.__clock_t = int
35
+ rbx.platform.typedef.__clockid_t = int
36
+ rbx.platform.typedef.__off_t = long_long
37
+ rbx.platform.typedef.__ptrdiff_t = long
38
+ rbx.platform.typedef.__size_t = ulong
39
+ rbx.platform.typedef.__ssize_t = long
40
+ rbx.platform.typedef.__time_t = int
41
+ rbx.platform.typedef.__timer_t = int
42
+ rbx.platform.typedef.__wchar_t = int
43
+ rbx.platform.typedef.__wint_t = int
44
+ rbx.platform.typedef.__rune_t = int
45
+ rbx.platform.typedef.__wctrans_t = pointer
46
+ rbx.platform.typedef.__wctype_t = pointer
47
+ rbx.platform.typedef.__cpuid_t = ulong
48
+ rbx.platform.typedef.__dev_t = int
49
+ rbx.platform.typedef.__fixpt_t = uint
50
+ rbx.platform.typedef.__gid_t = uint
51
+ rbx.platform.typedef.__id_t = uint
52
+ rbx.platform.typedef.__in_addr_t = uint
53
+ rbx.platform.typedef.__in_port_t = ushort
54
+ rbx.platform.typedef.__ino_t = uint
55
+ rbx.platform.typedef.__key_t = long
56
+ rbx.platform.typedef.__mode_t = uint
57
+ rbx.platform.typedef.__nlink_t = uint
58
+ rbx.platform.typedef.__pid_t = int
59
+ rbx.platform.typedef.__rlim_t = ulong_long
60
+ rbx.platform.typedef.__sa_family_t = uchar
61
+ rbx.platform.typedef.__segsz_t = int
62
+ rbx.platform.typedef.__socklen_t = uint
63
+ rbx.platform.typedef.__swblk_t = int
64
+ rbx.platform.typedef.__uid_t = uint
65
+ rbx.platform.typedef.__useconds_t = uint
66
+ rbx.platform.typedef.__suseconds_t = int
67
+ rbx.platform.typedef.u_char = uchar
68
+ rbx.platform.typedef.u_short = ushort
69
+ rbx.platform.typedef.u_int = uint
70
+ rbx.platform.typedef.u_long = ulong
71
+ rbx.platform.typedef.unchar = uchar
72
+ rbx.platform.typedef.ushort = ushort
73
+ rbx.platform.typedef.uint = uint
74
+ rbx.platform.typedef.ulong = ulong
75
+ rbx.platform.typedef.cpuid_t = ulong
76
+ rbx.platform.typedef.register_t = int
77
+ rbx.platform.typedef.int8_t = char
78
+ rbx.platform.typedef.uint8_t = uchar
79
+ rbx.platform.typedef.int16_t = short
80
+ rbx.platform.typedef.uint16_t = ushort
81
+ rbx.platform.typedef.int32_t = int
82
+ rbx.platform.typedef.uint32_t = uint
83
+ rbx.platform.typedef.int64_t = long_long
84
+ rbx.platform.typedef.uint64_t = ulong_long
85
+ rbx.platform.typedef.u_int8_t = uchar
86
+ rbx.platform.typedef.u_int16_t = ushort
87
+ rbx.platform.typedef.u_int32_t = uint
88
+ rbx.platform.typedef.u_int64_t = ulong_long
89
+ rbx.platform.typedef.quad_t = long_long
90
+ rbx.platform.typedef.u_quad_t = ulong_long
91
+ rbx.platform.typedef.qaddr_t = pointer
92
+ rbx.platform.typedef.vaddr_t = ulong
93
+ rbx.platform.typedef.paddr_t = ulong
94
+ rbx.platform.typedef.vsize_t = ulong
95
+ rbx.platform.typedef.psize_t = ulong
96
+ rbx.platform.typedef.caddr_t = string
97
+ rbx.platform.typedef.daddr_t = int
98
+ rbx.platform.typedef.daddr32_t = int
99
+ rbx.platform.typedef.daddr64_t = long_long
100
+ rbx.platform.typedef.dev_t = int
101
+ rbx.platform.typedef.fixpt_t = uint
102
+ rbx.platform.typedef.gid_t = uint
103
+ rbx.platform.typedef.id_t = uint
104
+ rbx.platform.typedef.ino_t = uint
105
+ rbx.platform.typedef.key_t = long
106
+ rbx.platform.typedef.mode_t = uint
107
+ rbx.platform.typedef.nlink_t = uint
108
+ rbx.platform.typedef.pid_t = int
109
+ rbx.platform.typedef.rlim_t = ulong_long
110
+ rbx.platform.typedef.segsz_t = int
111
+ rbx.platform.typedef.swblk_t = int
112
+ rbx.platform.typedef.uid_t = uint
113
+ rbx.platform.typedef.useconds_t = uint
114
+ rbx.platform.typedef.suseconds_t = int
115
+ rbx.platform.typedef.in_addr_t = uint
116
+ rbx.platform.typedef.in_port_t = ushort
117
+ rbx.platform.typedef.sa_family_t = uchar
118
+ rbx.platform.typedef.socklen_t = uint
119
+ rbx.platform.typedef.clock_t = int
120
+ rbx.platform.typedef.clockid_t = int
121
+ rbx.platform.typedef.size_t = ulong
122
+ rbx.platform.typedef.ssize_t = long
123
+ rbx.platform.typedef.time_t = int
124
+ rbx.platform.typedef.timer_t = int
125
+ rbx.platform.typedef.off_t = long_long
126
+ rbx.platform.typedef.__fd_mask = int
@@ -0,0 +1,122 @@
1
+ rbx.platform.typedef.lock_t = uchar
2
+ rbx.platform.typedef.int8_t = char
3
+ rbx.platform.typedef.int16_t = short
4
+ rbx.platform.typedef.int32_t = int
5
+ rbx.platform.typedef.int64_t = long
6
+ rbx.platform.typedef.uint8_t = uchar
7
+ rbx.platform.typedef.uint16_t = ushort
8
+ rbx.platform.typedef.uint32_t = uint
9
+ rbx.platform.typedef.uint64_t = ulong
10
+ rbx.platform.typedef.intmax_t = long
11
+ rbx.platform.typedef.uintmax_t = ulong
12
+ rbx.platform.typedef.intptr_t = long
13
+ rbx.platform.typedef.uintptr_t = ulong
14
+ rbx.platform.typedef.int_fast8_t = char
15
+ rbx.platform.typedef.int_fast16_t = int
16
+ rbx.platform.typedef.int_fast32_t = int
17
+ rbx.platform.typedef.int_fast64_t = long
18
+ rbx.platform.typedef.uint_fast8_t = uchar
19
+ rbx.platform.typedef.uint_fast16_t = uint
20
+ rbx.platform.typedef.uint_fast32_t = uint
21
+ rbx.platform.typedef.uint_fast64_t = ulong
22
+ rbx.platform.typedef.int_least8_t = char
23
+ rbx.platform.typedef.int_least16_t = short
24
+ rbx.platform.typedef.int_least32_t = int
25
+ rbx.platform.typedef.int_least64_t = long
26
+ rbx.platform.typedef.uint_least8_t = uchar
27
+ rbx.platform.typedef.uint_least16_t = ushort
28
+ rbx.platform.typedef.uint_least32_t = uint
29
+ rbx.platform.typedef.uint_least64_t = ulong
30
+ rbx.platform.typedef.longlong_t = long_long
31
+ rbx.platform.typedef.u_longlong_t = ulong_long
32
+ rbx.platform.typedef.t_scalar_t = int
33
+ rbx.platform.typedef.t_uscalar_t = uint
34
+ rbx.platform.typedef.uchar_t = uchar
35
+ rbx.platform.typedef.ushort_t = ushort
36
+ rbx.platform.typedef.uint_t = uint
37
+ rbx.platform.typedef.ulong_t = ulong
38
+ rbx.platform.typedef.*caddr_t = char
39
+ rbx.platform.typedef.daddr_t = long
40
+ rbx.platform.typedef.cnt_t = short
41
+ rbx.platform.typedef.ptrdiff_t = long
42
+ rbx.platform.typedef.pfn_t = ulong
43
+ rbx.platform.typedef.pgcnt_t = ulong
44
+ rbx.platform.typedef.spgcnt_t = long
45
+ rbx.platform.typedef.use_t = uchar
46
+ rbx.platform.typedef.sysid_t = short
47
+ rbx.platform.typedef.index_t = short
48
+ rbx.platform.typedef.off_t = long
49
+ rbx.platform.typedef.off64_t = long
50
+ rbx.platform.typedef.ino_t = ulong
51
+ rbx.platform.typedef.blkcnt_t = long
52
+ rbx.platform.typedef.fsblkcnt_t = ulong
53
+ rbx.platform.typedef.fsfilcnt_t = ulong
54
+ rbx.platform.typedef.ino64_t = ulong
55
+ rbx.platform.typedef.blkcnt64_t = long
56
+ rbx.platform.typedef.fsblkcnt64_t = ulong
57
+ rbx.platform.typedef.fsfilcnt64_t = ulong
58
+ rbx.platform.typedef.blksize_t = int
59
+ rbx.platform.typedef.pad64_t = long
60
+ rbx.platform.typedef.upad64_t = ulong
61
+ rbx.platform.typedef.offset_t = long_long
62
+ rbx.platform.typedef.u_offset_t = ulong_long
63
+ rbx.platform.typedef.len_t = ulong_long
64
+ rbx.platform.typedef.diskaddr_t = ulong_long
65
+ rbx.platform.typedef.k_fltset_t = uint
66
+ rbx.platform.typedef.id_t = int
67
+ rbx.platform.typedef.lgrp_id_t = int
68
+ rbx.platform.typedef.useconds_t = uint
69
+ rbx.platform.typedef.suseconds_t = long
70
+ rbx.platform.typedef.major_t = uint
71
+ rbx.platform.typedef.minor_t = uint
72
+ rbx.platform.typedef.pri_t = short
73
+ rbx.platform.typedef.cpu_flag_t = ushort
74
+ rbx.platform.typedef.o_mode_t = ushort
75
+ rbx.platform.typedef.o_dev_t = short
76
+ rbx.platform.typedef.o_uid_t = ushort
77
+ rbx.platform.typedef.o_gid_t = ushort
78
+ rbx.platform.typedef.o_nlink_t = short
79
+ rbx.platform.typedef.o_pid_t = short
80
+ rbx.platform.typedef.o_ino_t = ushort
81
+ rbx.platform.typedef.key_t = int
82
+ rbx.platform.typedef.mode_t = uint
83
+ rbx.platform.typedef.uid_t = uint
84
+ rbx.platform.typedef.gid_t = uint
85
+ rbx.platform.typedef.datalink_id_t = uint
86
+ rbx.platform.typedef.taskid_t = int
87
+ rbx.platform.typedef.projid_t = int
88
+ rbx.platform.typedef.poolid_t = int
89
+ rbx.platform.typedef.zoneid_t = int
90
+ rbx.platform.typedef.ctid_t = int
91
+ rbx.platform.typedef.pthread_t = uint
92
+ rbx.platform.typedef.pthread_key_t = uint
93
+ rbx.platform.typedef.dev_t = ulong
94
+ rbx.platform.typedef.nlink_t = uint
95
+ rbx.platform.typedef.pid_t = int
96
+ rbx.platform.typedef.size_t = ulong
97
+ rbx.platform.typedef.ssize_t = long
98
+ rbx.platform.typedef.time_t = long
99
+ rbx.platform.typedef.clock_t = long
100
+ rbx.platform.typedef.clockid_t = int
101
+ rbx.platform.typedef.timer_t = int
102
+ rbx.platform.typedef.unchar = uchar
103
+ rbx.platform.typedef.ushort = ushort
104
+ rbx.platform.typedef.uint = uint
105
+ rbx.platform.typedef.ulong = ulong
106
+ rbx.platform.typedef.u_char = uchar
107
+ rbx.platform.typedef.u_short = ushort
108
+ rbx.platform.typedef.u_int = uint
109
+ rbx.platform.typedef.u_long = ulong
110
+ rbx.platform.typedef.hrtime_t = long_long
111
+ rbx.platform.typedef.fd_mask = long
112
+ rbx.platform.typedef.fds_mask = long
113
+ rbx.platform.typedef.sa_family_t = ushort
114
+ rbx.platform.typedef.socklen_t = uint
115
+ rbx.platform.typedef.nfds_t = ulong
116
+ rbx.platform.typedef.disp_lock_t = uchar
117
+ rbx.platform.typedef.model_t = uint
118
+ rbx.platform.typedef.in_port_t = ushort
119
+ rbx.platform.typedef.in_addr_t = uint
120
+ rbx.platform.typedef.ipaddr_t = uint
121
+ rbx.platform.typedef.rlim_t = ulong
122
+ rbx.platform.typedef.rlim64_t = ulong_long
@@ -222,7 +222,7 @@ module FFI
222
222
  def aligned(alignment = 1)
223
223
  @min_alignment = alignment
224
224
  end
225
- alias :align :aligned
225
+ alias_method :align, :aligned
226
226
 
227
227
  def enclosing_module
228
228
  begin
@@ -16,7 +16,7 @@ module FFI
16
16
  indent = $1
17
17
  original_lines = $2.count "\n"
18
18
 
19
- instance_eval $2
19
+ instance_eval $2, @ffi_name, $`.count("\n")
20
20
 
21
21
  new_lines = []
22
22
  @constants.each { |c| new_lines << c.to_ruby }
@@ -126,7 +126,7 @@ module FFI
126
126
  native_type Type::POINTER
127
127
 
128
128
  def self.from_native(val, ctx)
129
- [ val.null? ? Qnil : val.get_string(0), val ]
129
+ [ val.null? ? nil : val.get_string(0), val ]
130
130
  end
131
131
 
132
132
  end
@@ -148,6 +148,7 @@ module FFI
148
148
  end
149
149
  }
150
150
  end
151
+ typedef :pointer, :caddr_t
151
152
  rescue Errno::ENOENT
152
153
  end
153
154
  end
@@ -0,0 +1,65 @@
1
+ #
2
+ # This file is part of ruby-ffi.
3
+ #
4
+ # This code is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU Lesser General Public License version 3 only, as
6
+ # published by the Free Software Foundation.
7
+ #
8
+ # This code is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # version 3 for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+
18
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
19
+
20
+ describe "Pointer#dup" do
21
+ it "clone should be independent" do
22
+ p1 = FFI::MemoryPointer.new(:char, 1024)
23
+ p1.put_string(0, "test123");
24
+ p2 = p1.dup
25
+ p1.put_string(0, "deadbeef")
26
+
27
+ p2.get_string(0).should == "test123"
28
+ end
29
+
30
+ it "sliced pointer can be cloned" do
31
+ p1 = FFI::MemoryPointer.new(:char, 1024)
32
+ p1.put_string(0, "test123");
33
+ p2 = p1[1].dup
34
+
35
+ # first char will be excised
36
+ p2.get_string(0).should == "est123"
37
+ p1.get_string(0).should == "test123"
38
+ end
39
+
40
+ it "sliced pointer when cloned is independent" do
41
+ p1 = FFI::MemoryPointer.new(:char, 1024)
42
+ p1.put_string(0, "test123");
43
+ p2 = p1[1].dup
44
+
45
+ p1.put_string(0, "deadbeef")
46
+ # first char will be excised
47
+ p2.get_string(0).should == "est123"
48
+ end
49
+ end
50
+
51
+
52
+ describe "Struct#dup" do
53
+ it "clone should be independent" do
54
+ s = Class.new(FFI::Struct) do
55
+ layout :i, :int
56
+ end
57
+ s1 = s.new
58
+ s1[:i] = 0x12345
59
+ s2 = s1.dup
60
+ s1[:i] = 0x98765
61
+ s2[:i].should == 0x12345
62
+ s1[:i].should == 0x98765
63
+ end
64
+
65
+ end