ffi 0.6.4 → 1.0.0

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 (92) hide show
  1. data/History.txt +7 -0
  2. data/LICENSE +10 -21
  3. data/README.rdoc +70 -0
  4. data/Rakefile +56 -84
  5. data/ext/ffi_c/AbstractMemory.c +56 -38
  6. data/ext/ffi_c/AbstractMemory.h +15 -22
  7. data/ext/ffi_c/Buffer.c +61 -22
  8. data/ext/ffi_c/Call.c +52 -540
  9. data/ext/ffi_c/Call.h +1 -1
  10. data/ext/ffi_c/DataConverter.c +62 -0
  11. data/ext/ffi_c/DynamicLibrary.c +21 -1
  12. data/ext/ffi_c/Function.c +252 -30
  13. data/ext/ffi_c/MappedType.c +146 -0
  14. data/{libtest/FunctionTest.c → ext/ffi_c/MappedType.h} +32 -25
  15. data/ext/ffi_c/MemoryPointer.c +12 -33
  16. data/ext/ffi_c/Platform.c +2 -0
  17. data/ext/ffi_c/Pointer.c +66 -28
  18. data/ext/ffi_c/Struct.c +19 -306
  19. data/ext/ffi_c/Struct.h +6 -0
  20. data/ext/ffi_c/StructByReference.c +150 -0
  21. data/{libtest/LastErrorTest.c → ext/ffi_c/StructByReference.h} +30 -21
  22. data/ext/ffi_c/StructLayout.c +26 -16
  23. data/ext/ffi_c/Type.c +39 -68
  24. data/ext/ffi_c/Type.h +12 -22
  25. data/ext/ffi_c/Types.c +20 -5
  26. data/ext/ffi_c/Types.h +7 -7
  27. data/ext/ffi_c/Variadic.c +21 -17
  28. data/ext/ffi_c/extconf.rb +4 -0
  29. data/ext/ffi_c/ffi.c +8 -2
  30. data/ext/ffi_c/rbffi.h +1 -0
  31. data/lib/ffi/autopointer.rb +23 -22
  32. data/lib/ffi/enum.rb +36 -21
  33. data/lib/ffi/errno.rb +20 -0
  34. data/lib/ffi/ffi.rb +13 -80
  35. data/lib/ffi/io.rb +12 -20
  36. data/lib/ffi/library.rb +109 -92
  37. data/lib/ffi/managedstruct.rb +1 -1
  38. data/lib/ffi/memorypointer.rb +15 -21
  39. data/lib/ffi/platform.rb +27 -33
  40. data/lib/ffi/pointer.rb +14 -21
  41. data/lib/ffi/struct.rb +98 -49
  42. data/lib/ffi/struct_layout_builder.rb +158 -0
  43. data/lib/ffi/types.rb +99 -128
  44. data/lib/ffi/union.rb +20 -0
  45. data/lib/ffi/variadic.rb +33 -22
  46. data/spec/ffi/async_callback_spec.rb +23 -0
  47. data/spec/ffi/callback_spec.rb +62 -0
  48. data/spec/ffi/custom_param_type.rb +31 -0
  49. data/spec/ffi/custom_type_spec.rb +73 -0
  50. data/spec/ffi/enum_spec.rb +19 -0
  51. data/spec/ffi/ffi_spec.rb +24 -0
  52. data/spec/ffi/pointer_spec.rb +15 -0
  53. data/spec/ffi/rbx/memory_pointer_spec.rb +7 -1
  54. data/spec/ffi/strptr_spec.rb +36 -0
  55. data/spec/ffi/struct_packed_spec.rb +46 -0
  56. data/spec/ffi/struct_spec.rb +19 -5
  57. data/spec/ffi/typedef_spec.rb +14 -0
  58. data/tasks/ann.rake +80 -0
  59. data/tasks/extension.rake +25 -0
  60. data/tasks/gem.rake +200 -0
  61. data/tasks/git.rake +41 -0
  62. data/tasks/notes.rake +27 -0
  63. data/tasks/post_load.rake +34 -0
  64. data/tasks/rdoc.rake +50 -0
  65. data/tasks/rubyforge.rake +55 -0
  66. data/tasks/setup.rb +301 -0
  67. data/tasks/spec.rake +54 -0
  68. data/tasks/svn.rake +47 -0
  69. data/tasks/test.rake +40 -0
  70. metadata +139 -131
  71. data/README.md +0 -109
  72. data/ext/ffi_c/AutoPointer.c +0 -60
  73. data/ext/ffi_c/AutoPointer.h +0 -18
  74. data/ext/ffi_c/Ffi_c.iml +0 -12
  75. data/ffi.gemspec +0 -18
  76. data/gen/log +0 -1
  77. data/lib/Lib.iml +0 -21
  78. data/libtest/Benchmark.c +0 -73
  79. data/libtest/BoolTest.c +0 -52
  80. data/libtest/BufferTest.c +0 -52
  81. data/libtest/ClosureTest.c +0 -173
  82. data/libtest/EnumTest.c +0 -55
  83. data/libtest/GNUmakefile +0 -141
  84. data/libtest/GlobalVariable.c +0 -56
  85. data/libtest/NumberTest.c +0 -145
  86. data/libtest/PointerTest.c +0 -84
  87. data/libtest/ReferenceTest.c +0 -44
  88. data/libtest/StringTest.c +0 -55
  89. data/libtest/StructTest.c +0 -247
  90. data/libtest/UnionTest.c +0 -64
  91. data/libtest/VariadicTest.c +0 -57
  92. data/spec/ffi/Ffi.iml +0 -12
