]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: Use Py_BuildValue to create the argument tuple 26240/head
authorVolker Theile <vtheile@suse.com>
Fri, 1 Feb 2019 10:12:34 +0000 (11:12 +0100)
committerVolker Theile <vtheile@suse.com>
Fri, 1 Feb 2019 10:48:29 +0000 (11:48 +0100)
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 <vtheile@suse.com>
src/mgr/BaseMgrModule.cc

index eb0d24dfe18f87613a649af9a9c4389c989086e0..15a250cf112b43d52c84b5b6f58b0cbd2882bafc 100644 (file)
@@ -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;