File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed
Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 3636#include " core/templates/rb_set.h"
3737
3838#include " modules/modules_enabled.gen.h" // For regex.
39+
3940#ifdef MODULE_REGEX_ENABLED
4041#include " modules/regex/regex.h"
41- #else
42- class RegEx : public RefCounted {};
4342#endif // MODULE_REGEX_ENABLED
4443
4544#if defined(MINGW_ENABLED) || defined(_MSC_VER)
Original file line number Diff line number Diff line change @@ -180,10 +180,15 @@ class Ref {
180180 // do a lot of referencing on references and stuff
181181 // mutexes will avoid more crashes?
182182
183- if (reference && reference->unreference ()) {
184- memdelete (reference);
183+ if (reference) {
184+ // NOTE: `reinterpret_cast` is "safe" here because we know `T` has simple linear
185+ // inheritance to `RefCounted`. This guarantees that `T * == `RefCounted *`, which
186+ // allows us to declare `Ref<T>` with forward declared `T` types.
187+ if (reinterpret_cast <RefCounted *>(reference)->unreference ()) {
188+ memdelete (reinterpret_cast <RefCounted *>(reference));
189+ }
190+ reference = nullptr ;
185191 }
186- reference = nullptr ;
187192 }
188193
189194 template <typename ... VarArgs>
You can’t perform that action at this time.
0 commit comments