ffi 0.6.0 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi
14
14
  ifeq ($(srcdir),.)
15
15
  LIBFFI_SRC_DIR := $(shell pwd)/libffi
16
16
  else
17
- LIBFFI_SRC_DIR := $(srcdir)/libffi
17
+ LIBFFI_SRC_DIR := $(abspath $(srcdir)/libffi)
18
18
  endif
19
19
 
20
20
  LIBFFI = $(LIBFFI_BUILD_DIR)/.libs/libffi_convenience.a
data/ext/ffi_c/libffi.mk CHANGED
@@ -7,7 +7,7 @@ $(LIBFFI):
7
7
  @if [ ! -f $(LIBFFI_BUILD_DIR)/Makefile ]; then \
8
8
  echo "Configuring libffi"; \
9
9
  cd $(LIBFFI_BUILD_DIR) && \
10
- /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" \
10
+ /usr/bin/env CFLAGS="$(LIBFFI_CFLAGS)" \
11
11
  /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
12
12
  fi
13
13
  cd $(LIBFFI_BUILD_DIR) && $(MAKE)
data/ffi.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ffi'
3
+ s.version = '0.6.4'
4
+ s.author = 'Wayne Meissner'
5
+ s.email = 'wmeissner@gmail.com'
6
+ s.homepage = 'http://wiki.github.com/ffi/ffi'
7
+ s.summary = 'Ruby FFI'
8
+ s.description = 'Ruby FFI library'
9
+ s.files = %w(ffi.gemspec History.txt LICENSE README.md Rakefile) + Dir.glob("{ext,gen,lib,spec,libtest}/**/*").reject { |f| f =~ /lib\/1\.[89]/}
10
+ s.extensions << 'ext/ffi_c/extconf.rb'
11
+ s.has_rdoc = false
12
+ s.license = 'LGPL-3'
13
+ s.require_paths << 'ext/ffi_c' << 'lib/ffi'
14
+ s.required_ruby_version = '>= 1.8.7'
15
+ s.add_development_dependency 'rake'
16
+ s.add_development_dependency 'rake-compiler', '>=0.6.0'
17
+ s.add_development_dependency 'rspec'
18
+ end
data/gen/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
- require "#{File.join(ENV['RUBYLIBDIR'], 'ffi', 'tools', 'types_generator.rb')}"
3
- types_conf = File.join(ENV['RUBYLIBDIR'], 'ffi', 'types.conf')
2
+ require "#{File.join(File.dirname(__FILE__), '..', 'lib', 'ffi', 'tools', 'types_generator.rb')}"
3
+ types_conf = File.join(File.dirname(__FILE__), '..', 'lib', 'ffi', 'types.conf')
4
+
4
5
  file types_conf do |task|
5
6
  options = {}
6
7
  FileUtils.mkdir_p(File.dirname(task.name), { :mode => 0755 })
@@ -8,5 +9,6 @@ file types_conf do |task|
8
9
  f.puts FFI::TypesGenerator.generate(options)
9
10
  end
10
11
  end
12
+
11
13
  task :default => types_conf do
12
14
  end
data/gen/log ADDED
@@ -0,0 +1 @@
1
+ /Users/wayne/src/ruby-ffi/lib/ffi/platform/x86_64-darwin/types.conf
data/lib/Lib.iml ADDED
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
13
+ <exclude-output />
14
+ <content url="file://$MODULE_DIR$">
15
+ <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
16
+ </content>
17
+ <orderEntry type="inheritedJdk" />
18
+ <orderEntry type="sourceFolder" forTests="false" />
19
+ </component>
20
+ </module>
21
+
data/lib/ffi/ffi.rb CHANGED
@@ -57,6 +57,7 @@ module FFI
57
57
 
58
58
  def self.map_library_name(lib)
59
59
  # Mangle the library name to reflect the native library naming conventions
60
+ lib = lib.to_s unless lib.kind_of?(String)
60
61
  lib = Platform::LIBC if Platform::IS_LINUX && lib == 'c'
61
62
  if lib && File.basename(lib) == lib
62
63
  ext = ".#{Platform::LIBSUFFIX}"
data/lib/ffi/library.rb CHANGED
@@ -42,7 +42,7 @@ module FFI
42
42
 
43
43
  ffi_libs = names.map do |name|
44
44
  if name == FFI::CURRENT_PROCESS
45
- FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL)
45
+ FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL)
46
46
  else
47
47
  libnames = (name.is_a?(::Array) ? name : [ name ]).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
48
48
  lib = nil
