ffi 1.2.0.pre1 → 1.2.0.pre2

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.

@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -3,6 +3,10 @@
3
3
  #include <stdarg.h>
4
4
  #include <float.h>
5
5
 
6
+ #if defined (__CYGWIN__) || defined(__INTERIX)
7
+ # define strtold(str, endptr) ((long double) strtod((str), (endptr)))
8
+ #endif /* defined (__CYGWIN__) */
9
+
6
10
  static VALUE rb_cBigDecimal = Qnil;
7
11
  static VALUE bigdecimal_load(VALUE unused);
8
12
  static VALUE bigdecimal_failed(VALUE value);
@@ -0,0 +1,65 @@
1
+ #include "LongDouble.h"
2
+ #include <stdio.h>
3
+ #include <stdarg.h>
4
+ #include <float.h>
5
+
6
+ #if defined (__CYGWIN__) || defined(__INTERIX)
7
+
8
+ #define strtold(str, endptr) ((long double)strtod((str),(endptr)))
9
+
10
+ #endif /* defined (__CYGWIN__) */
11
+
12
+ static VALUE rb_cBigDecimal = Qnil;
13
+ static VALUE bigdecimal_load(VALUE unused);
14
+ static VALUE bigdecimal_failed(VALUE value);
15
+
16
+ VALUE
17
+ rbffi_longdouble_new(long double ld)
18
+ {
19
+ if (!RTEST(rb_cBigDecimal)) {
20
+ /* allow fallback if the bigdecimal library is unavailable in future ruby versions */
21
+ rb_cBigDecimal = rb_rescue(bigdecimal_load, Qnil, bigdecimal_failed, rb_cObject);
22
+ }
23
+
24
+ if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject) {
25
+ char buf[128];
26
+ return rb_funcall(rb_cBigDecimal, rb_intern("new"), 1, rb_str_new(buf, sprintf(buf, "%.35Le", ld)));
27
+ }
28
+
29
+ /* Fall through to handling as a float */
30
+ return rb_float_new(ld);
31
+ }
32
+
33
+ long double
34
+ rbffi_num2longdouble(VALUE value)
35
+ {
36
+ if (TYPE(value) == T_FLOAT) {
37
+ return rb_num2dbl(value);
38
+ }
39
+
40
+ if (!RTEST(rb_cBigDecimal) && rb_const_defined(rb_cObject, rb_intern("BigDecimal"))) {
41
+ rb_cBigDecimal = rb_const_get(rb_cObject, rb_intern("BigDecimal"));
42
+ }
43
+
44
+ if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject && RTEST(rb_obj_is_kind_of(value, rb_cBigDecimal))) {
45
+ VALUE s = rb_funcall(value, rb_intern("to_s"), 1, rb_str_new2("E"));
46
+ return strtold(RSTRING_PTR(s), NULL);
47
+ }
48
+
49
+ /* Fall through to handling as a float */
50
+ return rb_num2dbl(value);
51
+ }
52
+
53
+
54
+ static VALUE
55
+ bigdecimal_load(VALUE unused)
56
+ {
57
+ rb_require("bigdecimal");
58
+ return rb_const_get(rb_cObject, rb_intern("BigDecimal"));
59
+ }
60
+
61
+ static VALUE
62
+ bigdecimal_failed(VALUE value)
63
+ {
64
+ return value;
65
+ }
@@ -77,7 +77,7 @@ typedef int bool;
77
77
  static bool prep_trampoline(void* ctx, void* code, Closure* closure, char* errmsg, size_t errmsgsize);
78
78
  static long trampoline_size(void);
79
79
 
80
- #if defined(__x86_64__) && defined(__GNUC__)
80
+ #if defined(__x86_64__) && defined(__GNUC__) && !defined(__sun)
81
81
  # define CUSTOM_TRAMPOLINE 1
82
82
  #endif
83
83
 
@@ -27,7 +27,7 @@ $(LIBFFI):
27
27
  @if [ ! -f ${LIBFFI_BUILD_DIR}/Makefile ]; then \
28
28
  echo "Configuring libffi"; \
29
29
  cd ${LIBFFI_BUILD_DIR} && \
30
- /usr/bin/env CC="${CC}" LD="${LD}" CFLAGS="${LIBFFI_CFLAGS}" \
30
+ /usr/bin/env CC="${CC}" LD="${LD}" CFLAGS="${LIBFFI_CFLAGS}" GREP_OPTIONS="" \
31
31
  /bin/sh ${LIBFFI_CONFIGURE} ${LIBFFI_HOST} > /dev/null; \
32
32
  fi
33
33
  @cd ${LIBFFI_BUILD_DIR} && ${MAKE}
@@ -9,15 +9,17 @@ INCFLAGS += -I"$(BUILD_DIR)"
9
9
 
10
10
  # Work out which arches we need to compile the lib for
11
11
  ARCHES :=
12
- ifneq ($(findstring -arch ppc,$(CFLAGS)),)
12
+ ARCHFLAGS ?= $(filter -arch %, $(CFLAGS))
13
+
14
+ ifneq ($(findstring -arch ppc,$(ARCHFLAGS)),)
13
15
  ARCHES += ppc
14
16
  endif
15
17
 
16
- ifneq ($(findstring -arch i386,$(CFLAGS)),)
18
+ ifneq ($(findstring -arch i386,$(ARCHFLAGS)),)
17
19
  ARCHES += i386
