Skip to content

Commit

Permalink
fix: Fix OwningRef/BorrowingRef empty copy constructo
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 15, 2025
1 parent 3a2ea44 commit 224925f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class BorrowingReference final {
BorrowingReference(const BorrowingReference& ref)
: _value(ref._value), _isDeleted(ref._isDeleted), _strongRefCount(ref._strongRefCount), _weakRefCount(ref._weakRefCount),
_mutex(ref._mutex) {
// increment ref count after copy
(*_weakRefCount)++;
if (_weakRefCount != nullptr) {
// increment ref count after copy
(*_weakRefCount)++;
}
}

BorrowingReference(BorrowingReference&& ref)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ class OwningReference final {
OwningReference(const OwningReference& ref)
: _value(ref._value), _isDeleted(ref._isDeleted), _strongRefCount(ref._strongRefCount), _weakRefCount(ref._weakRefCount),
_mutex(ref._mutex) {
// increment ref count after copy
(*_strongRefCount)++;
if (_strongRefCount != nullptr) {
// increment ref count after copy
(*_strongRefCount)++;
}
}

OwningReference(OwningReference&& ref)
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-nitro-modules/cpp/views/CachedProp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace margelo::nitro {
// jsi::Value hasn't changed - no need to convert it again!
return oldProp;
}
T converted = JSIConverter<T>::fromJSI(runtime, value);
auto converted = JSIConverter<T>::fromJSI(runtime, value);
auto cache = JSICache::getOrCreateCache(runtime);
auto cached = cache.makeShared(jsi::Value(runtime, value));
return CachedProp<T>(std::move(converted), cached, /* isDirty */ true);
return CachedProp<T>(std::move(converted), std::move(cached), /* isDirty */ true);
}
};

Expand Down

0 comments on commit 224925f

Please sign in to comment.