From 40d75c62761e80fa0cf4048f4af63a36bf6a605a Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 2 Jul 2025 15:21:31 +0900 Subject: [PATCH] api: fixed mis-aligned the ref count size, u8 -> u16 C++ API Modifications: * uint8_t Paint::unref() -> uint16_t Paint::ref() * uint8_t Paint::ref() -> uint16_t Paint::unref() * uint8_t Paint::refCnt() -> uint16_t Paint::refCnt() C API Modifications: * uint8_t tvg_paint_ref(...) -> uint16_t tvg_paint_ref(...) * uint8_t tvg_paint_unref(...) -> uint16_t tvg_paint_unref(...) * uint8_t tvg_paint_get_ref(...) -> uint16_t tvg_paint_get_ref(...) --- inc/thorvg.h | 6 +++--- src/bindings/capi/thorvg_capi.h | 6 +++--- src/bindings/capi/tvgCapi.cpp | 18 +++++++++--------- src/renderer/tvgPaint.cpp | 6 +++--- src/renderer/tvgPaint.h | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/inc/thorvg.h b/inc/thorvg.h index f5c2db3a..e053d6e4 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -506,7 +506,7 @@ public: * * @since 1.0 */ - uint8_t ref() noexcept; + uint16_t ref() noexcept; /** * @brief Decrement the reference count for the Paint instance. @@ -523,7 +523,7 @@ public: * * @since 1.0 */ - uint8_t unref(bool free = true) noexcept; + uint16_t unref(bool free = true) noexcept; /** * @brief Retrieve the current reference count of the Paint instance. @@ -537,7 +537,7 @@ public: * * @since 1.0 */ - uint8_t refCnt() const noexcept; + uint16_t refCnt() const noexcept; /** * @brief Returns the ID value of this class. diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index da8733b7..9a3e67d0 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -729,7 +729,7 @@ TVG_API Tvg_Result tvg_paint_del(Tvg_Paint* paint); * * @since 1.0 */ -TVG_API uint8_t tvg_paint_ref(Tvg_Paint* paint); +TVG_API uint16_t tvg_paint_ref(Tvg_Paint* paint); /** @@ -748,7 +748,7 @@ TVG_API uint8_t tvg_paint_ref(Tvg_Paint* paint); * * @since 1.0 */ -TVG_API uint8_t tvg_paint_unref(Tvg_Paint* paint, bool free); +TVG_API uint16_t tvg_paint_unref(Tvg_Paint* paint, bool free); /** @@ -765,7 +765,7 @@ TVG_API uint8_t tvg_paint_unref(Tvg_Paint* paint, bool free); * * @since 1.0 */ -TVG_API uint8_t tvg_paint_get_ref(const Tvg_Paint* paint); +TVG_API uint16_t tvg_paint_get_ref(const Tvg_Paint* paint); /*! diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index b650a671..80efa53a 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -180,24 +180,24 @@ TVG_API Tvg_Result tvg_paint_del(Tvg_Paint* paint) } -TVG_API uint8_t tvg_paint_ref(Tvg_Paint* paint) +TVG_API uint16_t tvg_paint_ref(Tvg_Paint* paint) { - if (paint) return (Tvg_Result) reinterpret_cast(paint)->ref(); - return TVG_RESULT_INVALID_ARGUMENT; + if (paint) return reinterpret_cast(paint)->ref(); + return 0; } -TVG_API uint8_t tvg_paint_unref(Tvg_Paint* paint, bool free) +TVG_API uint16_t tvg_paint_unref(Tvg_Paint* paint, bool free) { - if (paint) return (Tvg_Result) reinterpret_cast(paint)->unref(free); - return TVG_RESULT_INVALID_ARGUMENT; + if (paint) return reinterpret_cast(paint)->unref(free); + return 0; } -TVG_API uint8_t tvg_paint_get_ref(const Tvg_Paint* paint) +TVG_API uint16_t tvg_paint_get_ref(const Tvg_Paint* paint) { - if (paint) return (Tvg_Result) reinterpret_cast(paint)->refCnt(); - return TVG_RESULT_INVALID_ARGUMENT; + if (paint) return reinterpret_cast(paint)->refCnt(); + return 0; } diff --git a/src/renderer/tvgPaint.cpp b/src/renderer/tvgPaint.cpp index c04e47db..12c07a93 100644 --- a/src/renderer/tvgPaint.cpp +++ b/src/renderer/tvgPaint.cpp @@ -430,19 +430,19 @@ Result Paint::blend(BlendMethod method) noexcept } -uint8_t Paint::ref() noexcept +uint16_t Paint::ref() noexcept { return pImpl->ref(); } -uint8_t Paint::unref(bool free) noexcept +uint16_t Paint::unref(bool free) noexcept { return pImpl->unrefx(free); } -uint8_t Paint::refCnt() const noexcept +uint16_t Paint::refCnt() const noexcept { return pImpl->refCnt; } diff --git a/src/renderer/tvgPaint.h b/src/renderer/tvgPaint.h index e79d39ad..bddb7b97 100644 --- a/src/renderer/tvgPaint.h +++ b/src/renderer/tvgPaint.h @@ -106,18 +106,18 @@ namespace tvg } } - uint8_t ref() + uint16_t ref() { return ++refCnt; } - uint8_t unref(bool free = true) + uint16_t unref(bool free = true) { parent = nullptr; return unrefx(free); } - uint8_t unrefx(bool free) + uint16_t unrefx(bool free) { if (refCnt > 0) --refCnt;