Skip to content

Commit 930f2e4

Browse files
authored
Merge pull request #381 from ruby-rice/dev
Run tests with stress GC on and see what happens.
2 parents abc6d80 + be4646d commit 930f2e4

19 files changed

Lines changed: 109 additions & 72 deletions

Rice.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ if(NOT TARGET Rice)
44
add_library(Rice INTERFACE)
55

66
target_include_directories(Rice INTERFACE
7-
$<BUILD_INTERFACE:$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}>>
8-
$<BUILD_INTERFACE:$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/include>>
7+
$<BUILD_INTERFACE:$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}>>
8+
$<BUILD_INTERFACE:$<$<CONFIG:Release>:${CMAKE_CURRENT_LIST_DIR}/include>>
99
$<INSTALL_INTERFACE:include>
1010
)
1111

rice/Pin.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@ namespace Rice
1818
class Pin
1919
{
2020
public:
21-
//! Construct a strong pin for a Ruby VALUE.
22-
explicit Pin(VALUE value);
21+
//! Construct a pin from a Ruby VALUE.
22+
Pin(VALUE value);
2323

24-
// Shared-anchor semantics.
24+
// Copying
2525
Pin(const Pin&) = default;
2626
Pin& operator=(const Pin&) = default;
2727

28+
// Moving
2829
Pin(Pin&&) noexcept = default;
2930
Pin& operator=(Pin&&) noexcept = default;
3031

31-
//! Replace the pinned Ruby VALUE.
32-
void set(VALUE value);
33-
3432
//! Retrieve the pinned Ruby VALUE.
35-
VALUE get() const;
33+
VALUE value() const;
3634

3735
private:
3836
//! Shared ownership of the internal GC anchor.

rice/Pin.ipp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ namespace Rice
55
{
66
}
77

8-
inline void Pin::set(VALUE value)
9-
{
10-
this->anchor_->set(value);
11-
}
12-
13-
inline VALUE Pin::get() const
8+
inline VALUE Pin::value() const
149
{
1510
return this->anchor_->get();
1611
}

rice/cpp_api/Module.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Rice
2424
//! Construct a Module from an existing Module object.
2525
Module(VALUE v);
2626

27-
//! Construct a Module from an string that references a Module
27+
//! Construct a Module from a string that references a Module
2828
Module(std::string name, Object under = rb_cObject);
2929

3030
//! Return the name of the module.

rice/cpp_api/Module.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Rice
1616
}
1717
}
1818

19-
//! Construct a Module from an string that references a Module
19+
//! Construct a Module from a string that references a Module
2020
inline Module::Module(std::string name, Object under)
2121
{
2222
VALUE result = under.const_get(name);

rice/cpp_api/Object.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ namespace Rice
3939
// Having this conversion also prevents accidental conversion to
4040
// undesired integral types (e.g. long or int) by making the
4141
// conversion ambiguous.
42-
bool test() const { return RTEST(value_); }
42+
bool test() const;
4343

4444
//! Returns false if the object is nil or false; returns true
4545
//! otherwise.
46-
operator bool() const { return test(); }
46+
operator bool() const;
4747

4848
//! Returns true if the object is nil, false otherwise.
49-
bool is_nil() const { return NIL_P(value_); }
49+
bool is_nil() const;
5050

5151
//! Implicit conversion to VALUE.
52-
operator VALUE() const { return value_; }
52+
operator VALUE() const;
5353

5454
//! Explicitly get the encapsulated VALUE.
55-
VALUE value() const { return value_; }
55+
VALUE value() const;
5656

5757
//! Get the class of an object.
5858
/*! \return the object's Class.
@@ -254,7 +254,7 @@ namespace Rice
254254

255255
protected:
256256
//! Set the encapsulated value.
257-
void set_value(VALUE v);
257+
void set_value(VALUE value);
258258

259259
private:
260260
volatile VALUE value_;

rice/cpp_api/Object.ipp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ namespace Rice
2727
return *this;
2828
}
2929

30+
inline bool Object::test() const
31+
{
32+
return RTEST(this->value());
33+
}
34+
35+
inline Object::operator bool() const
36+
{
37+
return this->test();
38+
}
39+
40+
inline bool Object::is_nil() const
41+
{
42+
return NIL_P(this->value());
43+
}
44+
45+
inline Object::operator VALUE() const
46+
{
47+
return this->value();
48+
}
49+
50+
inline VALUE Object::value() const
51+
{
52+
return this->value_;
53+
}
54+
3055
template<typename ...Parameter_Ts>
3156
inline Object Object::call(Identifier id, Parameter_Ts... args) const
3257
{
@@ -63,13 +88,13 @@ namespace Rice
6388

6489
inline bool Object::is_equal(const Object& other) const
6590
{
66-
VALUE result = detail::protect(rb_equal, this->value_, other.value_);
91+
VALUE result = detail::protect(rb_equal, this->value(), other.value());
6792
return RB_TEST(result);
6893
}
6994

7095
inline bool Object::is_eql(const Object& other) const
7196
{
72-
VALUE result = detail::protect(rb_eql, this->value_, other.value_);
97+
VALUE result = detail::protect(rb_eql, this->value(), other.value());
7398
return RB_TEST(result);
7499
}
75100

@@ -125,9 +150,9 @@ namespace Rice
125150
return detail::protect(rb_attr_get, this->value(), name.id());
126151
}
127152

128-
inline void Object::set_value(VALUE v)
153+
inline void Object::set_value(VALUE value)
129154
{
130-
value_ = v;
155+
value_ = value;
131156
}
132157

133158
inline Object Object::const_get(Identifier name) const

rice/detail/Anchor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace Rice
5151

5252
private:
5353
//! GC-visible Ruby VALUE slot.
54-
VALUE value_;
54+
VALUE value_ = Qnil;
5555
};
5656
}
5757
}

rice/detail/Anchor.ipp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ namespace Rice
44
{
55
inline Anchor::Anchor(VALUE value) : value_(value)
66
{
7-
Anchor::registerExitHandler();
8-
detail::protect(rb_gc_register_address, &this->value_);
7+
if (value != Qnil)
8+
{
9+
Anchor::registerExitHandler();
10+
detail::protect(rb_gc_register_address, &this->value_);
11+
}
912
}
1013

1114
inline Anchor::~Anchor()
1215
{
13-
if (Anchor::enabled_)
16+
if (Anchor::enabled_ && this->value_ != Qnil)
1417
{
1518
detail::protect(rb_gc_unregister_address, &this->value_);
1619
}
20+
// Ruby auto detects VALUEs in the stack, so make sure up in case this object is on the stack
21+
this->value_ = Qnil;
1722
}
1823

1924
inline VALUE Anchor::get() const

rice/detail/NativeCallback.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ namespace Rice::detail
221221
convertToRuby(args)... };
222222

223223
static Identifier id("call");
224-
VALUE result = detail::protect(rb_funcallv, this->proc_.get(), id.id(), (int)sizeof...(Parameter_Ts), values.data());
224+
VALUE result = detail::protect(rb_funcallv, this->proc_.value(), id.id(), (int)sizeof...(Parameter_Ts), values.data());
225225
if constexpr (!std::is_void_v<Return_T>)
226226
{
227227
return this->fromRuby_.convert(result);

0 commit comments

Comments
 (0)