Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Note: We're only listing outstanding class updates.
* `IO.select` accepts +Float::INFINITY+ as a timeout argument.
[[Feature #20610]]

* Math

* `Math.log1p` and `Math.expm1` are added. [[Feature #21527]]

* Socket

* `Socket.tcp` & `TCPSocket.new` accepts `open_timeout` as a keyword argument to specify
Expand Down Expand Up @@ -254,3 +258,4 @@ The following bundled gems are updated.
[Feature #21287]: https://bugs.ruby-lang.org/issues/21287
[Feature #21347]: https://bugs.ruby-lang.org/issues/21347
[Feature #21360]: https://bugs.ruby-lang.org/issues/21360
[Feature #21527]: https://bugs.ruby-lang.org/issues/21527
15 changes: 0 additions & 15 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1680,21 +1680,6 @@ AS_IF([test "$rb_cv_func_weak" != x], [
AC_DEFINE(HAVE_FUNC_WEAK)
])

AC_CACHE_CHECK([for __attribute__((__deprecated__(msg))) in C++],
rb_cv_CentOS6_CXX_workaround,
RUBY_WERROR_FLAG([
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[],
[__attribute__((__deprecated__("message"))) int conftest(...);])],
[rb_cv_CentOS6_CXX_workaround=yes],
[rb_cv_CentOS6_CXX_workaround=no])
AC_LANG_POP()]))
AS_IF([test "$rb_cv_CentOS6_CXX_workaround" != no],[
AC_DEFINE([RUBY_CXX_DEPRECATED(msg)],
[__attribute__((__deprecated__(msg)))])])

AC_CACHE_CHECK([for std::nullptr_t], rb_cv_CXX_nullptr, [
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE(
Expand Down
3 changes: 1 addition & 2 deletions depend
Original file line number Diff line number Diff line change
Expand Up @@ -6306,6 +6306,7 @@ imemo.$(OBJEXT): $(top_srcdir)/internal/compilers.h
imemo.$(OBJEXT): $(top_srcdir)/internal/gc.h
imemo.$(OBJEXT): $(top_srcdir)/internal/imemo.h
imemo.$(OBJEXT): $(top_srcdir)/internal/namespace.h
imemo.$(OBJEXT): $(top_srcdir)/internal/object.h
imemo.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
imemo.$(OBJEXT): $(top_srcdir)/internal/serial.h
imemo.$(OBJEXT): $(top_srcdir)/internal/set_table.h
Expand Down Expand Up @@ -7159,7 +7160,6 @@ iseq.$(OBJEXT): $(top_srcdir)/prism/pack.h
iseq.$(OBJEXT): $(top_srcdir)/prism/parser.h
iseq.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
iseq.$(OBJEXT): $(top_srcdir)/prism/prism.h
iseq.$(OBJEXT): $(top_srcdir)/prism/prism.h
iseq.$(OBJEXT): $(top_srcdir)/prism/regexp.h
iseq.$(OBJEXT): $(top_srcdir)/prism/static_literals.h
iseq.$(OBJEXT): $(top_srcdir)/prism/util/pm_buffer.h
Expand Down Expand Up @@ -11676,7 +11676,6 @@ prism/prism.$(OBJEXT): $(top_srcdir)/prism/util/pm_string.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/util/pm_strncasecmp.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/util/pm_strpbrk.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/version.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/version.h
prism/regexp.$(OBJEXT): $(top_srcdir)/prism/ast.h
prism/regexp.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/regexp.$(OBJEXT): $(top_srcdir)/prism/encoding.h
Expand Down
3 changes: 3 additions & 0 deletions imemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "id_table.h"
#include "internal.h"
#include "internal/imemo.h"
#include "internal/object.h"
#include "internal/st.h"
#include "vm_callinfo.h"

Expand Down Expand Up @@ -208,6 +209,8 @@ rb_imemo_fields_clear(VALUE fields_obj)
else {
RBASIC_SET_SHAPE_ID(fields_obj, ROOT_SHAPE_ID);
}
// Invalidate the ec->gen_fields_cache.
RBASIC_CLEAR_CLASS(fields_obj);
}

/* =========================================================================
Expand Down
2 changes: 1 addition & 1 deletion internal/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ RCLASS_WRITE_CALLABLE_M_TBL(VALUE klass, struct rb_id_table *table)
static inline void
RCLASS_WRITE_CC_TBL(VALUE klass, VALUE table)
{
RB_OBJ_WRITE(klass, &RCLASSEXT_CC_TBL(RCLASS_EXT_WRITABLE(klass)), table);
RB_OBJ_ATOMIC_WRITE(klass, &RCLASSEXT_CC_TBL(RCLASS_EXT_WRITABLE(klass)), table);
}

static inline void
Expand Down
71 changes: 71 additions & 0 deletions math.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,34 @@ math_exp(VALUE unused_obj, VALUE x)
return DBL2NUM(exp(Get_Double(x)));
}

/*
* call-seq:
* Math.expm1(x) -> float
*
* Returns "exp(x) - 1", +e+ raised to the +x+ power, minus 1.
*
*
* - Domain: <tt>[-INFINITY, INFINITY]</tt>.
* - Range: <tt>[-1.0, INFINITY]</tt>.
*
* Examples:
*
* expm1(-INFINITY) # => 0.0
* expm1(-1.0) # => -0.6321205588285577 # 1.0/E - 1
* expm1(0.0) # => 0.0
* expm1(0.5) # => 0.6487212707001282 # sqrt(E) - 1
* expm1(1.0) # => 1.718281828459045 # E - 1
* expm1(2.0) # => 6.38905609893065 # E**2 - 1
* expm1(INFINITY) # => Infinity
*
*/

static VALUE
math_expm1(VALUE unused_obj, VALUE x)
{
return DBL2NUM(expm1(Get_Double(x)));
}

#if defined __CYGWIN__
# include <cygwin/version.h>
# if CYGWIN_VERSION_DLL_MAJOR < 1005
Expand Down Expand Up @@ -646,6 +674,47 @@ math_log10(VALUE unused_obj, VALUE x)
return DBL2NUM(log10(d) + numbits * log10(2)); /* log10(d * 2 ** numbits) */
}

/*
* call-seq:
* Math.log1p(x) -> float
*
* Returns "log(x + 1)", the base E {logarithm}[https://en.wikipedia.org/wiki/Logarithm] of (+x+ + 1).
*
* - Domain: <tt>[-1, INFINITY]</tt>.
* - Range: <tt>[-INFINITY, INFINITY]</tt>.
*
* Examples:
*
* log1p(-1.0) # => -Infinity
* log1p(0.0) # => 0.0
* log1p(E - 1) # => 1.0
* log1p(INFINITY) # => Infinity
*
*/

static VALUE
math_log1p(VALUE unused_obj, VALUE x)
{
size_t numbits;
double d = get_double_rshift(x, &numbits);

if (numbits != 0) {
x = rb_big_plus(x, INT2FIX(1));
d = math_log_split(x, &numbits);
/* check for pole error */
if (d == 0.0) return DBL2NUM(-HUGE_VAL);
d = log(d);
d += numbits * M_LN2;
return DBL2NUM(d);
}

domain_check_min(d, -1.0, "log1p");
/* check for pole error */
if (d == -1.0) return DBL2NUM(-HUGE_VAL);

return DBL2NUM(log1p(d)); /* log10(d * 2 ** numbits) */
}

static VALUE rb_math_sqrt(VALUE x);

/*
Expand Down Expand Up @@ -1120,9 +1189,11 @@ InitVM_Math(void)
rb_define_module_function(rb_mMath, "atanh", math_atanh, 1);

rb_define_module_function(rb_mMath, "exp", math_exp, 1);
rb_define_module_function(rb_mMath, "expm1", math_expm1, 1);
rb_define_module_function(rb_mMath, "log", math_log, -1);
rb_define_module_function(rb_mMath, "log2", math_log2, 1);
rb_define_module_function(rb_mMath, "log10", math_log10, 1);
rb_define_module_function(rb_mMath, "log1p", math_log1p, 1);
rb_define_module_function(rb_mMath, "sqrt", math_sqrt, 1);
rb_define_module_function(rb_mMath, "cbrt", math_cbrt, 1);

Expand Down
20 changes: 20 additions & 0 deletions test/ruby/test_math.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def test_exp
check(Math::E ** 2, Math.exp(2))
end

def test_expm1
check(0, Math.expm1(0))
check(Math.sqrt(Math::E) - 1, Math.expm1(0.5))
check(Math::E - 1, Math.expm1(1))
check(Math::E ** 2 - 1, Math.expm1(2))
end

def test_log
check(0, Math.log(1))
check(1, Math.log(Math::E))
Expand Down Expand Up @@ -201,6 +208,19 @@ def test_log10
assert_nothing_raised { assert_infinity(-Math.log10(0)) }
end

def test_log1p
check(0, Math.log1p(0))
check(1, Math.log1p(Math::E - 1))
check(Math.log(2.0 ** 64 + 1), Math.log1p(1 << 64))
check(Math.log(2) * 1024.0, Math.log1p(2 ** 1024))
assert_nothing_raised { assert_infinity(Math.log1p(1.0/0)) }
assert_nothing_raised { assert_infinity(-Math.log1p(-1.0)) }
assert_raise_with_message(Math::DomainError, /\blog1p\b/) { Math.log1p(-1.1) }
assert_raise_with_message(Math::DomainError, /\blog1p\b/) { Math.log1p(-Float::EPSILON-1) }
assert_nothing_raised { assert_nan(Math.log1p(Float::NAN)) }
assert_nothing_raised { assert_infinity(-Math.log1p(-1)) }
end

def test_sqrt
check(0, Math.sqrt(0))
check(1, Math.sqrt(1))
Expand Down
13 changes: 13 additions & 0 deletions test/ruby/test_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,19 @@ def test_local_variables_encoding
assert_equal(%i[α b], b.local_variables)
end

def test_genivar_cache
bug21547 = '[Bug #21547]'
klass = Class.new(Array)
instance = klass.new
instance.instance_variable_set(:@a1, 1)
instance.instance_variable_set(:@a2, 2)
Fiber.new do
instance.instance_variable_set(:@a3, 3)
instance.instance_variable_set(:@a4, 4)
end.resume
assert_equal 4, instance.instance_variable_get(:@a4)
end

private
def with_kwargs_11(v1:, v2:, v3:, v4:, v5:, v6:, v7:, v8:, v9:, v10:, v11:)
local_variables
Expand Down
2 changes: 1 addition & 1 deletion variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ rb_obj_fields(VALUE obj, ID field_name)
generic_fields:
{
rb_execution_context_t *ec = GET_EC();
if (ec->gen_fields_cache.obj == obj) {
if (ec->gen_fields_cache.obj == obj && rb_imemo_fields_owner(ec->gen_fields_cache.fields_obj) == obj) {
fields_obj = ec->gen_fields_cache.fields_obj;
}
else {
Expand Down
9 changes: 8 additions & 1 deletion vm_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,14 @@ cache_callable_method_entry(VALUE klass, ID mid, const rb_callable_method_entry_
#endif
}
else {
vm_ccs_create(klass, cc_tbl, mid, cme);
if (rb_multi_ractor_p()) {
VALUE new_cc_tbl = rb_vm_cc_table_dup(cc_tbl);
vm_ccs_create(klass, new_cc_tbl, mid, cme);
RB_OBJ_ATOMIC_WRITE(klass, &RCLASSEXT_CC_TBL(RCLASS_EXT_WRITABLE(klass)), new_cc_tbl);
}
else {
vm_ccs_create(klass, cc_tbl, mid, cme);
}
}
}

Expand Down