diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f72734..5e459b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Drop macOS 11 support - Fix (and test) all compression modules on all platforms - Recompiling the built-in Python now requires that `conan>=2.0.0` is installed - + - Fix [#324](https://github.com/mmomtchev/pymport/issues/324), reference counting error when accessing the Python constructor `.constr` + ### [1.5.1] 2024-04-01 - Fix the build with recent Node.js versions after `node_api_nogc_env` in Node.js 18.20 diff --git a/src/pyobj.cc b/src/pyobj.cc index 2f519fc..7da159e 100644 --- a/src/pyobj.cc +++ b/src/pyobj.cc @@ -158,7 +158,7 @@ Value PyObjectWrap::Constructor(const CallbackInfo &info) { Napi::Env env = info.Env(); PyGILGuard pyGilGuard; - return New(env, PyStrongRef(reinterpret_cast(Py_TYPE(*self)))); + return New(env, PyStrongRef(PyWeakRef(reinterpret_cast(Py_TYPE(*self))))); } Value PyObjectWrap::Item(const CallbackInfo &info) { diff --git a/src/pystackobject.h b/src/pystackobject.h index 03864e4..c96fbe9 100644 --- a/src/pystackobject.h +++ b/src/pystackobject.h @@ -115,7 +115,7 @@ class PyStrongRef : public PyWeakRef { self = v.self; v.self = nullptr; } else if (v.self == nullptr) { - VERBOSE_PYOBJ(REFS, v.self, "StrongRef unreference"); + VERBOSE_PYOBJ(REFS, self, "StrongRef unreference"); ASSERT(self->ob_refcnt > 0); Py_DECREF(self); self = nullptr;