@@ -50,7 +50,7 @@ module FFI
50
50
 
51
51
  libnames.each do |libname|
52
52
  begin
53
- lib = FFI::DynamicLibrary.open(libname, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL)
53
+ lib = FFI::DynamicLibrary.open(libname, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL)
54
54
  break if lib
55
55
  rescue Exception => ex
56
56
  errors[libname] = ex
data/lib/ffi/platform.rb CHANGED
@@ -25,12 +25,14 @@
25
25
  # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
26
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
 
28
+ require 'ffi_c'
28
29
  require 'rbconfig'
30
+
29
31
  module FFI
30
32
  class PlatformError < FFI::NativeError; end
31
33
 
32
34
  module Platform
33
- OS = case Config::CONFIG['host_os'].downcase
35
+ OS = case RbConfig::CONFIG['host_os'].downcase
34
36
  when /linux/
35
37
  "linux"
36
38
  when /darwin/
@@ -44,7 +46,7 @@ module FFI
44
46
  when /win|mingw/
45
47
  "windows"
46
48
  else
47
- Config::CONFIG['host_os'].downcase
49
+ RbConfig::CONFIG['host_os'].downcase
48
50
  end
49
51
 
50
52
  ARCH = case CPU.downcase
@@ -55,7 +57,7 @@ module FFI
55
57
  when /ppc|powerpc/
56
58
  "powerpc"
57
59
  else
58
- Config::CONFIG['host_cpu']
60
+ RbConfig::CONFIG['host_cpu']
59
61
  end
60
62
 
61
63
  private
data/lib/ffi/struct.rb CHANGED
@@ -44,11 +44,11 @@ module FFI
44
44
  class Enum < Field
45
45
 
46
46
  def get(ptr)
47
- type.find(ptr.get_int(0))
47
+ type.find(ptr.get_int(offset))
48
48
  end
49
49
 
50
50
  def put(ptr, value)
51
- ptr.put_int(0, type.find(value))
51
+ ptr.put_int(offset, type.find(value))
52
52
  end
53
53
 
54
54
  end
