summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/fiddle/closure.c25
-rw-r--r--ext/fiddle/extconf.rb33
-rw-r--r--version.h6
3 files changed, 53 insertions, 11 deletions
diff --git a/ext/fiddle/closure.c b/ext/fiddle/closure.c
index b997e23f45d..2044c836ea0 100644
--- a/ext/fiddle/closure.c
+++ b/ext/fiddle/closure.c
@@ -13,11 +13,22 @@ typedef struct {
ffi_type **argv;
} fiddle_closure;
+#if defined(USE_FFI_CLOSURE_ALLOC)
+#elif !defined(HAVE_FFI_CLOSURE_ALLOC)
+# define USE_FFI_CLOSURE_ALLOC 0
+#else
+# define USE_FFI_CLOSURE_ALLOC 1
+#endif
+
static void
dealloc(void * ptr)
{
fiddle_closure * cls = (fiddle_closure *)ptr;
+#if USE_FFI_CLOSURE_ALLOC
ffi_closure_free(cls->pcl);
+#else
+ munmap(cls->pcl, sizeof(*cls->pcl));
+#endif
if (cls->argv) xfree(cls->argv);
xfree(cls);
}
@@ -191,7 +202,12 @@ allocate(VALUE klass)
VALUE i = TypedData_Make_Struct(klass, fiddle_closure,
&closure_data_type, closure);
+#if USE_FFI_CLOSURE_ALLOC
closure->pcl = ffi_closure_alloc(sizeof(ffi_closure), &closure->code);
+#else
+ closure->pcl = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+#endif
return i;
}
@@ -238,8 +254,17 @@ initialize(int rbargc, VALUE argv[], VALUE self)
if (FFI_OK != result)
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
+#if USE_FFI_CLOSURE_ALLOC
result = ffi_prep_closure_loc(pcl, cif, callback,
(void *)self, cl->code);
+#else
+ result = ffi_prep_closure(pcl, cif, callback, (void *)self);
+ cl->code = (void *)pcl;
+ i = mprotect(pcl, sizeof(*pcl), PROT_READ | PROT_EXEC);
+ if (i) {
+ rb_sys_fail("mprotect");
+ }
+#endif
if (FFI_OK != result)
rb_raise(rb_eRuntimeError, "error prepping closure %d", result);
diff --git a/ext/fiddle/extconf.rb b/ext/fiddle/extconf.rb
index 5525b2c8084..f8a94d41e7a 100644
--- a/ext/fiddle/extconf.rb
+++ b/ext/fiddle/extconf.rb
@@ -7,12 +7,13 @@ bundle = enable_config('bundled-libffi')
if ! bundle
dir_config 'libffi'
- pkg_config("libffi")
+ pkg_config("libffi") and
+ ver = pkg_config("libffi", "modversion")
if have_header(ffi_header = 'ffi.h')
true
elsif have_header(ffi_header = 'ffi/ffi.h')
- $defs.push(format('-DUSE_HEADER_HACKS'))
+ $defs.push('-DUSE_HEADER_HACKS')
true
end and (have_library('ffi') || have_library('libffi'))
end or
@@ -27,20 +28,20 @@ begin
Dir.glob("#{$srcdir}/libffi-*/").each{|dir| FileUtils.rm_rf(dir)}
extlibs.run(["--cache=#{cache_dir}", ext_dir])
end
- libffi_dir = bundle != false &&
+ ver = bundle != false &&
Dir.glob("#{$srcdir}/libffi-*/")
.map {|n| File.basename(n)}
.max_by {|n| n.scan(/\d+/).map(&:to_i)}
- unless libffi_dir
+ unless ver
raise "missing libffi. Please install libffi."
end
- srcdir = "#{$srcdir}/#{libffi_dir}"
+ srcdir = "#{$srcdir}/#{ver}"
ffi_header = 'ffi.h'
libffi = Struct.new(*%I[dir srcdir builddir include lib a cflags ldflags opt arch]).new
- libffi.dir = libffi_dir
+ libffi.dir = ver
if $srcdir == "."
- libffi.builddir = "#{libffi_dir}/#{RUBY_PLATFORM}"
+ libffi.builddir = "#{ver}/#{RUBY_PLATFORM}"
libffi.srcdir = "."
else
libffi.builddir = libffi.dir
@@ -51,6 +52,7 @@ begin
libffi.a = "#{libffi.lib}/libffi_convenience.#{$LIBEXT}"
nowarn = CONFIG.merge("warnflags"=>"")
libffi.cflags = RbConfig.expand("$(CFLAGS)".dup, nowarn)
+ ver = ver[/libffi-(.*)/, 1]
FileUtils.mkdir_p(libffi.dir)
libffi.opt = CONFIG['configure_args'][/'(-C)'/, 1]
@@ -110,6 +112,21 @@ begin
$INCFLAGS << " -I" << libffi.include
end
+if ver
+ ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just ignored.
+ ver = (ver.split('.').map(&:to_i) + [0,0])[0,3]
+ $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver }})
+ warn "libffi_version: #{ver.join('.')}"
+end
+
+case
+when $mswin, $mingw, (ver && (ver <=> [3, 2]) >= 0)
+ $defs << "-DUSE_FFI_CLOSURE_ALLOC=1"
+when (ver && (ver <=> [3, 2]) < 0)
+else
+ have_func('ffi_closure_alloc', ffi_header)
+end
+
have_header 'sys/mman.h'
if have_header "dlfcn.h"
@@ -134,7 +151,7 @@ types.each do |type, signed|
if /^\#define\s+SIZEOF_#{type}\s+(SIZEOF_(.+)|\d+)/ =~ config
if size = $2 and size != 'VOIDP'
size = types.fetch(size) {size}
- $defs << format("-DTYPE_%s=TYPE_%s", signed||type, size)
+ $defs << "-DTYPE_#{signed||type}=TYPE_#{size}"
end
if signed
check_signedness(type.downcase, "stddef.h")
diff --git a/version.h b/version.h
index d1e50ce8379..0f7d49e797c 100644
--- a/version.h
+++ b/version.h
@@ -2,11 +2,11 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 1
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 133
+#define RUBY_PATCHLEVEL 134
#define RUBY_RELEASE_YEAR 2020
-#define RUBY_RELEASE_MONTH 9
-#define RUBY_RELEASE_DAY 30
+#define RUBY_RELEASE_MONTH 10
+#define RUBY_RELEASE_DAY 1
#include "ruby/version.h"