From 84d34ddd49f0e14e44a8215e43e2486406f29161 Mon Sep 17 00:00:00 2001 From: Yuanle Liu Date: Thu, 13 Apr 2023 10:36:26 +0800 Subject: [PATCH] fix bug only on win (#52839) --- paddle/fluid/inference/api/analysis_predictor.cc | 3 +-- paddle/fluid/pybind/eager_utils.cc | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/inference/api/analysis_predictor.cc b/paddle/fluid/inference/api/analysis_predictor.cc index 790c32b31e1..d718ab936b5 100644 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -1241,8 +1241,7 @@ bool AnalysisPredictor::GetFetch(std::vector *outputs, for (size_t i = 0; i < fetches_.size(); ++i) { auto const &name = idx2fetches_[i]; auto &t = framework::GetVariableTensor(*scope, name); - (*outputs)[i] = - std::move(paddle::Tensor(std::make_shared(t), name)); + (*outputs)[i] = paddle::Tensor(std::make_shared(t), name); } return true; } diff --git a/paddle/fluid/pybind/eager_utils.cc b/paddle/fluid/pybind/eager_utils.cc index 93030c9138f..b7ecd196ca2 100644 --- a/paddle/fluid/pybind/eager_utils.cc +++ b/paddle/fluid/pybind/eager_utils.cc @@ -770,11 +770,15 @@ PyObject* ToPyObject(const std::vector>& value) { PyObject* ToPyObject(const std::vector& value, bool return_py_none_if_not_initialize) { - // NOTE(liuyuanle): I encountered a bug(access violation) in windows. ref to - // https://stackoverflow.com/questions/55598839/how-to-fix-access-violation-error-when-returning-pyobject-from-c-function-usin +// NOTE(liuyuanle): I encountered a bug(access violation) in windows. ref to +// https://stackoverflow.com/questions/55598839/how-to-fix-access-violation-error-when-returning-pyobject-from-c-function-usin +#ifdef _WIN32 PyGILState_STATE gstate = PyGILState_Ensure(); +#endif PyObject* result = PyList_New((Py_ssize_t)value.size()); +#ifdef _WIN32 PyGILState_Release(gstate); +#endif for (size_t i = 0; i < value.size(); i++) { if (!value[i].initialized() && return_py_none_if_not_initialize) { -- GitLab