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
41 changes: 20 additions & 21 deletions cont.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ static const int DEBUG = 0;
#define RB_PAGE_MASK (~(RB_PAGE_SIZE - 1))
static long pagesize;

const rb_data_type_t rb_cont_data_type;
const rb_data_type_t rb_fiber_data_type;
static const rb_data_type_t rb_cont_data_type;
static const rb_data_type_t rb_fiber_data_type;
static VALUE rb_cContinuation;
static VALUE rb_cFiber;
static VALUE rb_eFiberError;
Expand Down Expand Up @@ -1239,17 +1239,11 @@ cont_save_machine_stack(rb_thread_t *th, rb_context_t *cont)
asan_unpoison_memory_region(cont->machine.stack_src, size, false);
MEMCPY(cont->machine.stack, cont->machine.stack_src, VALUE, size);
}
const rb_data_type_t rb_cont_data_type = {
"continuation",
{cont_mark, cont_free, cont_memsize, cont_compact},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};

void
rb_cont_handle_weak_references(VALUE obj)
static void
cont_handle_weak_references(void *ptr)
{
rb_context_t *cont;
TypedData_Get_Struct(obj, rb_context_t, &rb_cont_data_type, cont);
rb_context_t *cont = ptr;

if (!cont) return;

Expand All @@ -1260,6 +1254,12 @@ rb_cont_handle_weak_references(VALUE obj)
}
}

static const rb_data_type_t rb_cont_data_type = {
"continuation",
{cont_mark, cont_free, cont_memsize, cont_compact, cont_handle_weak_references},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};

static inline void
cont_save_thread(rb_context_t *cont, rb_thread_t *th)
{
Expand Down Expand Up @@ -1996,17 +1996,10 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval)
*
*/

const rb_data_type_t rb_fiber_data_type = {
"fiber",
{fiber_mark, fiber_free, fiber_memsize, fiber_compact,},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};

void
rb_fiber_handle_weak_references(VALUE obj)
static void
fiber_handle_weak_references(void *ptr)
{
rb_fiber_t *fiber;
TypedData_Get_Struct(obj, rb_fiber_t, &rb_fiber_data_type, fiber);
rb_fiber_t *fiber = ptr;

if (!fiber) return;

Expand All @@ -2017,6 +2010,12 @@ rb_fiber_handle_weak_references(VALUE obj)
}
}

static const rb_data_type_t rb_fiber_data_type = {
"fiber",
{fiber_mark, fiber_free, fiber_memsize, fiber_compact, fiber_handle_weak_references},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};

static VALUE
fiber_alloc(VALUE klass)
{
Expand Down
33 changes: 10 additions & 23 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,17 +1204,6 @@ rb_gc_handle_weak_references_alive_p(VALUE obj)
return rb_gc_impl_handle_weak_references_alive_p(rb_gc_get_objspace(), obj);
}

extern const rb_data_type_t rb_weakmap_type;
void rb_wmap_handle_weak_references(VALUE obj);
extern const rb_data_type_t rb_weakkeymap_type;
void rb_wkmap_handle_weak_references(VALUE obj);

extern const rb_data_type_t rb_fiber_data_type;
void rb_fiber_handle_weak_references(VALUE obj);

extern const rb_data_type_t rb_cont_data_type;
void rb_cont_handle_weak_references(VALUE obj);

