This commit adds constants for unsigned values. Currently we can use `-`
to mean "unsigned", but I think having a specific name makes Fiddle more
user friendly. This commit continues to support `-`, but introduces
negative constants with "unsigned" names
I think this will help to eliminate [this
code](3a56bf0bcc/lib/mjit/c_type.rb (L31-L38))
https://github.com/ruby/fiddle/commit/2bef0f1082
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
rb_ary_tmp_new suggests that the array is temporary in some way, but
that's not true, it just creates an array that's hidden and not on the
transient heap. This commit renames it to rb_ary_hidden_new.
On OpenBSD, USE_FFI_CLOSURE_ALLOC was always set to 0 previously. In
633a1f15d8, the code was modified in a
way that it ended up being set to 1 on OpenBSD. However, that results
in SIGABRT when running make test-all, inside ffi_closure_free.
Setting USE_FFI_CLOSURE_ALLOC back to 0 fixes the issue.
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
```
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.
* 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
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
* ext/bigdecimal/bigdecimal.c: use RARRAY_CONST_PTR just fore
reference instead of RARRAY_PTR, to keep the array WB-protected.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The `callback' function is not used outside of closure.c and
should not be able to cause namespace conflicts in compilers
without visibility pragmas.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RUBY_LIBFFI_MODVERSION is not defined (usually on Windows).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/fiddle: Complete documentation of Fiddle. Patch by Vincent
Batts. [#5192]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
should be used to handle shorter return value. fix [Bug #3861]
[ruby-core:32504]
* ext/fiddle/closure.c (callback): ditto
* ext/fiddle/conversions.h (fiddle_generic): ditto
* ext/fiddle/conversions.c (value_to_generic): char, short and int
are strictly distinguished on big-endian CPU, e.g. sparc64.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
xmalloc() to allocate an array for arguments of callback procedure,
to prevent arguments from being swept by GC. [ruby-core:38546]
[Bug #4929]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
so that the content surely get initialized. [ruby-dev:42480]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
don't use ffi_closure_alloc, ffi_prep_closure_loc and
ffi_closure_free on MACOSX and __linux__.
[ruby-dev:41483] [ruby-dev:41214]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28315 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/fiddle/*: testing fiddle extension
* ext/dl/lib/dl.rb: Requiring fiddle if it is available
* ext/dl/lib/dl/callback.rb: using Fiddle if it is available
* ext/dl/lib/dl/func.rb: ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e