8000 merge revision(s) d732bc51bdbfe7d66038731d42e01a511d13b5f8,633a1f15d8… · github/ruby@229c041 · GitHub
[go: up one dir, main page]

Skip to content

Commit 229c041

Browse files
committed
merge revision(s) d732bc5,633a1f15d8228236094ddee12e4e169d655ec49e,95f387f61a4a4ea92635da760b7de5b1e09bb84e,528a3a17977aa1843a26630c96635c3cb161e729,261569d4aac440f25de588cca365163ecf1124a2,e4a9e926f0fe0acf2fbe61da6e075a95d34be066,318be1cb2f9c6f04403c063a5618c6267012ee51,e1855100e46040e73630b378974c17764e0cccee,9cfa811b0f209d714f89fe0de6778c71f77556c7,b68dab866724aacc1cbc6b7d5e1f555dec092346: [Backport #17202]
Revert "Revert "Revert "[ruby/fiddle] Use ffi_closure_free by default. (#20)""" This reverts commit 87f6154. It turned out that the change fails to build on macOS https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1014/ruby-master/log/20200304T074503Z.fail.html.gz ``` + make 'TESTS=--hide-skip -v fiddle' RUBYOPT=-w test-all dyld: lazy symbol binding failed: Symbol not found: _ffi_closure_alloc Referenced from: /Users/hsbt/Documents/cb/tmp/build/20200304T074503Z/ruby/.ext/x86_64-darwin18/fiddle.bundle Expected in: flat namespace dyld: Symbol not found: _ffi_closure_alloc Referenced from: /Users/hsbt/Documents/cb/tmp/build/20200304T074503Z/ruby/.ext/x86_64-darwin18/fiddle.bundle Expected in: flat namespace make: *** [yes-test-all] Abort trap: 6 ``` [ruby/fiddle] Use ffi_closure_free if available [ruby/fiddle] ffi_closure_free is available in the bundled libffi [ruby/fiddle] use ffi_closure_alloc only with 3.2 or later [ruby/fiddle] always use ffi_closure_alloc on Windows Fixed a typo Show libffi version only if set ext/fiddle/extconf.rb: check if ffi_closure_alloc is available to define HAVE_FFI_CLOSURE_ALLOC. The macro is used in closure.c, so have_func check is needed. If pkg-config is not installed, extconf.rb fails to detect the version of libffi, and does not add "-DUSE_FFI_CLOSURE_ALLOC=1" even when system libffi version is >= 3.2. If USE_FFI_CLOSURE_ALLOC is not defined, closure.c attempts to check if HAVE_FFI_CLOSURE_ALLOC is defined or not, but have_func was removed with 528a3a1, so the macro is always not defined. This resulted in this deprecation warning: https://rubyci.org/logs/rubyci.s3.amazonaws.com/ubuntu2004/ruby-master/log/20200512T123003Z.log.html.gz ``` compiling closure.c closure.c: In function 'initialize': closure.c:265:5: warning: 'ffi_prep_closure' is deprecated: use ffi_prep_closure_loc instead [-Wdeprecated-declarations] 265 | result = ffi_prep_closure(pcl, cif, callback, (void *)self); | ^~~~~~ In file included from ./fiddle.h:42, from closure.c:1: /usr/include/x86_64-linux-gnu/ffi.h:334:1: note: declared here 334 | ffi_prep_closure (ffi_closure*, | ^~~~~~~~~~~~~~~~ ``` Do not try ffi_closure_alloc if libffi is <= 3.1 Maybe due to e185510, CentOS, RHEL, and Fedora CIs have started failing with SEGV. Try to avoid ffi_closure_alloc on those environments. https://rubyci.org/logs/rubyci.s3.amazonaws.com/centos8/ruby-master/log/20200512T183004Z.fail.html.gz https://rubyci.org/logs/rubyci.s3.amazonaws.com/fedora32/ruby-master/log/20200512T183004Z.fail.html.gz https://rubyci.org/logs/rubyci.s3.amazonaws.com/rhel8/ruby-master/log/20200512T183003Z.fail.html.gz ext/fiddle/extconf.rb: Fix the condition of libffi <= 3.1 ver is [3, 1, 0] which is not less then or equal to [3, 1]
1 parent f469298 commit 229c041

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

ext/fiddle/closure.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@ typedef struct {
1313
ffi_type **argv;
1414
} fiddle_closure;
1515

16+
#if defined(USE_FFI_CLOSURE_ALLOC)
17+
#elif !defined(HAVE_FFI_CLOSURE_ALLOC)
18+
# define USE_FFI_CLOSURE_ALLOC 0
19+
#else
20+
# define USE_FFI_CLOSURE_ALLOC 1
21+
#endif
22+
1623
static void
1724
dealloc(void * ptr)
1825
{
1926
fiddle_closure * cls = (fiddle_closure *)ptr;
27+
#if USE_FFI_CLOSURE_ALLOC
2028
ffi_closure_free(cls->pcl);
29+
#else
30+
munmap(cls->pcl, sizeof(*cls->pcl));
31+
#endif
2132
if (cls->argv) xfree(cls->argv);
2233
xfree(cls);
2334
}
@@ -191,7 +202,12 @@ allocate(VALUE klass)
191202
VALUE i = TypedData_Make_Struct(klass, fiddle_closure,
192203
&closure_data_type, closure);
193204

205+
#if USE_FFI_CLOSURE_ALLOC
194206
closure->pcl = ffi_closure_alloc(sizeof(ffi_closure), &closure->code);
207+
#else
208+
closure->pcl = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
209+
MAP_ANON | MAP_PRIVATE, -1, 0);
210+
#endif
195211

