From: Volker Theile Date: Fri, 1 Feb 2019 10:12:34 +0000 (+0100) Subject: mgr: Use Py_BuildValue to create the argument tuple X-Git-Tag: v14.1.0~220^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8210be29ad531d1d0339d59ed93a7e474dd67498;p=ceph-ci.git mgr: Use Py_BuildValue to create the argument tuple Reduce the complexity of the code by using the generic function, Py_BuildValue(), that can create most common objects from C values, directed by a format string. Signed-off-by: Volker Theile --- diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index eb0d24dfe18..15a250cf112 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -409,11 +409,8 @@ ceph_get_module_option(BaseMgrModule *self, PyObject *args) derr << "Invalid args!" << dendl; return nullptr; } - auto pKey = PyString_FromString(key); - auto pModule = PyString_FromString(self->this_module->get_name().c_str()); - auto pArgs = PyTuple_Pack(2, pModule, pKey); - Py_DECREF(pKey); - Py_DECREF(pModule); + auto pArgs = Py_BuildValue("(ss)", self->this_module->get_name().c_str(), + key); auto pResult = ceph_get_module_option_ex(self, pArgs); Py_DECREF(pArgs); return pResult; @@ -461,13 +458,8 @@ ceph_set_module_option(BaseMgrModule *self, PyObject *args) derr << "Invalid args!" << dendl; return nullptr; } - auto pModule = PyString_FromString(self->this_module->get_name().c_str()); - auto pKey = PyString_FromString(key); - auto pValue = PyString_FromString(value); - auto pArgs = PyTuple_Pack(3, pModule, pKey, pValue); - Py_DECREF(pValue); - Py_DECREF(pKey); - Py_DECREF(pModule); + auto pArgs = Py_BuildValue("(ssz)", self->this_module->get_name().c_str(), + key, value); auto pResult = ceph_set_module_option_ex(self, pArgs); Py_DECREF(pArgs); return pResult;