data/README.md DELETED
@@ -1,109 +0,0 @@
1
- # ruby-ffi http://wiki.github.com/ffi/ffi [![Build Status](https://travis-ci.org/ffi/ffi.png?branch=master)](https://travis-ci.org/ffi/ffi)
2
-
3
- ## Description
4
-
5
- Ruby-FFI is a ruby extension for programmatically loading dynamic
6
- libraries, binding functions within them, and calling those functions
7
- from Ruby code. Moreover, a Ruby-FFI extension works without changes
8
- on Ruby and JRuby. Discover why should you write your next extension
9
- using Ruby-FFI [here](http://wiki.github.com/ffi/ffi/why-use-ffi).
10
-
11
- ## Features/problems
12
-
13
- * Intuitive DSL
14
- * Supports all C native types
15
- * C structs (also nested), enums and global variables
16
- * Callbacks from C to ruby
17
- * Automatic garbage collection of native memory
18
-
19
- ## Synopsis
20
-
21
- ```ruby
22
- require 'ffi'
23
-
24
- module MyLib
25
- extend FFI::Library
26
- ffi_lib 'c'
27
- attach_function :puts, [ :string ], :int
28
- end
29
-
30
- MyLib.puts 'Hello, World using libc!'
31
- ```
32
-
33
- For less minimalistic and more sane examples you may look at:
34
-
35
- * the samples/ folder
36
- * the examples on the [wiki](http://wiki.github.com/ffi/ffi)
37
- * the projects using FFI listed on this page (http://wiki.github.com/ffi/ffi/projects-using-ffi)
38
-
39
- ## Requirements
40
-
41
- You need a sane building environment in order to compile the extension.
42
- At a minimum, you will need:
43
- * A C compiler (e.g. Xcode on OSX, gcc on everything else)
44
- * libffi development library - this is commonly in the libffi-dev or libffi-devel
45
-
46
- ## Installation
47
-
48
- From rubygems:
49
-
50
- [sudo] gem install ffi
51
-
52
- or from the git repository on github:
53
-
54
- git clone git://github.com/ffi/ffi.git
55
- cd ffi
56
- rake gem:install
57
-
58
- ## License
59
-
60
- The ffi library is covered by the LGPL3 license, also see the LICENSE file.
61
- The specs are shared with Rubyspec and are licensed by the same license
62
- as Rubyspec, see the LICENSE.SPECS file.
63
-
64
- ## Credits
65
-
66
- The following people have submitted code, bug reports, or otherwide contributed to the success of this project:
67
-
68
- * Alban Peignier <alban.peignier@free.fr>
69
- * Aman Gupta <aman@tmm1.net>
70
- * Andrea Fazzi <andrea.fazzi@alcacoop.it>
71
- * Andreas Niederl <rico32@gmx.net>
72
- * Andrew Cholakian <andrew@andrewvc.com>
73
- * Antonio Terceiro <terceiro@softwarelivre.org>
74
- * Brian Candler <B.Candler@pobox.com>
75
- * Brian D. Burns <burns180@gmail.com>
76
- * Bryan Kearney <bkearney@redhat.com>
77
- * Charlie Savage <cfis@zerista.com>
78
- * Chikanaga Tomoyuki <nagachika00@gmail.com>
79
- * Hongli Lai <hongli@phusion.nl>
80
- * Ian MacLeod <ian@nevir.net>
81
- * Jake Douglas <jake@shiftedlabs.com>
82
- * Jean-Dominique Morani <jdmorani@mac.com>
83
- * Jeremy Hinegardner <jeremy@hinegardner.org>
84
- * Jesús García Sáez <blaxter@gmail.com>
85
- * Joe Khoobyar <joe@ankhcraft.com>
86
- * Jurij Smakov <jurij@wooyd.org>
87
- * KISHIMOTO, Makoto <ksmakoto@dd.iij4u.or.jp>
88
- * Kim Burgestrand <kim@burgestrand.se>
89
- * Lars Kanis <kanis@comcard.de>
90
- * Luc Heinrich <luc@honk-honk.com>
91
- * Luis Lavena <luislavena@gmail.com>
92
- * Matijs van Zuijlen <matijs@matijs.net>
93
- * Matthew King <automatthew@gmail.com>
94
- * Mike Dalessio <mike.dalessio@gmail.com>
95
- * NARUSE, Yui <naruse@airemix.jp>
96
- * Park Heesob <phasis@gmail.com>
97
- * Shin Yee <shinyee@speedgocomputing.com>
98
- * Stephen Bannasch <stephen.bannasch@gmail.com>
99
- * Suraj N. Kurapati <sunaku@gmail.com>
100
- * Sylvain Daubert <sylvain.daubert@laposte.net>
101
- * Victor Costan
102
- * beoran@gmail.com
103
- * ctide <christide@christide.com>
104
- * emboss <Martin.Bosslet@googlemail.com>
105
- * hobophobe <unusualtears@gmail.com>
106
- * meh <meh@paranoici.org>
107
- * postmodern <postmodern.mod3@gmail.com>
108
- * wycats@gmail.com <wycats@gmail.com>
109
- * Wayne Meissner <wmeissner@gmail.com>
@@ -1,60 +0,0 @@
1
-
2
- #include <stdbool.h>
3
- #include <stdint.h>
4
- #include <limits.h>
5
- #include <ruby.h>
6
- #include "rbffi.h"
7
- #include "AbstractMemory.h"
8
- #include "Pointer.h"
9
- #include "AutoPointer.h"
10
-
11
- typedef struct AutoPointer {
12
- AbstractMemory memory;
13
- VALUE parent;
14
- } AutoPointer;
15
-
16
- static void autoptr_mark(AutoPointer* ptr);
17
- static VALUE autoptr_allocate(VALUE klass);
18
- static VALUE autoptr_set_parent(VALUE self, VALUE parent);
19
-
20
- VALUE rbffi_AutoPointerClass = Qnil;
21
-
22
- static VALUE
23
- autoptr_allocate(VALUE klass)
24
- {
25
- AutoPointer* p;
26
- VALUE obj = Data_Make_Struct(klass, AutoPointer, autoptr_mark, -1, p);
27
- p->parent = Qnil;
28
- p->memory.access = MEM_RD | MEM_WR;
29
-
30
- return obj;
31
- }
32
-
33
- static VALUE
34
- autoptr_set_parent(VALUE self, VALUE parent)
35
- {
36
- AutoPointer* p;
37
- AbstractMemory* ptr = rbffi_AbstractMemory_Cast(parent, rbffi_PointerClass);
38
-
39
- Data_Get_Struct(self, AutoPointer, p);
40
- p->memory = *ptr;
41
- p->parent = parent;
42
-
43
- return self;
44
- }
45
-
46
- static void
47
- autoptr_mark(AutoPointer* ptr)
48
- {
49
- rb_gc_mark(ptr->parent);
50
- }
51
-
52
- void
53
- rbffi_AutoPointer_Init(VALUE moduleFFI)
54
- {
55
- rbffi_AutoPointerClass = rb_define_class_under(moduleFFI, "AutoPointer", rbffi_PointerClass);
56
- rb_global_variable(&rbffi_AutoPointerClass);
57
-
58
- rb_define_alloc_func(rbffi_AutoPointerClass, autoptr_allocate);
59
- rb_define_protected_method(rbffi_AutoPointerClass, "parent=", autoptr_set_parent, 1);
60
- }
@@ -1,18 +0,0 @@
1
-
2
- #ifndef _AUTOPOINTER_H
3
- #define _AUTOPOINTER_H
4
-
5
- #ifdef __cplusplus
6
- extern "C" {
7
- #endif
8
-
9
- extern void rbffi_AutoPointer_Init(VALUE ffiModule);
10
- extern VALUE rbffi_AutoPointerClass;
11
-
12
-
13
- #ifdef __cplusplus
14
- }
15
- #endif
16
-
17
- #endif /* _AUTOPOINTER_H */
18
-
data/ext/ffi_c/Ffi_c.iml DELETED
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$">
6
- <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
7
- </content>
8
- <orderEntry type="inheritedJdk" />
9
- <orderEntry type="sourceFolder" forTests="false" />
10
- </component>
11
- </module>
12
-
data/ffi.gemspec DELETED
@@ -1,18 +0,0 @@
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/log DELETED
@@ -1 +0,0 @@
1
- /Users/wayne/src/ruby-ffi/lib/ffi/platform/x86_64-darwin/types.conf
data/lib/Lib.iml DELETED
@@ -1,21 +0,0 @@
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/libtest/Benchmark.c DELETED
@@ -1,73 +0,0 @@
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);
data/libtest/BoolTest.c DELETED
@@ -1,52 +0,0 @@
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
- }
data/libtest/BufferTest.c DELETED
@@ -1,52 +0,0 @@
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
-
@@ -1,173 +0,0 @@
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
-