fiddle 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fiddle.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fiddle.so'
3
+ if RUBY_ENGINE == 'ruby'
4
+ require 'fiddle.so'
5
+ else
6
+ require 'fiddle/ffi_backend'
7
+ end
4
8
  require 'fiddle/closure'
5
9
  require 'fiddle/function'
6
10
  require 'fiddle/version'
@@ -10,36 +14,63 @@ module Fiddle
10
14
  # Returns the last win32 +Error+ of the current executing +Thread+ or nil
11
15
  # if none
12
16
  def self.win32_last_error
13
- Thread.current[:__FIDDLE_WIN32_LAST_ERROR__]
17
+ if RUBY_ENGINE == 'jruby'
18
+ errno = FFI.errno
19
+ errno == 0 ? nil : errno
20
+ else
21
+ Thread.current[:__FIDDLE_WIN32_LAST_ERROR__]
22
+ end
14
23
  end
15
24
 
16
25
  # Sets the last win32 +Error+ of the current executing +Thread+ to +error+
17
26
  def self.win32_last_error= error
18
- Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
27
+ if RUBY_ENGINE == 'jruby'
28
+ FFI.errno = error || 0
29
+ else
30
+ Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
31
+ end
19
32
  end
20
33
 
21
34
  # Returns the last win32 socket +Error+ of the current executing
22
35
  # +Thread+ or nil if none
23
36
  def self.win32_last_socket_error
24
- Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__]
37
+ if RUBY_ENGINE == 'jruby'
38
+ errno = FFI.errno
39
+ errno == 0 ? nil : errno
40
+ else
41
+ Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__]
42
+ end
25
43
  end
26
44
 
27
45
  # Sets the last win32 socket +Error+ of the current executing
28
46
  # +Thread+ to +error+
29
47
  def self.win32_last_socket_error= error
30
- Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__] = error
48
+ if RUBY_ENGINE == 'jruby'
49
+ FFI.errno = error || 0
50
+ else
51
+ Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__] = error
52
+ end
31
53
  end
32
54
  end
33
55
 
34
56
  # Returns the last +Error+ of the current executing +Thread+ or nil if none
35
57
  def self.last_error
36
- Thread.current[:__FIDDLE_LAST_ERROR__]
58
+ if RUBY_ENGINE == 'jruby'
59
+ errno = FFI.errno
60
+ errno == 0 ? nil : errno
61
+ else
62
+ Thread.current[:__FIDDLE_LAST_ERROR__]
63
+ end
37
64
  end
38
65
 
39
66
  # Sets the last +Error+ of the current executing +Thread+ to +error+
40
67
  def self.last_error= error
41
- Thread.current[:__DL2_LAST_ERROR__] = error
42
- Thread.current[:__FIDDLE_LAST_ERROR__] = error
68
+ if RUBY_ENGINE == 'jruby'
69
+ FFI.errno = error || 0
70
+ else
71
+ Thread.current[:__DL2_LAST_ERROR__] = error
72
+ Thread.current[:__FIDDLE_LAST_ERROR__] = error
73
+ end
43
74
  end
44
75
 
45
76
  # call-seq: dlopen(library) => Fiddle::Handle
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  - SHIBATA Hiroshi
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2023-11-08 00:00:00.000000000 Z
11
+ date: 2024-10-11 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A libffi wrapper for Ruby.
15
14
  email:
@@ -37,14 +36,11 @@ files:
37
36
  - ext/fiddle/memory_view.c
38
37
  - ext/fiddle/pinned.c
39
38
  - ext/fiddle/pointer.c
40
- - ext/fiddle/win32/fficonfig.h
41
- - ext/fiddle/win32/libffi-3.2.1-mswin.patch
42
- - ext/fiddle/win32/libffi-config.rb
43
- - ext/fiddle/win32/libffi.mk.tmpl
44
39
  - fiddle.gemspec
45
40
  - lib/fiddle.rb
46
41
  - lib/fiddle/closure.rb
47
42
  - lib/fiddle/cparser.rb
43
+ - lib/fiddle/ffi_backend.rb
48
44
  - lib/fiddle/function.rb
49
45
  - lib/fiddle/import.rb
50
46
  - lib/fiddle/pack.rb
@@ -58,7 +54,7 @@ licenses:
58
54
  - BSD-2-Clause