18
20
  endif
19
21
 
20
- ifneq ($(findstring -arch x86_64,$(CFLAGS)),)
22
+ ifneq ($(findstring -arch x86_64,$(ARCHFLAGS)),)
21
23
  ARCHES += x86_64
22
24
  endif
23
25
 
@@ -29,7 +31,7 @@ $(LIBFFI):
29
31
  @if [ ! -f "$(LIBFFI_BUILD_DIR)"/Makefile ]; then \
30
32
  echo "Configuring libffi"; \
31
33
  cd "$(LIBFFI_BUILD_DIR)" && \
32
- /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" \
34
+ /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" GREP_OPTIONS="" \
33
35
  /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
34
36
  fi
35
37
  cd "$(LIBFFI_BUILD_DIR)" && $(MAKE)
@@ -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 CFLAGS="$(LIBFFI_CFLAGS)" \
10
+ /usr/bin/env CFLAGS="$(LIBFFI_CFLAGS)" GREP_OPTIONS="" \
11
11
  /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
12
12
  fi
13
13
  $(MAKE) -C "$(LIBFFI_BUILD_DIR)"
@@ -94,11 +94,19 @@ module FFI
94
94
  @releaser.autorelease=(autorelease)
95
95
  end
96
96
 
97
+ # @return [Boolean] +autorelease+
98
+ # Get +autorelease+ property. See {Pointer Autorelease section at Pointer}.
99
+ def autorelease?
100
+ @releaser.autorelease
101
+ end
102
+
97
103
  # @abstract Base class for {AutoPointer}'s releasers.
98
104
  #
99
105
  # All subclasses of Releaser should define a +#release(ptr)+ method.
100
106
  # A releaser is an object in charge of release an {AutoPointer}.
101
107
  class Releaser
108
+ attr_accessor :autorelease
109
+
102
110
  # @param [Pointer] ptr
103
111
  # @param [#call] proc
104
112
  # @return [nil]
@@ -119,14 +127,7 @@ module FFI
119
127
  @proc = nil
120
128
  end
121
129
  end
122
-
123
- # @param [Boolean] autorelease
124
- # @return [Boolean] autorelease
125
- # Set +autorelease+ attribute for pointer managed by Releaser.
126
- def autorelease=(autorelease)
127
- @autorelease = autorelease if @ptr
128
- end
129
-
130
+
130
131
  # @param args
131
132
  # Release pointer if +autorelease+ is set.
132
133
  def call(*args)
@@ -86,6 +86,7 @@ module FFI
86
86
  info.each do |i|
87
87
  case i
88
88
  when Symbol
89
+ raise ArgumentError, "duplicate enum key" if @kv_map.has_key?(i)
89
90
  @kv_map[i] = value
90
91
  last_cst = i
91
92
  value += 1
@@ -95,7 +96,7 @@ module FFI
95
96
  end
96
97
  end
97
98
  end
98
- @vk_map = Hash[@kv_map.map{|k,v| [v,k]}]
99
+ @vk_map = @kv_map.invert
99
100
  end
100
101
 
101
102
  # @return [Array] enum symbol names
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+ #include <sys/types.h>
21
+ #include <stdint.h>
22
+
23
+ void returnVoid() {
24
+
25
+ }
26
+
27
+ void returnVoidI(int arg) {
28
+
29
+ }
30
+ int returnInt() {
31
+ return 0;
32
+ }
33
+
34
+ int returnIntI(int arg) {
35
+ return arg;
36
+ }
37
+
38
+ typedef int8_t s8;
39
+ typedef uint8_t u8;
40
+ typedef int16_t s16;
41
+ typedef uint16_t u16;
42
+ typedef int32_t s32;
43
+ typedef uint32_t u32;
44
+ typedef int64_t s64;
45
+ typedef uint64_t u64;
46
+ typedef float f32;
47
+ typedef double f64;
48
+ typedef void v;
49
+ typedef char* S;
50
+ typedef void* P;
51
+
52
+ #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) {}
53
+ #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) {}
54
+ #define B4(R, T1, T2, T3, T4) R bench_##T1##T2##T3##T4##_##R(T1 a1, T2 a2, T3 a3, T4 a4) {}
55
+ #define B3(R, T1, T2, T3) R bench_##T1##T2##T3##_##R(T1 a1, T2 a2, T3 a3) {}
56
+ #define B2(R, T1, T2) R bench_##T1##T2##_##R(T1 a1, T2 a2) {}
57
+ #define B1(R, T1) R bench_##T1##_##R(T1 a1) {}
58
+ #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);
59
+ BrV(u32);
60
+ BrV(s32);
61
+ BrV(s64);
62
+ BrV(u64);
63
+ BrV(f32);
64
+ BrV(f64);
65
+ BrV(S);
66
+ BrV(P);
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright (c) 2009 Aman Gupta. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #include <stdbool.h>
22
+
23
+ bool
24
+ bool_return_true()
25
+ {
26
+ return true;
27
+ }
28
+
29
+ bool
30
+ bool_return_false()
31
+ {
32
+ return false;
33
+ }
34
+
35
+ bool
36
+ bool_return_val(bool value)
37
+ {
38
+ return value;
39
+ }
40
+
41
+ bool
42
+ bool_reverse_val(bool value)
43
+ {
44
+ return value ? false : true;
45
+ }