Skip to content

Commit

Permalink
Py_TYPE returns a borrowed (weak) reference (#325)
Browse files Browse the repository at this point in the history
* Py_TYPE returns a borrowed (weak) reference

* update the changelog
  • Loading branch information
mmomtchev authored Jan 16, 2025
1 parent ba77c3f commit 2de7fae
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/pyobj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Value PyObjectWrap::Constructor(const CallbackInfo &info) {
Napi::Env env = info.Env();
PyGILGuard pyGilGuard;

return New(env, PyStrongRef(reinterpret_cast<PyObject *>(Py_TYPE(*self))));
return New(env, PyStrongRef(PyWeakRef(reinterpret_cast<PyObject *>(Py_TYPE(*self)))));
}

Value PyObjectWrap::Item(const CallbackInfo &info) {
Expand Down
2 changes: 1 addition & 1 deletion src/pystackobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2de7fae

Please sign in to comment.