From 45cdffdf3216b0ea2eb480bfc7fc03881519e613 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Wed, 6 Nov 2024 23:10:36 -0800 Subject: [PATCH] let PointerValue::invalidate() be noexcept Summary: X-link: https://github.com/facebook/react-native/pull/47354 `PointerValue::invalidate()` is called from `Pointer` destructor, which is implicitly `noexcept`, and from `Pointer` move-assignment operator, which is now `noexcept`. Reviewed By: neildhar Differential Revision: D65271399 fbshipit-source-id: 26fd9707e4389da78537d0d607adaef0c68690ca --- API/hermes/hermes.cpp | 6 +++--- API/hermes_abi/HermesABIRuntimeWrapper.cpp | 6 +++--- API/hermes_sandbox/HermesSandboxRuntime.cpp | 6 +++--- API/jsi/jsi/jsi.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/API/hermes/hermes.cpp b/API/hermes/hermes.cpp index 49324d2364a..cb2074cd26e 100644 --- a/API/hermes/hermes.cpp +++ b/API/hermes/hermes.cpp @@ -927,7 +927,7 @@ class HermesRuntimeImpl final : public HermesRuntime, return value_; } - void invalidate() override { + void invalidate() noexcept override { #ifdef ASSERT_ON_DANGLING_VM_REFS assert( ((1u << 31) & refCount_) == 0 && @@ -936,7 +936,7 @@ class HermesRuntimeImpl final : public HermesRuntime, dec(); } - void inc() { + void inc() noexcept { // It is always safe to use relaxed operations for incrementing the // reference count, because the only operation that may occur concurrently // with it is decrementing the reference count, and we do not need to @@ -947,7 +947,7 @@ class HermesRuntimeImpl final : public HermesRuntime, (void)oldCount; } - void dec() { + void dec() noexcept { // It is safe to use relaxed operations here because decrementing the // reference count is the only access that may be performed without proper // synchronisation. As a result, the only ordering we need to enforce when diff --git a/API/hermes_abi/HermesABIRuntimeWrapper.cpp b/API/hermes_abi/HermesABIRuntimeWrapper.cpp index cf1776fed57..405d1af5672 100644 --- a/API/hermes_abi/HermesABIRuntimeWrapper.cpp +++ b/API/hermes_abi/HermesABIRuntimeWrapper.cpp @@ -189,11 +189,11 @@ class HermesABIRuntimeWrapper : public Runtime { return managedPointer_; } - void invalidate() override { + void invalidate() noexcept override { dec(); } - void inc() { + void inc() noexcept { // See comments in hermes_abi.cpp for why we use relaxed operations here. auto oldCount = refCount_.fetch_add(1, std::memory_order_relaxed); assert(oldCount && "Cannot resurrect a pointer"); @@ -201,7 +201,7 @@ class HermesABIRuntimeWrapper : public Runtime { (void)oldCount; } - void dec() { + void dec() noexcept { // See comments in hermes_abi.cpp for why we use relaxed operations here. auto oldCount = refCount_.fetch_sub(1, std::memory_order_relaxed); assert(oldCount > 0 && "Ref count underflow"); diff --git a/API/hermes_sandbox/HermesSandboxRuntime.cpp b/API/hermes_sandbox/HermesSandboxRuntime.cpp index 181d129c852..ded57ed162b 100644 --- a/API/hermes_sandbox/HermesSandboxRuntime.cpp +++ b/API/hermes_sandbox/HermesSandboxRuntime.cpp @@ -1048,11 +1048,11 @@ class HermesSandboxRuntimeImpl : public facebook::hermes::HermesSandboxRuntime, return managedPointer_; } - void invalidate() override { + void invalidate() noexcept override { dec(); } - void inc() { + void inc() noexcept { // See comments in hermes_vtable.cpp for why we use relaxed operations // here. auto oldCount = refCount_.fetch_add(1, std::memory_order_relaxed); @@ -1061,7 +1061,7 @@ class HermesSandboxRuntimeImpl : public facebook::hermes::HermesSandboxRuntime, (void)oldCount; } - void dec() { + void dec() noexcept { // See comments in hermes_vtable.cpp for why we use relaxed operations // here, and why TSAN requires different ordering. diff --git a/API/jsi/jsi/jsi.h b/API/jsi/jsi/jsi.h index 07e3722cb0e..a826923a640 100644 --- a/API/jsi/jsi/jsi.h +++ b/API/jsi/jsi/jsi.h @@ -288,7 +288,7 @@ class JSI_EXPORT Runtime { // rvalue arguments/methods would also reduce the number of clones. struct PointerValue { - virtual void invalidate() = 0; + virtual void invalidate() noexcept = 0; protected: virtual ~PointerValue() = default;