Fix Python GIL-not-held issues in python/callbacks.cc.
The GIL bug was introduced in ec6ea6a69e and is resolved by decrementing the refcount before returning from MjWrapperLookup.
PiperOrigin-RevId: 481558798
Change-Id: I2744287d48635a55ae6d2ec46c9e43fe881019d8
This commit is contained in:
committed by
Copybara-Service
parent
ec6ea6a69e
commit
3aaf94f42c
@@ -18,6 +18,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
@@ -46,7 +47,7 @@ using enable_if_not_const_t =
|
|||||||
// table that associates raw MuJoCo struct pointers back to the pointers to
|
// table that associates raw MuJoCo struct pointers back to the pointers to
|
||||||
// their corresponding wrappers.
|
// their corresponding wrappers.
|
||||||
template <typename Raw>
|
template <typename Raw>
|
||||||
static enable_if_not_const_t<Raw, py::object> MjWrapperLookup(Raw* ptr) {
|
static enable_if_not_const_t<Raw, py::handle> MjWrapperLookup(Raw* ptr) {
|
||||||
using LookupFnType = MjWrapper<Raw>* (Raw*);
|
using LookupFnType = MjWrapper<Raw>* (Raw*);
|
||||||
static LookupFnType* const lookup = []() -> LookupFnType* {
|
static LookupFnType* const lookup = []() -> LookupFnType* {
|
||||||
py::gil_scoped_acquire gil;
|
py::gil_scoped_acquire gil;
|
||||||
@@ -102,7 +103,7 @@ static enable_if_not_const_t<Raw, py::object> MjWrapperLookup(Raw* ptr) {
|
|||||||
"cannot find the Python instance of the MjWrapper");
|
"cannot find the Python instance of the MjWrapper");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return instance;
|
return std::move(instance);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!PyErr_Occurred()) {
|
if (!PyErr_Occurred()) {
|
||||||
@@ -117,7 +118,7 @@ static enable_if_not_const_t<Raw, py::object> MjWrapperLookup(Raw* ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Raw>
|
template <typename Raw>
|
||||||
static const py::object MjWrapperLookup(const Raw* ptr) {
|
static const py::handle MjWrapperLookup(const Raw* ptr) {
|
||||||
return MjWrapperLookup(const_cast<Raw*>(ptr));
|
return MjWrapperLookup(const_cast<Raw*>(ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user