196212
return i;
197213
}
@@ -238,8 +254,17 @@ initialize(int rbargc, VALUE argv[], VALUE self)
238254
if (FFI_OK != result)
239255
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
240256

257+
#if USE_FFI_CLOSURE_ALLOC
241258
result = ffi_prep_closure_loc(pcl, cif, callback,
242259
(void *)self, cl->code);
260+
#else
261+
result = ffi_prep_closure(pcl, cif, callback, (void *)self);
262+
cl->code = (void *)pcl;
263+
i = mprotect(pcl, sizeof(*pcl), PROT_READ | PROT_EXEC);
264+
if (i) {
265+
rb_sys_fail("mprotect");
266+
}
267+
#endif
243268

244269
if (FFI_OK != result)
245270
rb_raise(rb_eRuntimeError, "error prepping closure %d", result);

ext/fiddle/extconf.rb

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
if ! bundle
88
dir_config 'libffi'
99

10-
pkg_config("libffi")
10+
pkg_config("libffi") and
11+
ver = pkg_config("libffi", "modversion")
1112

1213
if have_header(ffi_header = 'ffi.h')
1314
true
1415
elsif have_header(ffi_header = 'ffi/ffi.h')
15-
$defs.push(format('-DUSE_HEADER_HACKS'))
16+
$defs.push('-DUSE_HEADER_HACKS')
1617
true
1718
end and (have_library('ffi') || have_library('libffi'))
1819
end or
@@ -27,20 +28,20 @@
2728
Dir.glob("#{$srcdir}/libffi-*/").each{|dir| FileUtils.rm_rf(dir)}
2829
extlibs.run(["--cache=#{cache_dir}", ext_dir])
2930
end
30-
libffi_dir = bundle != false &&
31+
ver = bundle != false &&
3132
Dir.glob("#{$srcdir}/libffi-*/")
3233
.map {|n| File.basename(n)}
3334
.max_by {|n| n.scan(/\d+/).map(&:to_i)}
34-
unless libffi_dir
35+
unless ver
3536
raise "missing libffi. Please install libffi."
3637
end
3738

38-
srcdir = "#{$srcdir}/#{libffi_dir}"
39+
srcdir = "#{$srcdir}/#{ver}"
3940
ffi_header = 'ffi.h'
4041
libffi = Struct.new(*%I[dir srcdir builddir include lib a cflags ldflags opt arch]).new
41-
libffi.dir = libffi_dir
42+
libffi.dir = ver
4243
if $srcdir == "."
43-
libffi.builddir = "#{libffi_dir}/#{RUBY_PLATFORM}"
44+
libffi.builddir = "#{ver}/#{RUBY_PLATFORM}"
4445
libffi.srcdir = "."
4546
else
4647
libffi.builddir = libffi.dir
@@ -51,6 +52,7 @@
5152
libffi.a = "#{libffi.lib}/libffi_convenience.#{$LIBEXT}"
5253
nowarn = CONFIG.merge("warnflags"=>"")
5354
libffi.cflags = RbConfig.expand("$(CFLAGS)".dup, nowarn)
55+
ver = ver[/libffi-(.*)/, 1]
5456

5557
FileUtils.mkdir_p(libffi.dir)
5658
libffi.opt = CONFIG['configure_args'][/'(-C)'/, 1]
@@ -110,6 +112,21 @@
110112
$INCFLAGS << " -I" << libffi.include
111113
end
112114

115+
if ver
116+
ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just ignored.
117+
ver = (ver.split('.').map(&:to_i) + [0,0])[0,3]
118+
$defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver }})
119+
warn "libffi_version: #{ver.join('.')}"
120+
end
121+
122+
case
123+
when $mswin, $mingw, (ver && (ver <=> [3, 2]) >= 0)
124+
$defs << "-DUSE_FFI_CLOSURE_ALLOC=1"
125+
when (ver && (ver <=> [3, 2]) < 0)
126+
else
127+
have_func('ffi_closure_alloc', ffi_header)
128+
end
129+
113130
have_header 'sys/mman.h'
114131

115132
if have_header "dlfcn.h"
@@ -134,7 +151,7 @@
134151
if /^\#define\s+SIZEOF_#{type}\s+(SIZEOF_(.+)|\d+)/ =~ config
135152
if size = $2 and size != 'VOIDP'
136153
size = types.fetch(size) {size}
137-
$defs << format("-DTYPE_%s=TYPE_%s", signed||type, size)
154+
$defs << "-DTYPE_#{signed||type}=TYPE_#{size}"
138155
end
139156
if signed
140157
check_signedness(type.downcase, "stddef.h")

version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
33
#define RUBY_VERSION_TEENY 1
44
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
5-
#define RUBY_PATCHLEVEL 133
5+
#define RUBY_PATCHLEVEL 134
66

77
#define RUBY_RELEASE_YEAR 2020
8-
#define RUBY_RELEASE_MONTH 9
9-
#define RUBY_RELEASE_DAY 30
8+
#define RUBY_RELEASE_MONTH 10
9+
#define RUBY_RELEASE_DAY 1
1010

1111
#include "ruby/version.h"
1212

0 commit comments

Comments
 (0)
0