void
rb_gc_handle_weak_references(VALUE obj)
{
Expand All @@ -1223,20 +1212,14 @@ rb_gc_handle_weak_references(VALUE obj)
if (RTYPEDDATA_P(obj)) {
const rb_data_type_t *type = RTYPEDDATA_TYPE(obj);

if (type == &rb_fiber_data_type) {
rb_fiber_handle_weak_references(obj);
}
else if (type == &rb_cont_data_type) {
rb_cont_handle_weak_references(obj);
}
else if (type == &rb_weakmap_type) {
rb_wmap_handle_weak_references(obj);
}
else if (type == &rb_weakkeymap_type) {
rb_wkmap_handle_weak_references(obj);
if (type->function.handle_weak_references) {
(type->function.handle_weak_references)(RTYPEDDATA_GET_DATA(obj));
}
else {
rb_bug("rb_gc_handle_weak_references: unknown TypedData %s", RTYPEDDATA_TYPE(obj)->wrap_struct_name);
rb_bug(
"rb_gc_handle_weak_references: TypedData %s does not implement handle_weak_references",
RTYPEDDATA_TYPE(obj)->wrap_struct_name
);
}
}
else {
Expand Down Expand Up @@ -4861,6 +4844,10 @@ rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALU
}
break;
case T_STRING: {
APPEND_F("[%s%s] ",
C(FL_TEST(obj, RSTRING_FSTR), "F"),
C(RB_OBJ_FROZEN(obj), "R"));

if (STR_SHARED_P(obj)) {
APPEND_F(" [shared] len: %ld", RSTRING_LEN(obj));
}
Expand Down
6 changes: 2 additions & 4 deletions include/ruby/internal/core/rtypeddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,9 @@ struct rb_data_type_struct {
RUBY_DATA_FUNC dcompact;

/**
* This field is reserved for future extension. For now, it must be
* filled with zeros.
* @internal
*/
void *reserved[1]; /* For future extension.
This array *must* be filled with ZERO. */
void (*handle_weak_references)(void *);
} function;

/**
Expand Down
1 change: 1 addition & 0 deletions spec/ruby/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Style/Lambda:
- 'language/lambda_spec.rb'
- 'language/proc_spec.rb'
- 'language/numbered_parameters_spec.rb'
- 'language/it_parameter_spec.rb'
- 'core/kernel/lambda_spec.rb'

Style/EmptyLambdaParameter:
Expand Down
24 changes: 22 additions & 2 deletions spec/ruby/command_line/frozen_strings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,28 @@
ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb")).chomp.should == "false"
end

it "if file has no frozen_string_literal comment produce different mutable strings each time" do
ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
context "if file has no frozen_string_literal comment" do
it "produce different mutable strings each time" do
ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
end

guard -> { ruby_version_is "3.4" and !"test".frozen? } do
it "complain about modification of produced mutable strings" do
-> { eval(<<~RUBY) }.should complain(/warning: literal string will be frozen in the future \(run with --debug-frozen-string-literal for more information\)/)
"test" << "!"
RUBY
end

it "does not complain about modification if Warning[:deprecated] is false" do
deprecated = Warning[:deprecated]
Warning[:deprecated] = false
-> { eval(<<~RUBY) }.should_not complain
"test" << "!"
RUBY
ensure
Warning[:deprecated] = deprecated
end
end
end

it "if file has frozen_string_literal:true comment produce same frozen strings each time" do
Expand Down
10 changes: 3 additions & 7 deletions spec/ruby/core/array/pack/shared/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@
end

ruby_version_is ""..."3.3" do
# https://bugs.ruby-lang.org/issues/19150
# NOTE: it's just a plan of the Ruby core team
it "warns that a directive is unknown" do
# additional directive ('a') is required for the X directive
-> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/)
-> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/)
-> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/)
-> { [@obj, @obj].pack("a K" + pack_format) }.should complain(/unknown pack directive 'K' in 'a K#{pack_format}'/)
-> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0' in 'a 0#{pack_format}'/)
-> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':' in 'a :#{pack_format}'/)
end
end

ruby_version_is "3.3" do
# https://bugs.ruby-lang.org/issues/19150
# NOTE: Added this case just to not forget about the decision in the ticket
it "raise ArgumentError when a directive is unknown" do
# additional directive ('a') is required for the X directive
-> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/)
Expand Down
74 changes: 74 additions & 0 deletions spec/ruby/core/builtin_constants/builtin_constants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
end
end

describe "RUBY_ENGINE_VERSION" do
it "is a String" do
RUBY_ENGINE_VERSION.should be_kind_of(String)
end

it "is frozen" do
RUBY_ENGINE_VERSION.should.frozen?
end
end

describe "RUBY_PLATFORM" do
it "is a String" do
RUBY_PLATFORM.should be_kind_of(String)
Expand Down Expand Up @@ -75,3 +85,67 @@
RUBY_REVISION.should.frozen?
end
end

ruby_version_is "4.0" do
context "The constant" do
describe "Ruby" do
it "is a Module" do
Ruby.should.instance_of?(Module)
end
end

describe "Ruby::VERSION" do
it "is equal to RUBY_VERSION" do
Ruby::VERSION.should equal(RUBY_VERSION)
end
end

describe "RUBY::PATCHLEVEL" do
it "is equal to RUBY_PATCHLEVEL" do
Ruby::PATCHLEVEL.should equal(RUBY_PATCHLEVEL)
end
end

describe "Ruby::COPYRIGHT" do
it "is equal to RUBY_COPYRIGHT" do
Ruby::COPYRIGHT.should equal(RUBY_COPYRIGHT)
end
end

describe "Ruby::DESCRIPTION" do
it "is equal to RUBY_DESCRIPTION" do
Ruby::DESCRIPTION.should equal(RUBY_DESCRIPTION)
end
end

describe "Ruby::ENGINE" do
it "is equal to RUBY_ENGINE" do
Ruby::ENGINE.should equal(RUBY_ENGINE)
end
end

describe "Ruby::ENGINE_VERSION" do
it "is equal to RUBY_ENGINE_VERSION" do
Ruby::ENGINE_VERSION.should equal(RUBY_ENGINE_VERSION)
end
end

describe "Ruby::PLATFORM" do
it "is equal to RUBY_PLATFORM" do
Ruby::PLATFORM.should equal(RUBY_PLATFORM)
end
end

describe "Ruby::RELEASE_DATE" do
it "is equal to RUBY_RELEASE_DATE" do
Ruby::RELEASE_DATE.should equal(RUBY_RELEASE_DATE)
end
end

describe "Ruby::REVISION" do
it "is equal to RUBY_REVISION" do
Ruby::REVISION.should equal(RUBY_REVISION)
end
end
end
end
Loading