59
55
  metadata:
60
56
  msys2_mingw_dependencies: libffi
61
- post_install_message:
57
+ changelog_uri: https://github.com/ruby/fiddle/releases
62
58
  rdoc_options: []
63
59
  require_paths:
64
60
  - lib
@@ -73,8 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
69
  - !ruby/object:Gem::Version
74
70
  version: '0'
75
71
  requirements: []
76
- rubygems_version: 3.5.0.dev
77
- signing_key:
72
+ rubygems_version: 3.6.0.dev
78
73
  specification_version: 4
79
74
  summary: A libffi wrapper for Ruby.
80
75
  test_files: []
@@ -1,29 +0,0 @@
1
- #define HAVE_ALLOCA 1
2
- #define HAVE_MEMCPY 1
3
- #define HAVE_MEMORY_H 1
4
- #define HAVE_STDLIB_H 1
5
- #define HAVE_STRING_H 1
6
- #define HAVE_SYS_STAT_H 1
7
- #define HAVE_SYS_TYPES_H 1
8
- #if _MSC_VER >= 1600
9
- #define HAVE_INTTYPES_H 1
10
- #define HAVE_STDINT_H 1
11
- #endif
12
-
13
- #define SIZEOF_DOUBLE 8
14
- #if defined(X86_WIN64)
15
- #define SIZEOF_SIZE_T 8
16
- #else
17
- #define SIZEOF_SIZE_T 4
18
- #endif
19
-
20
- #define STACK_DIRECTION -1
21
-
22
- #define STDC_HEADERS 1
23
-
24
- #ifdef LIBFFI_ASM
25
- #define FFI_HIDDEN(name)
26
- #else
27
- #define FFI_HIDDEN
28
- #endif
29
-
@@ -1,191 +0,0 @@
1
- diff -ru libffi-3.2.1/src/x86/ffi.c libffi-3.2.1/src/x86/ffi.c
2
- --- libffi-3.2.1/src/x86/ffi.c 2014-11-08 21:47:24.000000000 +0900
3
- +++ libffi-3.2.1/src/x86/ffi.c 2014-12-25 18:46:14.806761900 +0900
4
- @@ -99,11 +99,13 @@
5
- i != 0;
6
- i--, p_arg += dir, p_argv += dir)
7
- {
8
- + size_t z;
9
- +
10
- /* Align if necessary */
11
- if ((sizeof(void*) - 1) & (size_t) argp)
12
- argp = (char *) ALIGN(argp, sizeof(void*));
13
-
14
- - size_t z = (*p_arg)->size;
15
- + z = (*p_arg)->size;
16
-
17
- #ifdef X86_WIN64
18
- if (z > FFI_SIZEOF_ARG
19
- @@ -202,6 +204,7 @@
20
- on top of stack, so that those can be moved to registers by call-handler. */
21
- if (stack_args_count > 0)
22
- {
23
- + int i;
24
- if (dir < 0 && stack_args_count > 1)
25
- {
26
- /* Reverse order if iterating arguments backwards */
27
- @@ -210,7 +213,6 @@
28
- *(ffi_arg*) p_stack_data[stack_args_count - 1] = tmp;
29
- }
30
-
31
- - int i;
32
- for (i = 0; i < stack_args_count; i++)
33
- {
34
- if (p_stack_data[i] != argp2)
35
- @@ -569,11 +571,12 @@
36
- i < cif->nargs && passed_regs < max_stack_count;
37
- i++, p_arg++)
38
- {
39
- + size_t sz;
40
- if ((*p_arg)->type == FFI_TYPE_FLOAT
41
- || (*p_arg)->type == FFI_TYPE_STRUCT)
42
- continue;
43
-
44
- - size_t sz = (*p_arg)->size;
45
- + sz = (*p_arg)->size;
46
- if(sz == 0 || sz > FFI_SIZEOF_ARG)
47
- continue;
48
-
49
- @@ -599,11 +602,13 @@
50
- i != 0;
51
- i--, p_arg += dir, p_argv += dir)
52
- {
53
- + size_t z;
54
- +
55
- /* Align if necessary */
56
- if ((sizeof(void*) - 1) & (size_t) argp)
57
- argp = (char *) ALIGN(argp, sizeof(void*));
58
-
59
- - size_t z = (*p_arg)->size;
60
- + z = (*p_arg)->size;
61
-
62
- #ifdef X86_WIN64
63
- if (z > FFI_SIZEOF_ARG
64
- @@ -642,7 +647,7 @@
65
- #endif
66
- }
67
-
68
- - return (size_t)argp - (size_t)stack;
69
- + return (int)((size_t)argp - (size_t)stack);
70
- }
71
-
72
- #define FFI_INIT_TRAMPOLINE_WIN64(TRAMP,FUN,CTX,MASK) \
73
- @@ -855,11 +860,12 @@
74
-
75
- for (i = 0; i < cif->nargs && passed_regs <= max_regs; i++)
76
- {
77
- + size_t sz;
78
- if (cif->arg_types[i]->type == FFI_TYPE_FLOAT
79
- || cif->arg_types[i]->type == FFI_TYPE_STRUCT)
80
- continue;
81
-
82
- - size_t sz = cif->arg_types[i]->size;
83
- + sz = cif->arg_types[i]->size;
84
- if (sz == 0 || sz > FFI_SIZEOF_ARG)
85
- continue;
86
-
87
- diff -ru libffi-3.2.1/src/x86/ffitarget.h libffi-3.2.1/src/x86/ffitarget.h
88
- --- libffi-3.2.1/src/x86/ffitarget.h 2014-11-08 21:47:24.000000000 +0900
89
- +++ libffi-3.2.1/src/x86/ffitarget.h 2014-12-22 15:45:54.000000000 +0900
90
- @@ -50,7 +50,9 @@
91
- #endif
92
-
93
- #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
94
- +#ifndef _MSC_VER
95
- #define FFI_TARGET_HAS_COMPLEX_TYPE
96
- +#endif
97
-
98
- /* ---- Generic type definitions ----------------------------------------- */
99
-
100
- diff -ru libffi-3.2.1/src/x86/win64.S libffi-3.2.1/src/x86/win64.S
101
- --- libffi-3.2.1/src/x86/win64.S 2014-11-08 21:47:24.000000000 +0900
102
- +++ libffi-3.2.1/src/x86/win64.S 2014-12-22 16:14:40.000000000 +0900
103
- @@ -127,7 +127,7 @@
104
-
105
- mov rcx, QWORD PTR RVALUE[rbp]
106
- mov DWORD PTR [rcx], eax
107
- - jmp ret_void$
108
- + jmp SHORT ret_void$
109
-
110
- ret_struct2b$:
111
- cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_SMALL_STRUCT_2B
112
- @@ -135,7 +135,7 @@
113
-
114
- mov rcx, QWORD PTR RVALUE[rbp]
115
- mov WORD PTR [rcx], ax
116
- - jmp ret_void$
117
- + jmp SHORT ret_void$
118
-
119
- ret_struct1b$:
120
- cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_SMALL_STRUCT_1B
121
- @@ -143,7 +143,7 @@
122
-
123
- mov rcx, QWORD PTR RVALUE[rbp]
124
- mov BYTE PTR [rcx], al
125
- - jmp ret_void$
126
- + jmp SHORT ret_void$
127
-
128
- ret_uint8$:
129
- cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_UINT8
130
- @@ -152,7 +152,7 @@
131
- mov rcx, QWORD PTR RVALUE[rbp]
132
- movzx rax, al
133
- mov QWORD PTR [rcx], rax
134
- - jmp ret_void$
135
- + jmp SHORT ret_void$
136
-
137
- ret_sint8$:
138
- cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_SINT8
139
- @@ -161,7 +161,7 @@
140
- mov rcx, QWORD PTR RVALUE[rbp]
141
- movsx rax, al
142
- mov QWORD PTR [rcx], rax
143
- - jmp ret_void$
144
- + jmp SHORT ret_void$
145
-
146
- ret_uint16$:
147
- cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_UINT16
148
- @@ -188,7 +188,13 @@
149
- mov rcx, QWORD PTR RVALUE[rbp]
150
- mov eax, eax
151
- mov QWORD PTR [rcx], rax
152
- - jmp SHORT ret_void$
153
- +
154
- +ret_void$:
155
- + xor rax, rax
156
- +
157
- + lea rsp, QWORD PTR [rbp+16]
158
- + pop rbp
159
- + ret 0
160
-
161
- ret_sint32$:
162
- cmp DWORD PTR CIF_FLAGS[rbp], FFI_TYPE_SINT32
163
- @@ -247,13 +253,6 @@
164
- cdqe
165
- mov QWORD PTR [rcx], rax
166
- jmp SHORT ret_void$
167
- -
168
- -ret_void$:
169
- - xor rax, rax
170
- -
171
- - lea rsp, QWORD PTR [rbp+16]
172
- - pop rbp
173
- - ret 0
174
- ffi_call_win64 ENDP
175
- _TEXT ENDS
176
- END
177
- diff -ru libffi-3.2.1/include/ffi.h.in libffi-3.2.1/include/ffi.h.in
178
- --- libffi-3.2.1/include/ffi.h.in 2014-11-08 21:47:24.000000000 +0900
179
- +++ libffi-3.2.1/include/ffi.h.in 2015-01-11 12:35:30.000000000 +0900
180
- @@ -103,6 +103,11 @@
181
- # undef FFI_64_BIT_MAX
182
- # define FFI_64_BIT_MAX 9223372036854775807LL
183
- # endif
184
- +# ifdef _MSC_VER
185
- +# define FFI_LONG_LONG_MAX _I64_MAX
186
- +# undef FFI_64_BIT_MAX
187
- +# define FFI_64_BIT_MAX 9223372036854775807I64
188
- +# endif
189
- # endif
190
- #endif
191
-
@@ -1,48 +0,0 @@
1
- #!/usr/bin/ruby
2
- # frozen_string_literal: true
3
- require 'fileutils'
4
-
5
- basedir = File.dirname(__FILE__)
6
- conf = {}
7
- enable = {}
8
- until ARGV.empty?
9
- arg = ARGV.shift
10
- case arg
11
- when '-C'
12
- # ignore
13
- when /\A--srcdir=(.*)/
14
- conf['SRCDIR'] = srcdir = $1
15
- when /\A(CC|CFLAGS|CXX|CXXFLAGS|LD|LDFLAGS)=(.*)/
16
- conf[$1] = $2
17
- when /\A--host=(.*)/
18
- host = $1
19
- when /\A--enable-([^=]+)(?:=(.*))?/
20
- enable[$1] = $2 || true
21
- when /\A--disable-([^=]+)/
22
- enable[$1] = false
23
- end
24
- end
25
-
26
- File.foreach("#{srcdir}/configure.ac") do |line|
27
- if /^AC_INIT\((.*)\)/ =~ line
28
- version = $1.split(/,\s*/)[1]
29
- version.gsub!(/\A\[|\]\z/, '')
30
- conf['VERSION'] = version
31
- break
32
- end
33
- end
34
-
35
- builddir = srcdir == "." ? (enable['builddir'] || ".") : "."
36
- conf['TARGET'] = /^x64/ =~ host ? "X86_WIN64" : "X86_WIN32"
37
-
38
- FileUtils.mkdir_p([builddir, "#{builddir}/include", "#{builddir}/src/x86"])
39
- FileUtils.cp("#{basedir}/fficonfig.h", ".", preserve: true)
40
-
41
- hdr = File.binread("#{srcdir}/include/ffi.h.in")
42
- hdr.gsub!(/@(\w+)@/) {conf[$1] || $&}
43
- hdr.gsub!(/^(#if\s+)@\w+@/, '\10')
44
- File.binwrite("#{builddir}/include/ffi.h", hdr)
45
-
46
- mk = File.binread("#{basedir}/libffi.mk.tmpl")
47
- mk.gsub!(/@(\w+)@/) {conf[$1] || $&}
48
- File.binwrite("Makefile", mk)
@@ -1,96 +0,0 @@
1
- # -*- makefile -*-
2
- # ====================================================================
3
- #
4
- # libffi Windows Makefile
5
- #
6
- #
7
- # ====================================================================
8
- #
9
- NAME = ffi
10
- TARGET = @TARGET@
11
- CC = cl
12
- !if "$(TARGET)" == "X86_WIN64"
13
- AS = ml64
14
- !else
15
- AS = ml
16
- !endif
17
- AR = link
18
- DLEXT = dll
19
- OBJEXT = obj
20
- LIBEXT = lib
21
- TOPDIR = @SRCDIR@
22
- CPP = $(CC) -EP
23
- CFLAGS = @CFLAGS@
24
- ARFLAGS = -lib
25
- ASFLAGS = -coff -W3 -Cx
26
- INCLUDES= -I. -I./include -I./src/x86 \
27
- -I$(TOPDIR)/include -I$(TOPDIR)/include/src/x86
28
-
29
- SRCDIR = $(TOPDIR)/src
30
- WORKDIR = ./.libs
31
- BUILDDIR= ./src
32
- LIBNAME = lib$(NAME)
33
- STATICLIB= $(WORKDIR)/$(LIBNAME)_convenience.$(LIBEXT)
34
-
35
- HEADERS = \
36
- ./fficonfig.h
37
- FFI_HEADERS = \
38
- ./include/ffi.h \
39
- ./include/ffitarget.h
40
-
41
- !if "$(TARGET)" == "X86_WIN32"
42
- OSSRC = win32
43
- !else if "$(TARGET)" == "X86_WIN64"
44
- OSSRC = win64
45
- !else
46
- ! error unknown target: $(TARGET)
47
- !endif
48
-
49
- OBJECTS = \
50
- $(BUILDDIR)/closures.$(OBJEXT) \
51
- $(BUILDDIR)/debug.$(OBJEXT) \
52
- $(BUILDDIR)/java_raw_api.$(OBJEXT) \
53
- $(BUILDDIR)/prep_cif.$(OBJEXT) \
54
- $(BUILDDIR)/raw_api.$(OBJEXT) \
55
- $(BUILDDIR)/types.$(OBJEXT) \
56
- $(BUILDDIR)/x86/ffi.$(OBJEXT) \
57
- $(BUILDDIR)/x86/$(OSSRC).$(OBJEXT)
58
- ASMSRCS = \
59
- $(BUILDDIR)/x86/$(OSSRC).asm
60
-
61
- .SUFFIXES : .S .asm
62
-
63
- all: $(WORKDIR) $(STATICLIB)
64
-
65
- {$(SRCDIR)}.c{$(BUILDDIR)}.$(OBJEXT):
66
- $(CC) -c $(CFLAGS) $(INCLUDES) -Fo$(@:\=/) -Fd$(WORKDIR)/$(NAME)-src $(<:\=/)
67
-
68
- {$(SRCDIR)/x86}.c{$(BUILDDIR)/x86}.$(OBJEXT):
69
- $(CC) -c $(CFLAGS) $(INCLUDES) -Fo$(@:\=/) -Fd$(WORKDIR)/$(NAME)-src $(<:\=/)
70
-
71
- {$(SRCDIR)/x86}.S{$(BUILDDIR)/x86}.asm:
72
- $(CPP) $(CFLAGS) $(INCLUDES) $(<:\=/) >$(@:\=/)
73
-
74
- {$(BUILDDIR)/x86}.asm{$(BUILDDIR)/x86}.$(OBJEXT):
75
- cd $(@D) && $(AS) -c $(ASFLAGS) -Fo $(@F) $(<F)
76
-
77
- $(BUILDDIR)/x86/$(OSSRC).asm: $(SRCDIR)/x86/$(OSSRC).S
78
-
79
- $(OBJECTS): $(FFI_HEADERS) $(HEADERS)
80
-
81
- $(WORKDIR):
82
- -@if not exist "$(WORKDIR:/=\)\$(NULL)" mkdir $(WORKDIR:/=\)
83
-
84
- $(STATICLIB): $(WORKDIR) $(OBJECTS)
85
- $(AR) $(ARFLAGS) -out:$(STATICLIB) @<<
86
- $(OBJECTS)
87
- <<
88
-
89
- clean:
90
- -@del /Q $(OBJECTS:/=\) 2>NUL
91
- -@del /Q $(ASMSRCS:/=\) 2>NUL
92
- -@del /Q /S $(WORKDIR:/=\) 2>NUL
93
-
94
- distclean: clean
95
- -@del /Q $(HEADERS:/=\) $(FFI_HEADERS:/=\) 2>NUL
96
- -@del /Q Makefile 2>NUL