Skip to content

Commit f61cedb

Browse files
authored
Merge pull request #390 from ruby-rice/dev
Dev
2 parents d028ee8 + 351e059 commit f61cedb

24 files changed

Lines changed: 208 additions & 276 deletions

Agents.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Agent Instructions
2+
3+
## Rules
4+
5+
- NEVER add an `#include` header to any file. To control header include order, edit `rice/rice.hpp`.
6+
- NEVER run `ruby lib/rice/make_rice_headers.rb`. The `include/` folder is autogenerated by a GitHub hook.
7+
8+
## Building
9+
10+
Configure and build from the project root directory:
11+
12+
```bash
13+
cmake --preset linux-debug
14+
cmake --build --preset linux-debug
15+
```
16+
17+
## Running Tests
18+
19+
Run all tests via the built `unittest` executable:
20+
21+
```bash
22+
./build/linux-debug/test/unittest
23+
```
24+
25+
Run specific test suites by passing suite names as arguments:
26+
27+
```bash
28+
./build/linux-debug/test/unittest Array Hash Iterator
29+
```

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

3-
## 4.11.0 (Unreleased)
3+
## 4.11.0 (2026-02-17)
4+
5+
Enhancements:
6+
This release focuses on improving memory management:
7+
* C++ API is now GC safe
8+
* C++ API wrappers no longer default to rb_cObject, avoiding unintended Object changes
9+
* Enable Instance Registry for Ruby owned C++ objects to avoid double frees
410

511
Incompatible Changes:
612
* `InstanceRegistry.isEnabled` (boolean) has been replaced by an `InstanceRegistry.isEnabled` which is an enum (`Off`, `Owned`, `All`).
@@ -9,6 +15,7 @@ Incompatible Changes:
915
* C++ API wrappers now store their Ruby `VALUE` in a `Pin` instead of a raw `VALUE` field. Previously, wrappers were not GC-safe and Ruby could reclaim wrapped objects while C++ still referenced them. This is now fixed, and wrappers such as `Object` can be stored safely in containers like `std::vector`.
1016
* The global `Object` constants (`Rice::Nil`, `Rice::True`, `Rice::False`, `Rice::Undef`) have been removed.
1117
* `Object::test()` has been removed. Use `operator bool()` or `is_nil()` depending on the desired semantics.
18+
* Remove `Builtin_Object` since it didn't serve a useful purpose
1219

1320
## 4.10.0 (2026-02-07)
1421

docs/cpp_api/struct.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Struct inherits from [Class](class.md), which means it has access to:
240240
* `define_singleton_method` - Add class methods
241241
* `create` - Create instances
242242

243-
Struct::Instance inherits from `Builtin_Object<T_STRUCT>`, providing access to [Object](object.md) methods.
243+
Struct::Instance inherits from [Object](object.md) and validates that wrapped values are Ruby structs (`T_STRUCT`).
244244

245245
---
246246

lib/rice/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Rice
2-
VERSION = "4.10.0"
2+
VERSION = "4.11.0"
33
end

rice/Director.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ namespace Rice
1313
public:
1414
//! Construct new Director. Needs the Ruby object so that the
1515
// proxy class can call methods on that object.
16-
Director(Object self) : self_(self)
17-
{
18-
}
16+
Director(Object self);
1917

2018
virtual ~Director() = default;
2119

@@ -24,13 +22,10 @@ namespace Rice
2422
* method, use this method to throw an exception in this case.
2523
*/
2624
[[noreturn]]
27-
void raisePureVirtual() const
28-
{
29-
rb_raise(rb_eNotImpError, "Cannot call super() into a pure-virtual C++ method");
30-
}
25+
void raisePureVirtual() const;
3126

3227
//! Get the Ruby object linked to this C++ instance
33-
Object getSelf() const { return self_; }
28+
Object getSelf() const;
3429

3530
private:
3631

rice/Director.ipp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef Rice__Director__ipp_
2+
#define Rice__Director__ipp_
3+
4+
namespace Rice
5+
{
6+
inline Director::Director(Object self) : self_(self)
7+
{
8+
}
9+
10+
inline void Director::raisePureVirtual() const
11+
{
12+
rb_raise(rb_eNotImpError, "Cannot call super() into a pure-virtual C++ method");
13+
}
14+
15+
inline Object Director::getSelf() const
16+
{
17+
return self_;
18+
}
19+
}
20+
#endif // Rice__Director__ipp_

rice/cpp_api/Array.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Rice
1717
* \endcode
1818
*/
1919
class Array
20-
: public Builtin_Object<T_ARRAY>
20+
: public Object
2121
{
2222
public:
2323
//! Construct a new array
@@ -243,4 +243,4 @@ namespace Rice
243243
Array::Iterator<Array_Ptr_T, Value_T> const& it);
244244
} // namespace Rice
245245

246-
#endif // Rice__Array__hpp_
246+
#endif // Rice__Array__hpp_

rice/cpp_api/Array.ipp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33

44
namespace Rice
55
{
6-
inline Array::Array() : Builtin_Object<T_ARRAY>(detail::protect(rb_ary_new))
6+
inline Array::Array() : Object(detail::protect(rb_ary_new))
77
{
88
}
99

10-
inline Array::Array(long capacity) : Builtin_Object<T_ARRAY>(detail::protect(rb_ary_new_capa, capacity))
10+
inline Array::Array(long capacity) : Object(detail::protect(rb_ary_new_capa, capacity))
1111
{
1212
}
1313

14-
inline Array::Array(Object v) : Builtin_Object<T_ARRAY>(v)
14+
inline Array::Array(Object v) : Object(v)
1515
{
16+
detail::protect(rb_check_type, this->value(), T_ARRAY);
1617
}
1718

18-
inline Array::Array(VALUE v) : Builtin_Object<T_ARRAY>(v)
19+
inline Array::Array(VALUE v) : Object(v)
1920
{
21+
detail::protect(rb_check_type, this->value(), T_ARRAY);
2022
}
2123

2224
template<typename Iter_T>
23-
inline Array::Array(Iter_T it, Iter_T end) : Builtin_Object<T_ARRAY>(detail::protect(rb_ary_new))
25+
inline Array::Array(Iter_T it, Iter_T end) : Object(detail::protect(rb_ary_new))
2426
{
2527
for (; it != end; ++it)
2628
{
@@ -29,7 +31,7 @@ namespace Rice
2931
}
3032

3133
template<typename T, long n>
32-
inline Array::Array(T (&a)[n]) : Builtin_Object<T_ARRAY>(detail::protect(rb_ary_new))
34+
inline Array::Array(T (&a)[n]) : Object(detail::protect(rb_ary_new))
3335
{
3436
for (long j = 0; j < n; ++j)
3537
{
@@ -442,4 +444,4 @@ namespace Rice::detail
442444
Arg* arg_ = nullptr;
443445
};
444446
}
445-
#endif // Rice__Array__ipp_
447+
#endif // Rice__Array__ipp_

rice/cpp_api/Builtin_Object.hpp

Lines changed: 0 additions & 31 deletions
This file was deleted.

rice/cpp_api/Builtin_Object.ipp

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)