Граф коммитов

75 Коммитов

Автор SHA1 Сообщение Дата
Sutou Kouhei 2ec2051f1f [ruby/fiddle] Don't use mkmf to generate dummy Makefile
(https://github.com/ruby/fiddle/pull/155)

GitHub: fix https://github.com/ruby/fiddle/pull/153

mkmf requires fileutils. JRuby doesn't like it.

https://github.com/ruby/fiddle/commit/df4bd21fc3
2024-10-26 18:44:15 +09:00
Nobuyoshi Nakada a51007fc35 [ruby/fiddle] Suppress -Wundef warnings
(https://github.com/ruby/fiddle/pull/157)

The GCC warning puts undefined macro names in double quotes while clang
puts them in single quotes.

https://github.com/ruby/fiddle/commit/7dcb40bccb
2024-10-26 18:44:15 +09:00
Sutou Kouhei 8d127c9b59
Use JRuby implementation for TruffleRuby (#149)
Fix GH-145

Rename `lib/fiddle/jruby.rb` to `lib/fiddle/ffi_backend.rb` as a generic
ffi gem API based implementation.
JRuby and TruffleRuby use `lib/fiddle/ffi_backend.rb`.

---------

Co-authored-by: Benoit Daloze <eregontp@gmail.com>
2024-10-16 11:24:25 +09:00
Nobuyoshi Nakada bbd5b8ddae
[ruby/fiddle] Ractor support
(https://github.com/ruby/fiddle/pull/139)

https://github.com/ruby/fiddle/commit/91d0ea9849

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2024-10-16 11:24:25 +09:00
Sutou Kouhei a47f153d9d
Import JRuby implementation (#147)
Fix GH-104

lib/fiddle/jruby.rb is based on

https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/fiddle/jruby.rb
.

Here are changes for it:

* Move `Fiddle::TYPE_*` to `Fiddle::Types::*`
* Add `Fiddle::Types::VARIADIC`
* Add `Fiddle::Types::CONST_STRING`
* Add `Fiddle::Types::BOOL`
* Add `Fiddle::Types::INT8_T`
* Add `Fiddle::Types::UINT8_T`
* Add `Fiddle::Types::INT16_T`
* Add `Fiddle::Types::UINT16_T`
* Add `Fiddle::Types::INT32_T`
* Add `Fiddle::Types::UINT32_T`
* Add `Fiddle::Types::INT64_T`
* Add `Fiddle::Types::UINT64_T`
* Add more `Fiddle::ALIGN_*` for the above new `Fiddle::Types::*`
* Add more `Fiddle::SIZEOF_*` for the above new `Fiddle::Types::*`
* Add support for specifying type as not only `Fiddle::Types::*` but
also `Symbol` like `:int`
* Add support for variable size arguments in `Fiddle::Function`
* Add `Fiddle::Closure#free`
* Add `Fiddle::Closure#freed?`
* Add `Fiddle::Error` as base the error class
* Add `Fiddle::Pointer#call_free` and stop using `FFI::AutoPointer` in
`Fiddle::Pointer`
* Add support for `Fiddle::Pointer.malloc {}` `Fiddle::Pointer`
* Add support for `Fiddle::Pointer#free=`
* Add `Fiddle::Pointer#freed?`
* Use binary string not C string for `Fiddle::Pointer#[]`
* Add `Fiddle::Handle.sym_defined?`
* Add `Fiddle::Handle#sym_defined?`
* Add `Fiddle::Handle::DEFAULT`
* Add `Fiddle::ClearedReferenceError`
* Add no-op `Fiddle::Pinned`

Some features are still "not implemented". So there are some "omit"s for
JRuby in tests.
2024-10-10 10:05:52 +09:00
Nobuyoshi Nakada 5c94f3fe9d [ruby/fiddle] Suppress -Wundef warnings on arm64 macOS and Windows
(https://github.com/ruby/fiddle/pull/134)

```
In file included from ../../../../ext/fiddle/fiddle.h:46:
/opt/local/include/ffi.h:477:5: warning: 'FFI_GO_CLOSURES' is not defined, evaluates to 0 [-Wundef]
    ^
```

c.f. https://github.com/libffi/libffi/pull/796

https://github.com/ruby/fiddle/commit/d4feb57098
2023-09-17 22:42:50 +09:00
Hiroshi SHIBATA 286812bcf3 Merge fiddle-1.1.1 2022-12-09 16:36:22 +09:00
Hiroshi SHIBATA 4f78560cf1
Add --with-libffi-source-dir feature and removed --enable-bundled-libffi option. (#113)
https://bugs.ruby-lang.org/issues/18571

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2022-10-07 15:20:11 +09:00
Koichi Sasada cc8064ba2e Do not need to print to stderr 2022-01-26 10:05:10 +09:00
Kenta Murata 67897762cf
[ruby/fiddle] Add Fiddle::Handle#file_name (https://github.com/ruby/fiddle/pull/88)
https://github.com/ruby/fiddle/commit/4ee1c6fc4b
2021-07-14 18:56:00 +09:00
Sutou Kouhei bb868f4814
[ruby/fiddle] Use have_header and have_type to detect memory view availability
Fix https://github.com/ruby/fiddle/pull/84

It may detect ruby/memory_view.h for system Ruby that is installed in
/usr.

We can use RUBY_API_VERSION_MAJOR to detect memory view availability
because memory view is available since Ruby 3.0.

Reported by Jun Aruga. Thanks!!!

https://github.com/ruby/fiddle/commit/3292929830
2021-07-13 19:37:46 +09:00
Sutou Kouhei 79717f81f8 [ruby/fiddle] windows: link to ws2_32 for WSAGetLastError()
https://github.com/ruby/fiddle/commit/e9955d74ae
2021-05-18 12:48:40 +09:00
Sutou Kouhei 4d1bb460f6 [ruby/fiddle] Add --enable-debug-build option to extconf.rb
https://github.com/ruby/fiddle/commit/e0498e60ea
2021-05-18 12:48:40 +09:00
Sutou Kouhei 32849dc1bb fiddle: Update to 1.0.5 2020-12-23 05:49:52 +09:00
Kenta Murata 9b0c36b390
Import fiddle-1.0.4 (#3860)
I don't use tool/sync_default_gem.rb because the last sync was incomplete.

Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: sinisterchipmunk <sinisterchipmunk@gmail.com>
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2020-12-11 09:41:12 +09:00
Nobuyoshi Nakada c405a8d37a
[ruby/fiddle] try bundled libffi by default
If no installed libffi found, use bundled libffi unless explicitly
`--disable-bundled-libffi` option is given.
2020-06-28 01:03:21 +09:00
Sutou Kouhei f2bcdc7283
[ruby/fiddle] Support MSWIN (#43)
https://github.com/ruby/fiddle/commit/f16e7ff6e0
2020-06-27 23:54:09 +09:00
Sutou Kouhei ae18220f99
[ruby/fiddle] Add support for variadic arguments
GitHub: fix GH-39

Reported by kojix2. Thanks!!!

https://github.com/ruby/fiddle/commit/6c4cb904dc
2020-06-27 23:54:08 +09:00
Yusuke Endoh b68dab8667 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]
2020-05-13 10:57:14 +09:00
Yusuke Endoh 9cfa811b0f Do not try ffi_closure_alloc if libffi is <= 3.1
Maybe due to e1855100e4, 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
2020-05-13 08:42:48 +09:00
Yusuke Endoh e1855100e4 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
528a3a1797, 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*,
      | ^~~~~~~~~~~~~~~~
```
2020-05-13 01:17:30 +09:00
Nobuyoshi Nakada 318be1cb2f
Show libffi version only if set 2020-03-21 16:38:29 +09:00
Nobuyoshi Nakada e4a9e926f0
Fixed a typo 2020-03-05 13:31:25 +09:00
Nobuyoshi Nakada 261569d4aa
[ruby/fiddle] always use ffi_closure_alloc on Windows 2020-03-05 11:31:08 +09:00
Nobuyoshi Nakada 528a3a1797
[ruby/fiddle] use ffi_closure_alloc only with 3.2 or later 2020-03-04 23:19:35 +09:00
Nobuyoshi Nakada 95f387f61a
[ruby/fiddle] ffi_closure_free is available in the bundled libffi 2020-03-04 18:41:47 +09:00
Nobuyoshi Nakada 633a1f15d8
[ruby/fiddle] Use ffi_closure_free if available 2020-03-04 18:14:18 +09:00
Yusuke Endoh d732bc51bd Revert "Revert "Revert "[ruby/fiddle] Use ffi_closure_free by default. (#20)"""
This reverts commit 87f6154bb4.

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
```
2020-03-04 17:28:21 +09:00
Yusuke Endoh 87f6154bb4 Revert "Revert "[ruby/fiddle] Use ffi_closure_free by default. (#20)""
This reverts commit efd641ffab.

This changeset seems to be needed to suppress a warning on Ubuntu 20.04
https://rubyci.org/logs/rubyci.s3.amazonaws.com/ubuntu/ruby-master/log/20200304T033004Z.log.html.gz
```
closure.c:264:5: warning: 'ffi_prep_closure' is deprecated: use ffi_prep_closure_loc instead [-Wdeprecated-declarations]
  264 |     result = ffi_prep_closure(pcl, cif, callback, (void *)self);
      |     ^~~~~~
```

I guess there was a reason why the commit was reverted (maybe some CIs
failed?), so try it again.
2020-03-04 15:46:26 +09:00
Hiroshi SHIBATA efd641ffab Revert "[ruby/fiddle] Use ffi_closure_free by default. (#20)"
This reverts commit ce6caade7c.
2019-10-24 20:58:32 +09:00
Vít Ondruch ce6caade7c [ruby/fiddle] Use ffi_closure_free by default. (#20)
* Use ffi_closure_free unconditionally.

The current conditionals reflect historic heritage of FFI. Usage of
ffi_closure_free should be better default nowadays, because libffi 3.0.5
fixing issues of ffi_closure_free should be widely available.

* RUBY_LIBFFI_MODVERSION is not used anymore.

Because `ffi_closure_free()` is not used unconditionally, there is no
other use for RUBY_LIBFFI_MODVERSION define, so drop its usage.

* Use more meaningful variable name.

`ver` variable used to be used to pupulate RUBY_LIBFFI_MODVERSION
define. Since the define was removed, the `libffi_dir` variable name
should better describe the remaining usage of the variable.

https://github.com/ruby/fiddle/commit/c49cc79eb8
2019-10-24 19:34:43 +09:00
tadd b640b21d9c fix typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 07:40:45 +00:00
hsbt d303a2c45a Merge fiddle from github repository.
* ext/fiddle/extconf.rb: It supports to build libffi with standalone gem.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 07:27:18 +00:00
hsbt 7f24b0aabd Merge fiddle-1.0.0.beta2 from upstream.
* ext/fiddle/closure.c: use directly declaration for standalone gem
    without internal.h.
  * Specify frozen string literal is true.
  * Update gemspec configuration for release version.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-12 11:52:23 +00:00
nobu 35533d0346 fiddle: fix $(SUBMAKE_PRE)
* ext/fiddle/extconf.rb: fix $(SUBMAKE_PRE) to chdir to
  $(LIBFFI_DIR) instead of $(@D), since $(LIBFFI_A) is not
  underneath libffi but under .libs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-10 04:24:08 +00:00
nobu 3c06d3a6bd fiddle: jobserver for libffi
* ext/fiddle/depend (libffi): use $(MAKE) explicitly for recursive
  make, so that jobserver works.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-09 12:08:56 +00:00
naruse c4fdfabcc8 handle ext/ as r53141
g -L frozen_string_literal ext/**/*.rb|xargs ruby -Ka -e'ARGV.each{|fn|puts
fn;open(fn,"r+"){|f|s=f.read.sub(/\A(#!.*\n)?(#.*coding.*\n)?/,"\\&#
frozen_string_literal: false\n");f.rewind;f.write s}}'

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:31:54 +00:00
normal 15476c695d fiddle: release GVL for ffi_call
Some external functions I wish to call may take a long time
and unnecessarily block other threads.  This may lead to performance
regressions for fast functions as releasing/acquiring the GVL is not
cheap, but can improve performance for long-running functions
in multi-threaded applications.

This also means we must reacquire the GVL when calling Ruby-defined
callbacks for Fiddle::Closure, meaning we must detect whether the
current thread has the GVL by exporting ruby_thread_has_gvl_p
in internal.h

* ext/fiddle/function.c (struct nogvl_ffi_call_args):
  new struct for GVL release
  (nogvl_ffi_call): new function
  (function_call): adjust for GVL release
  [ruby-core:71642] [Feature #11607]
* ext/fiddle/closure.c (struct callback_args):
  new struct for GVL acquire
  (with_gvl_callback): adjusted original callback function
  (callback): wrapper for conditional GVL acquire
* ext/fiddle/depend: add dependencies
* ext/fiddle/extconf.rb: include top_srcdir for internal.h
* internal.h (ruby_thread_has_gvl_p): expose for fiddle
* vm_core.h (ruby_thread_has_gvl_p): moved to internal.h
* test/fiddle/test_function.rb (test_nogvl_poll): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-23 21:20:56 +00:00
nobu 07900180ec fiddle: $LOCAL_LIBS needs to be expanded
* ext/fiddle/extconf.rb: revert part of r51401 and expand
  $LOCAL_LIBS as it will be extracted and copied to exts.mk.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-29 07:53:12 +00:00
nobu 50a585ed25 fiddle: unexpand LIBFFI_DIR
* ext/fiddle/extconf.rb: use LIBFFI_DIR instead of expanding it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-27 03:45:11 +00:00
nobu dc8d595461 libff: fix enable-shared condition
* ext/fiddle/extconf.rb: needs --enable-shared when linked to
  libruby or fiddle.so.  since --with-static-linked-ext does no
  longer link extensions to ruby program with --enable-shared, the
  only combination needs --enable-static is --disable-shared and
  --with-static-linked-ext.  [ruby-dev:48901] [Bug #10960]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-13 02:37:49 +00:00
nobu 8cfce15387 fiddle: --disable-bundled-libffi
* ext/fiddle/extconf.rb: disable bundled libffi if explicitly
  disabled by --disable-bundled-libffi.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-17 10:52:17 +00:00
nobu 24b6863f79 fiddle: check assembler
* ext/fiddle/extconf.rb: requires assembler for src/win{32,64}.S.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-11 03:54:45 +00:00
nobu 5cc1e95be3 fiddle: append libffi config.log
* ext/fiddle/extconf.rb: copy config.log of libffi when failed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49070 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-30 06:13:33 +00:00
nobu a9f70432d4 extconf.rb: libffi PIC objects
* ext/fiddle/extconf.rb: make PIC objects if it will be linked as
  a shared object eventually.  [ruby-core:67128]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-25 12:58:18 +00:00
nobu 0cd829c339 fiddle: win32/libffi-config.rb
* ext/fiddle/win32/libffi-config.rb: generate necessary files to
  build on mswin.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-24 02:29:56 +00:00
usa a54aae45a6 * ext/fiddle/extconf.rb: remove ffitarget.h generated by configure on
mswin, because it's not normal file (cygwin's symlink) and have
  system attribute.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-24 00:36:42 +00:00
nobu 132415bf9e extconf.rb: no empty CPP
* ext/fiddle/extconf.rb: pass CPP only if necessary, should not
  make it empty.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-23 13:07:39 +00:00
nobu 5b6fc3f006 extmk.rb: replace current directory name
* ext/extmk.rb (extmake): replace "./" at beginning in LOCAL_LIBS
  with the current directory name for values cached in previous
  Makefile.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-23 13:05:47 +00:00
nobu 276065f870 fiddle: clean-libffi
* ext/fiddle/depend (clean-libffi): clean libffi directory.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-23 11:33:54 +00:00