@@ -0,0 +1,73 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * Neither the name of the project nor the names of its contributors
13
+ * may be used to endorse or promote products derived from this software
14
+ * without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+ #include <sys/types.h>
28
+ #include <stdint.h>
29
+
30
+ void returnVoid() {
31
+
32
+ }
33
+
34
+ void returnVoidI(int arg) {
35
+
36
+ }
37
+ int returnInt() {
38
+ return 0;
39
+ }
40
+
41
+ int returnIntI(int arg) {
42
+ return arg;
43
+ }
44
+
45
+ typedef int8_t s8;
46
+ typedef uint8_t u8;
47
+ typedef int16_t s16;
48
+ typedef uint16_t u16;
49
+ typedef int32_t s32;
50
+ typedef uint32_t u32;
51
+ typedef int64_t s64;
52
+ typedef uint64_t u64;
53
+ typedef float f32;
54
+ typedef double f64;
55
+ typedef void v;
56
+ typedef char* S;
57
+ typedef void* P;
58
+
59
+ #define B6(R, T1, T2, T3, T4, T5, T6) R bench_##T1##T2##T3##T4##T5##T6##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) {}
60
+ #define B5(R, T1, T2, T3, T4, T5) R bench_##T1##T2##T3##T4##T5##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {}
61
+ #define B4(R, T1, T2, T3, T4) R bench_##T1##T2##T3##T4##_##R(T1 a1, T2 a2, T3 a3, T4 a4) {}
62
+ #define B3(R, T1, T2, T3) R bench_##T1##T2##T3##_##R(T1 a1, T2 a2, T3 a3) {}
63
+ #define B2(R, T1, T2) R bench_##T1##T2##_##R(T1 a1, T2 a2) {}
64
+ #define B1(R, T1) R bench_##T1##_##R(T1 a1) {}
65
+ #define BrV(T) B1(v, T); B2(v, T, T); B3(v, T, T, T); B4(v, T, T, T, T); B5(v, T, T, T, T, T); B6(v, T, T, T, T, T, T);
66
+ BrV(u32);
67
+ BrV(s32);
68
+ BrV(s64);
69
+ BrV(u64);
70
+ BrV(f32);
71
+ BrV(f64);
72
+ BrV(S);
73
+ BrV(P);
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright (c) 2009 Aman Gupta. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * Neither the name of the project nor the names of its contributors
13
+ * may be used to endorse or promote products derived from this software
14
+ * without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #include <stdbool.h>
29
+
30
+ bool
31
+ bool_return_true()
32
+ {
33
+ return true;
34
+ }
35
+
36
+ bool
37
+ bool_return_false()
38
+ {
39
+ return false;
40
+ }
41
+
42
+ bool
43
+ bool_return_val(bool value)
44
+ {
45
+ return value;
46
+ }
47
+
48
+ bool
49
+ bool_reverse_val(bool value)
50
+ {
51
+ return value ? false : true;
52
+ }
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright (C) 2007 Wayne Meissner
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * Neither the name of the project nor the names of its contributors
13
+ * may be used to endorse or promote products derived from this software
14
+ * without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+
29
+ #define MEMSET(buf, value, size) do { \
30
+ int i; for (i = 0; i < size; ++i) buf[i] = value; \
31
+ } while(0)
32
+ #define MEMCPY(dst, src, size) do { \
33
+ int i; for (i = 0; i < size; ++i) dst[i] = src[i]; \
34
+ } while(0)
35
+
36
+ #define FILL(JTYPE, CTYPE) \
37
+ void fill##JTYPE##Buffer(CTYPE* buf, CTYPE value, int size) { MEMSET(buf, value, size); }
38
+
39
+ #define COPY(JTYPE, CTYPE) \
40
+ void copy##JTYPE##Buffer(CTYPE* dst, CTYPE* src, int size) { MEMCPY(dst, src, size); }
41
+
42
+ #define FUNC(JTYPE, CTYPE) \
43
+ FILL(JTYPE, CTYPE); \
44
+ COPY(JTYPE, CTYPE)
45
+
46
+ FUNC(Byte, char);
47
+ FUNC(Short, short);
48
+ FUNC(Int, int);
49
+ FUNC(Long, long long);
50
+ FUNC(Float, float);
51
+ FUNC(Double, double);
52
+
@@ -0,0 +1,173 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * Neither the name of the project nor the names of its contributors
13
+ * may be used to endorse or promote products derived from this software
14
+ * without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #include <stdlib.h>
29
+ #include <stdbool.h>
30
+
31
+ #define R(T, rtype) rtype testClosureVr##T(rtype (*closure)(void)) { \
32
+ return closure != NULL ? (*closure)() : (rtype) 0; \
33
+ }
34
+
35
+ #define P(T, ptype) void testClosure##T##rV(void (*closure)(ptype), ptype a1) { \
36
+ if (closure != NULL) (*closure)(a1); \
37
+ }
38
+
39
+ void testClosureVrV(void (*closure)(void))
40
+ {
41
+ (*closure)();
42
+ }
43
+
44
+ R(Z, bool);
45
+ R(B, char);
46
+ R(S, short);
47
+ R(I, int);
48
+ R(L, long);
49
+ R(J, long long);
50
+ R(LL, long long);
51
+ R(F, float);
52
+ R(D, double);
53
+ R(P, const void*);
54
+
55
+
56
+ P(Z, bool);
57
+ P(B, char);
58
+ P(S, short);
59
+ P(I, int);
60
+ P(L, long);
61
+ P(J, long long);
62
+ P(LL, long long);
63
+ P(F, float);
64
+ P(D, double);
65
+ P(P, const void*);
66
+ P(UL, unsigned long);
67
+
68
+ void testOptionalClosureBrV(void (*closure)(char), char a1)
69
+ {
70
+ if (closure) {
71
+ (*closure)(a1);
72
+ }
73
+ }
74
+
75
+ struct s8f32s32 {
76
+ char s8;
77
+ float f32;
78
+ int s32;
79
+ };
80
+
81
+ // Takes a struct argument
82
+ void testClosureTrV(void (*closure)(struct s8f32s32 s), struct s8f32s32* s)
83
+ {
84
+ (*closure)(*s);
85
+ }
86
+
87
+ // Returns a struct value
88
+ struct s8f32s32 testClosureVrT(struct s8f32s32 (*closure)())
89
+ {
90
+ return (*closure)();
91
+ }
92
+
93
+ typedef int (*returnTypeClosure_t)(int) ;
94
+ typedef returnTypeClosure_t (*lookupClosure_t)();
95
+
96
+ int testReturnsClosure(lookupClosure_t lookup, int val)
97
+ {
98
+ returnTypeClosure_t func = lookup ? (*lookup)() : NULL;
99
+ return func ? (*func)(val) : 0;
100
+ }
101
+
102
+ static int multiplyByTwo(int value)
103
+ {
104
+ return value * 2;
105
+ }
106
+
107
+ returnTypeClosure_t testReturnsFunctionPointer()
108
+ {
109
+ return multiplyByTwo;
110
+ }
111
+
112
+ typedef int (*argumentClosure_t)(int);
113
+ typedef int (*withArgumentClosure_t)(argumentClosure_t, int);
114
+
115
+ int testArgumentClosure(withArgumentClosure_t closure_with, argumentClosure_t closure_arg, int val)
116
+ {
117
+ return (*closure_with)(closure_arg, val);
118
+ }
119
+
120
+
121
+ //
122
+ // These macros produce functions of the form:
123
+ // testClosureBIrV(void (*closure)(char, int), char a1, int a2) {}
124
+ //
125
+ #define C2_(J1, J2, N1, N2) \
126
+ void testClosure##J1##J2##rV(void (*closure)(N1, N2), N1 a1, N2 a2) \
127
+ { \
128
+ if (closure != NULL) (*closure)(a1, a2); \
129
+ }
130
+
131
+ #define C2(J, N) \
132
+ C2_(B, J, char, N) \
133
+ C2_(S, J, short, N) \
134
+ C2_(I, J, int, N) \
135
+ C2_(LL, J, long long, N) \
136
+ C2_(F, J, float, N) \
137
+ C2_(D, J, double, N) \
138
+
139
+
140
+ C2(B, char);
141
+ C2(S, short);
142
+ C2(I, int);
143
+ C2(LL, long long);
144
+ C2(F, float);
145
+ C2(D, double);
146
+
147
+ #define C3_(J1, J2, J3, N1, N2, N3) \
148
+ void testClosure##J1##J2##J3##rV(void (*closure)(N1, N2, N3), N1 a1, N2 a2, N3 a3) \
149
+ { \
150
+ (*closure)(a1, a2, a3); \
151
+ }
152
+
153
+
154
+ #define C3(J, N) \
155
+ C3_(B, J, B, char, N, char) \
156
+ C3_(S, J, S, short, N, short) \
157
+ C3_(I, J, I, int, N, int) \
158
+ C3_(LL, J, LL, long long, N, long long) \
159
+ C3_(F, J, F, float, N, float) \
160
+ C3_(D, J, D, double, N, double) \
161
+
162
+ C3(B, char);
163
+ C3(S, short);
164
+ C3(I, int);
165
+ C3(LL, long long);
166
+ C3(F, float);
167
+ C3(D, double);
168
+ C3_(B, S, I, char, short, int);
169
+ C3_(B, S, LL, char, short, long long);
170
+ C3_(LL, S, B, long long, short, char);
171
+ C3_(LL, B, S, long long, char, short);
172
+
173
+
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * Neither the name of the project nor the names of its contributors
13
+ * may be used to endorse or promote products derived from this software
14
+ * without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ int test_untagged_enum(int val) {
29
+ return val;
30
+ }
31
+
32
+ int test_untagged_typedef_enum(int val) {
33
+ return val;
34
+ }
35
+
36
+ typedef enum {c1, c2, c3, c4} enum_type1;
37
+ enum_type1 test_tagged_typedef_enum1(enum_type1 val) {
38
+ return val;
39
+ }
40
+
41
+ typedef enum {c5 = 42, c6, c7, c8} enum_type2;
42
+ enum_type2 test_tagged_typedef_enum2(enum_type2 val) {
43
+ return val;
44
+ }
45
+
46
+ typedef enum {c9 = 42, c10, c11 = 4242, c12} enum_type3;
47
+ enum_type3 test_tagged_typedef_enum3(enum_type3 val) {
48
+ return val;
49
+ }
50
+
51
+ typedef enum {c13 = 42, c14 = 4242, c15 = 424242, c16 = 42424242} enum_type4;
52
+ enum_type4 test_tagged_typedef_enum4(enum_type4 val) {
53
+ return val;
54
+ }
55
+
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright (c) 2009 Wayne Meissner. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are met:
6
+ *
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * Neither the name of the project nor the names of its contributors
13
+ * may be used to endorse or promote products derived from this software
14
+ * without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ #include <unistd.h>
29
+
30
+ #ifdef __WIN32__
31
+ #include <windows.h>
32
+ #define sleep(x) Sleep(x)
33
+ #endif
34
+
35
+ int testAdd(int a, int b)
36
+ {
37
+ return a + b;
38
+ };
39
+
40
+ int testFunctionAdd(int a, int b, int (*f)(int, int))
41
+ {
42
+ return f(a, b);
43
+ };
44
+
45
+ void testBlocking(int seconds) {
46
+ sleep(seconds);
47
+ };
48
+
49
+
50
+