summaryrefslogtreecommitdiff
path: root/ext/ffi_c/Function.c
Commit message (Collapse)AuthorAgeFilesLines
* Make FFI classes GC.compact friendlyLars Kanis2023-04-141-3/+14
| | | | | | This allows to relocate all FFI objects. Also remove marking of StructLayout->cache_row in favour of clearing it at GC.compact only.
* Implement Write Barrier and dsize for FFI::FunctionJean Boussier2023-03-061-8/+25
| | | | | | | | | | | | | | Ref: https://github.com/ffi/ffi/pull/991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. It's not counting everything because some types are opaque right now, so a larger refactoring would be needed.
* Merge branch 'typed-data-struct' of https://github.com/casperisfine/ffi into ↵Lars Kanis2023-03-031-1/+3
|\ | | | | | | casperisfine-typed-data-struct
| * Convert FFI::Struct to TypedDataJean Boussier2023-03-021-1/+3
| | | | | | | | | | | | | | Ref: https://github.com/ffi/ffi/pull/991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
* | Merge branch 'casperisfine-typed-data-abstract-memory'Lars Kanis2023-03-031-16/+36
|\ \
| * | Convert FFI::AbstractMemory and descendants to TypedDataJean Boussier2023-03-021-16/+36
| |/ | | | | | | | | | | | | Ref: https://github.com/ffi/ffi/pull/991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
* | Convert FFI::Type and descendants to TypedDataJean Boussier2023-03-021-1/+1
|/ | | | | | | Ref: https://github.com/ffi/ffi/pull/991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
* Fix async callbacks in conjunction with fork()Lars Kanis2021-03-051-0/+18
| | | | | | After fork() the dispatcher thread is no longer running, so it needs to be restarted in the child process. Fixes #884
* Use shorter thread names for FFI's callbacksLars Kanis2021-03-051-2/+2
| | | | The thread name is truncated in gdb to 15 characters, so that there was no distiction between "Callback Runner" and "Callback Dispatcher".
* Merge branch 'name-dispatcher-thread' of https://github.com/DataDog/ffi into ↵Lars Kanis2021-02-281-1/+5
|\ | | | | | | DataDog-name-dispatcher-thread
| * Name callback runner thread for easier debuggingIvo Anjo2021-02-211-2/+4
| | | | | | | | Similar to what was done for the dispatcher thread.
| * Name the async_cb_thread for easier debuggingIvo Anjo2021-02-191-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I found this useful while reviewing datadog/dd-trace-rb#1371 -- we were searching for specs that leaked threads, and saw a "mysterious" thread with no stack that we couldn't exactly point out what created it or why it existed. By setting a name on the callback thread, it becomes immediately obvious when looking at `Thread.list` what this thread is and where it comes from. (Thread naming has been around [since Ruby 2.3](https://github.com/ruby/ruby/blob/v2_3_0/NEWS) which means we can do it safely for every supported version)
* | Remove unused NATIVE_CALLBACK enumLars Kanis2021-02-281-2/+0
|/
* Merge branch 'fix-crash-on-apple-silicon' of ↵Lars Kanis2020-12-051-1/+1
|\ | | | | | | https://github.com/Watson1978/ffi into Watson1978-fix-crash-on-apple-silicon
| * Use ffi_closure_alloc() on Apple silicon to fix crashWatson2020-07-181-1/+1
| |
* | Remove win32/stdint.h and stdbool.hLars Kanis2020-09-231-9/+2
| | | | | | | | | | | | | | | | Only very old Visual-C compilers before 2010 didn't contain these files. Since the copyright of the included files conflicts with ffi's license, we better remove it. Fixes #693
* | Fix GC issue, when Proc is used on more than 2 callback signaturesLars Kanis2020-08-311-3/+5
|/ | | | Fixes #820
* Remove code required for ruby prior 2.3Lars Kanis2020-06-011-20/+2
| | | | Now that the gemspec requires ruby-2.3 or newer, compatibility code can be removed.
* Add long double as callback return valueLars Kanis2020-04-161-1/+4
| | | | Such callbacks returned nan before.
* replace ffi_prep_closure with ffi_prep_closure_locpavel2020-02-151-2/+2
|
* Remove taint supportyuuji.yaginuma2019-11-251-1/+1
| | | | | | | | | | Ruby 2.7 deprecates taint and it no longer has an effect. https://bugs.ruby-lang.org/issues/16131 The APIs related to taint cause deprecation warning message and the lack of taint support should not cause a problem in previous Ruby versions. So I removed that. But if need to taint support that to old versions of Ruby, I will update PR.
* Fix compiler warnings raised by ruby-2.7Lars Kanis2019-10-101-4/+4
|
* Remove old code for 'blocking: true' on Ruby before 2.0Lars Kanis2019-02-211-105/+0
| | | | | | | All supported ruby versions have rb_thread_call_without_gvl() and rb_thread_call_without_gvl(), so that we can finally get rid of the old code. This improves readability of Function.c a lot.
* Query ruby thread and GVL states instead of relying on our call frame for ↵Lars Kanis2019-01-251-5/+26
| | | | | | | | | | | | | callbacks This fixes #527 and other interoperability issues that can happen, when a callback is called without a valid call frame. The change is enabled for ruby-2.3+ only, since it requires the functions ruby_native_thread_p() and ruby_thread_has_gvl_p(). The creation of a call frame is not (yet) removed, because it still carries callback expections around.
* Revert "Do closures via libffi"Lars Kanis2018-06-031-16/+25
| | | | | | | | | | | | This reverts commit 9f257af19e6088c2986f85dea17455e52a2be405. This is due to issues with callback in combination with fork() on Centos. See https://github.com/ffi/ffi/issues/621 . It is caused by specialized handling of callback allocation on SE-Linux protected systems through ffi_closure_alloc(), which is incompatible to fork(). Reverting this now, pending more investigation, how we can solve callback allocation in a way that is compatible to both PaX and SE-Linux.
* Fix missing C declarations causing compiler warningsLars Kanis2018-06-021-5/+8
| | | | | | | | | | | | | | | | | | | | | | | This fixes declarations for ruby-2.0 and newer. rubies < 2.0 don't define ruby/thread.h, so that the warnings are still present there. compiling ../../../../ext/ffi_c/Call.c In file included from ../../../../ext/ffi_c/Call.h:36:0, from ../../../../ext/ffi_c/Function.h:48, from ../../../../ext/ffi_c/Call.c:57: ../../../../ext/ffi_c/Call.c: In function ‘rbffi_do_blocking_call’: ../../../../ext/ffi_c/Thread.h:78:39: warning: implicit declaration of function ‘rb_thread_call_without_gvl’; did you mean ‘rb_thread_wait_for’? [-Wimplicit-function-declaration] # define rbffi_thread_blocking_region rb_thread_call_without_gvl ^ ../../../../ext/ffi_c/Call.c:334:5: note: in expansion of macro ‘rbffi_thread_blocking_region’ rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ compiling ../../../../ext/ffi_c/Function.c ../../../../ext/ffi_c/Function.c: In function ‘async_cb_event’: ../../../../ext/ffi_c/Function.c:569:9: warning: implicit declaration of function ‘rb_thread_call_without_gvl’; did you mean ‘rb_thread_call_with_gvl’? [-Wimplicit-function-declaration] rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w); ^~~~~~~~~~~~~~~~~~~~~~~~~~ rb_thread_call_with_gvl
* Do closures via libffiMihail Konev2017-07-131-25/+16
| | | | | | | | | | | | This removes ClosurePool. It has been switching pages protection between writable and executable, which was making it incompatible with PaX MPROTECT. libffi instead leaves its closures (closure trampolines) non-executable, relying on PaX to recognize and emulate them, which allows it to work even under such circumstances. Remove CUSTOM_TRAMPOLINE and USE_RAW to avoid ifdef hassle.
* remove RB_GC_GUARD_PTR referencesLamont Granquist2016-03-231-26/+24
| | | | | | | | | | | RB_GC_GUARD_PTR is an 'internal' API and consumers should only use RB_GC_GUARD. On non-GCC/non-MSC compilers (i.e. "Sun" Compiler on Solaris or xlc compiler on AIX) this macro does not exist in a usable form. In this case both of the instances of RB_GC_GUARD_PTR were unnecessary since argv was already protected and rbParams was ALLOCA_N'd onto the stack which does not require protection.
* Fix return type of callback function to rb_thread_call_with_gvl().Lars Kanis2013-11-161-2/+3
| | | | | | | | | The return type is not used but caused a compiler warning: Function.c: In function 'callback_invoke': Function.c:479:9: warning: passing argument 1 of 'rb_thread_call_with_gvl' from incompatible pointer type [enabled by default] Function.c:102:14: note: expected 'void * (*)(void *)' but argument is of type 'VALUE (*)(void *)' This addresses issue #297.
* Fix invalid memory access caused by double dereferencing mapped types in ↵Lars Kanis2013-11-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | callback parameters. This is triggered in callback_spec in "struct by reference argument". Valgrind stacktrace: ==22636== Invalid read of size 8 ==22636== at 0xBF964B3: invoke_callback (Function.c:763) ==22636== by 0x4EA66BD: rb_rescue2 (eval.c:714) ==22636== by 0xBF9638A: callback_with_gvl (Function.c:737) ==22636== by 0xBF96054: callback_invoke (Function.c:475) ==22636== by 0xC1B18CA: ffi_closure_unix64_inner (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.1) ==22636== by 0xC1B1C43: ffi_closure_unix64 (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.1) ==22636== by 0xC1B1ADB: ffi_call_unix64 (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.1) ==22636== by 0xC1B140B: ffi_call (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.1) ==22636== by 0xBF9FB43: rbffi_CallFunction (Call.c:378) ==22636== by 0xBF9FFD5: custom_trampoline (MethodHandle.c:232) ==22636== by 0x4FCE5DE: vm_call_cfunc_with_frame (vm_insnhelper.c:1469) ==22636== by 0x4FDC4FC: vm_call_method (vm_insnhelper.c:1559) ==22636== Address 0xbb9fc30 is 8 bytes after a block of size 24 alloc'd ==22636== at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==22636== by 0x4EC06E7: vm_xmalloc (gc.c:3519) ==22636== by 0xBF9B2EB: builtin_type_new (Type.c:151) ==22636== by 0xBF9C95E: rbffi_Type_Init (Type.c:389) ==22636== by 0xBF94A7B: Init_ffi_c (ffi.c:75) ==22636== by 0x4E6048C: dln_load (dln.c:1354) ==22636== by 0x4FDEE59: rb_vm_call_cfunc (vm.c:1530) ==22636== by 0x4EAA960: rb_require_safe (load.c:963) ==22636== by 0x4FCE5DE: vm_call_cfunc_with_frame (vm_insnhelper.c:1469) ==22636== by 0x4FD3089: vm_exec_core (insns.def:1017) ==22636== by 0x4FD74A9: vm_exec (vm.c:1201) ==22636== by 0x4FDE7ED: rb_iseq_eval (vm.c:1436)
* Fix bad search and replace in C code.1.9.2Charles Oliver Nutter2013-10-291-1/+0
|
* Switch license to BSD throughout codebase. See #288.Charles Oliver Nutter2013-10-291-12/+22
|
* Check for HAVE_RB_THREAD_CALL_WITH_GVLWayne Meissner2013-04-231-2/+3
|
* Re-work exception saving & non-gil function callbacksWayne Meissner2013-04-231-10/+23
|
* Check for HAVE_RB_THREAD_CALL_WITHOUT_GVL _or_ HAVE_RB_THREAD_BLOCKING_REGIONWayne Meissner2013-04-221-6/+6
|
* Extract all win32 MSC stdbool compat typedefs into win32/stdbool.hWayne Meissner2013-04-221-11/+9
|
* Fix warningsWayne Meissner2013-03-051-1/+2
|
* Trap & save exceptions from ruby callbacks.Wayne Meissner2013-02-151-8/+16
|
* Use rb_thread_call_without_gvl where availableWayne Meissner2013-02-151-1/+5
|
* Convert C++ style comments to C /* */ styleWayne Meissner2012-08-041-25/+26
|
* Add experimental support for long double. Fixes issue #194Wayne Meissner2012-02-281-0/+4
|
* Move stdint.h to seperate pathPark Heesob2012-01-141-1/+1
|
* initial releaseunknown2012-01-091-1/+11
|
* Merge pull request #158 from sdaubert/masterWayne Meissner2011-09-251-0/+57
|\ | | | | More documentation
| * Add documentation for ArrayType, Buffer, DynamicLibrary, Function, Enum, EnumsSylvain Daubert2011-09-251-0/+57
| | | | | | | | and ConstGenerator.
* | Add rbffi_thread_blocking_region and DEFER_ASYNC_CALLBACK for Ruby 1.8 on win32Lars Kanis2011-09-081-10/+53
|/ | | | | | This mostly done by replacing posix with win32 functions, but it's working with rb_thread_select() and blocking _pipes, since rb_io_wait_readable() doesn't work with nonblocking pipes.
* Sprinkle RB_GC_GUARD aroundWayne Meissner2011-08-301-0/+1
|
* Fixup subclasses of PointerWayne Meissner2011-03-261-10/+20
|
* Make ffi build for 1.8.x on win32 againWayne Meissner2011-01-091-6/+5
|
* Sync up copyright headersWayne Meissner2011-01-091-2/+2
|