* Fix GitHub Actions
* Disable tests with `musl` for arm64 because there's no `libv8-node` gem for aarch64-linux-musl at the moment
* Fix tests on older Ruby versions by running `gem update --system`
* Removes macOS 10.15 (it will be unsupported by 2022-08-30 anyway)
* Adds macOS 12 to the matrix
* Run TruffleRuby job on macOS as well
* Use `ruby/setup-ruby` action where possible and update `actions/checkout` to v3
* Run tests for pull requests
* Raise sleep duration in tests to fix CI failures on macOS
* Add tests for mutable string arguments and return values
This gives a nice binary size reduction and may allow us to eliminate
the mini_racer_loader shim:
text data bss
before: 63987419 718108 110676
after: 56535503 454196 110676
append_ldflags is available in Ruby 2.3+ mkmf.rb, allowing us
to probe for supported LDFLAGS without extra conditionals.
whereas rb_enc_find requires an extra hash lookup. That said,
I've yet to measure an improvement in current benchmarks, though
binary size is reduced:
text data bss
before: 63988228 718148 110676
after: 63987419 718108 110676
Merely closing the pipe is enough to trigger a wakeup from
IO#wait_readable, there's no need to make a write(2) syscall nor
copy data in/out of the kernel. We'll use the Ruby 2.3+ 'foo&.method'
calls in a few places to simplify code, as well.
Check_Type is less code and used throughout the Ruby ecosystem and
raises TypeError on incorrect argument types. This is a minor behavior
change as it replaces some ArgumentError exceptions with TypeError, but
is more consistent with other Ruby libraries.
* changes link to supported Rubies to "Ruby Maintenance Branches"
This pages lists the support status of different Ruby versions
alongside with a note on the respective EOLs.
* adds note to "Fork safety" about V8 single threaded platform mode
Triggering an allocation inside a `free' callback doesn't help
in low memory situations; so operate directly on the ContextInfo
being freed when possible instead of creating a short-lived copy
of it.
For the `isolate_info->refs() > 1' case, we'll leak slightly
less memory by freeing the short-lived allocation in case
pthread_create(3) fails.
IO.select creates more garbage and gets slower on high-numbered
FDs. IO#wait_readable can use ppoll(2) to achieve consistent
performance regardless of FD value.
rb_thread_call_without_gvl may raise exceptions and prevent free(3) from
firing. Instead of relying on malloc(3) and free(3), rely on the Ruby
GC to recover memory on exceptions.
In most cases, alloca() is used and malloc/free are avoided entirely.
alloca(0) works with all compilers tested (clang 10..12, gcc 9.3), so
there's no need to create extra branches for the rare argc == 0 case.
RB_ALLOCV_N and RB_ALLOCV_END are documented in Ruby 3.1 public headers
(while functions those macros use internally are private). They are
used by the standard 'etc', 'date', and 'openssl' C extensions and exist
in their current ("RB_"-prefixed) form since Ruby 2.3. The non-prefixed
variants (ALLOCV_N, ALLOCV_END) have existed since Ruby 1.9.3.
Casting the result of RSTRING_LEN on 64-bit long systems with 32-bit
ints can lead to truncation errors when dealing with gigantic strings.
RSTRING_LENINT was introduced in Ruby 1.9.2 to avoid this problem, so
make use of it. It's used by by several standard extensions (openssl,
zlib) and expected to remain part of the supported Ruby C API.
While RUBY_METHOD_FUNC causes problems with newer Rubies, it's still
needed under Ruby 2.6 with clang. We'll define our own macro to
make it a no-op under Ruby 2.7+.
Tested with clang 10.0.0-4ubuntu1, 11.0.0-2~ubuntu20.04.1, and
12.0.0-3ubuntu1~20.04.4 on Ubuntu 20.04.3 LTS (x86-64).
Fixes: 7a16ef8120 ("remove RUBY_METHOD_FUNC use")
Fixes: #223
When raising ScriptTerminatedError due to timeout, MaybeLocal
could be empty and would core dump upon calling .ToLocalChecked.
Avoid that by checking MaybeLocal::IsEmpty before calling
ToLocalChecked and clearing the evalRes.executed flag so we
enter the exception handling branch below.
In order to support exception classes which take non-String #initialize
arguments, we must not blindly call rb_raise() to create a new exception
object. Instead, we can use rb_exc_raise() to reuse the existing
exception object.
While rb_exc_raise() isn't documented in extension.rdoc of the Ruby
source tree, it is used by several standard extensions such as
"openssl", "json", "psych", "zlib", and therefore expected to remain
supported by Ruby core developers.
Fixes#165
Tested with clang 10, 11, and 12 with ruby 3.1.0dev (master 0b999bef29).
This allows tests to run without "_ZTVN10__cxxabiv117__class_type_infoE"
errors on Ubuntu 20.04.3 Linux x86_64
A common mistake, the "CPP" in "CPPFLAGS" is for "C pre-processor"
and most of these options are intended for the (C++) compiler,
not the preprocessor.
In Ruby <=2.7, SecureRandom.hex lazily defined `gen_random'.
While the method definition itself was protected by a mutex,
another thread calling `gen_random' did not take the mutex so
it would attempt to call the method while another method was
still defining it.
Ruby 3.0+ has commit 475c8701d74ebebe (Make SecureRandom support
Ractor, 2020-09-04) which also made it thread-safe in addition
to being Ractor-safe.
The result of fdopen(3) must be matched with fclose(3) to
avoid memory leaks. However, fclose(3) has the side-effect
of closing the underlying FD behind Ruby's back (which would
corrupt Ruby's internals and cause problems for the remainder
of the process lifetime).
While one could dup(fptr->fd) to fdopen+fclose the resulting fd,
it would cause problems on FD-constrained systems. Since
GetChunkSize() is available and returns a reasonable value
(64K), the buffering of fwrite(3) is unnecessary and we can
safely use write(2) without performance loss.
So use unbuffered write(2) and perhaps prepare us for better
error reporting in a future change.
I've verified WriteAsciiChunk is indeed receiving the requested
64K (or close to it) in nearly all cases, so excessive syscalls
should not be a problem.
This is the least straightforward of the TypedData conversions
due to a possible bugfix in rb_context_create_isolate_value.
I believe the original call to Data_Wrap_Struct from
rb_context_create_isolate_value intentionally omitted the dmark
callback as a possible optimization. It's no longer possible to
have a one-off definition with TypedData. I also suspect there
were cases where the original code would be unsafe if the
original Isolate Ruby object died before the Context.
In any case, the performance cost of an extra GC mark call is
probably negligible, here; and the safest course of action is
to always mark a data type consistently.
TypedData allows memsize reporting and adds some extra
type-safety checks. Furthermore, TypedData_Make_Struct saves
us several lines of code in the allocate() function.
These functions don't appear to be used outside of
mini_racer_extension.cc, so lets not pollute symbol tables or
confuse future readers with unnecessary visibility.
This was causing deprecation warnings from ANYARGS usage
and no longer necessary since Ruby 1.8+, at least. It's
not used by any of the core *.c nor ext/ extensions in
the C ruby source tree, and I've rarely seen it used in
3rd-party C extensions.
The ruby/internal/attr/noreturn.h header of Ruby 3.0+ favors
using __has_declspec_attribute and __declspec(noreturn) over
other options (e.g. __attribute__((__noreturn__)) for gcc) i
available.
gcc (9.3.0) does not currently implement
__has_declspec_attribute and Ruby headers will use the
gcc-specific __attribute__((__noreturn__)).
clang (10.0.0) implements __has_declspec_attribute and Ruby
headers will favor use of __declspec, however __declspec itself
is only available via -fms-extensions or -fdeclspec in clang.
The -fms-extensions flag was chosen over -fdeclspec for
compatibility with gcc, as gcc only implements the former.
* Update to use libv8-node 16.3.0
Based on V8 9.0, his is the new LTS, node 15 now being unsupported. It
notably introduces single threaded mode.
Requiring c++14 is apparently the only change needed for this major. A
separate PR will add a more helpful install time check for compiler
requirements.
* Disable pointer compression
Node 16.4.0 introduced new cage flags for the experimental pointer
compression stuff. Unfortunately something fails and none of them are
set which causes the build to bail out because of the inconsistency.
* Update to use libv8-node 16.10.0
C++ will 'promote' a bitfield member that is narrower than an int into an int on arithmetic, leading to sign extension when converted back to a wider type.
gc callback can happen between init and set
this causes a confusing OOM crash because max mem is 0 at this point, so if the callback is hit, then the isolate will terminate no matter what.
Co-authored-by: nightpool <nightpool@users.noreply.github.com>
This is an attempt to make the CI configuration smaller, more confident. I am guessing that we are not relying on Bundler 1.x-specific behavior, so this commit is a try-out of that.