From aa1aac9dcd77fb6772743d589c3fc82700d9f194 Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Wed, 23 Jun 2021 10:44:37 +0800 Subject: [PATCH] fix bug about deallocating None (#33723) * fix bug about deallocating None, test=develop --- paddle/fluid/pybind/op_function_generator.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/pybind/op_function_generator.cc b/paddle/fluid/pybind/op_function_generator.cc index 619f14c30f1..b2205391a25 100644 --- a/paddle/fluid/pybind/op_function_generator.cc +++ b/paddle/fluid/pybind/op_function_generator.cc @@ -268,7 +268,7 @@ static PyObject * %s(PyObject *self, PyObject *args, PyObject *kwargs) imperative::GetCurrentTracer()->TraceOp("%s", ins, outs, attrs, {%s}); PyEval_RestoreThread(tstate); tstate = nullptr; - return %s; + %s } catch(...) { if (tstate) { @@ -488,13 +488,13 @@ std::string GenerateOpFunctionsBody( viwe_input_name, viwe_output_name); } if (outs_num == 0) { - return_str = "Py_None"; + return_str = "Py_INCREF(Py_None);\n return Py_None;"; } else if (outs_num == 1) { - return_str = "MakeReturnPyObject(" + return_str + ")"; + return_str = "return MakeReturnPyObject(" + return_str + ");"; } else { - return_str = "MakeReturnPyObject(" + + return_str = "return MakeReturnPyObject(" + paddle::string::Sprintf(RETURN_TUPLE_TEMPLATE, return_str) + - ")"; + ");"; } std::string function_args = ""; if (input_args == "") { -- GitLab