]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/MgrPyModule: no need to keep pClass and pModule around
authorKefu Chai <kchai@redhat.com>
Wed, 26 Apr 2017 09:17:38 +0000 (17:17 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 26 Apr 2017 10:08:07 +0000 (18:08 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mgr/MgrPyModule.cc
src/mgr/MgrPyModule.h

index 2997be1b27b8bc955e99b552e32cfd03422b5670..078f7f503503f17bfae837265bd981c0f1791ae6 100644 (file)
@@ -50,7 +50,7 @@ std::string handle_pyerror()
 #define dout_prefix *_dout << "mgr " << __func__ << " "
 
 MgrPyModule::MgrPyModule(const std::string &module_name_)
-  : module_name(module_name_), pModule(nullptr), pClass(nullptr),
+  : module_name(module_name_),
     pClassInstance(nullptr)
 {}
 
@@ -60,8 +60,6 @@ MgrPyModule::~MgrPyModule()
   gstate = PyGILState_Ensure();
 
   Py_XDECREF(pClassInstance);
-  Py_XDECREF(pClass);
-  Py_XDECREF(pModule);
 
   PyGILState_Release(gstate);
 }
@@ -70,7 +68,7 @@ int MgrPyModule::load()
 {
   // Load the module
   PyObject *pName = PyString_FromString(module_name.c_str());
-  pModule = PyImport_Import(pName);
+  auto pModule = PyImport_Import(pName);
   Py_DECREF(pName);
   if (pModule == nullptr) {
     derr << "Module not found: '" << module_name << "'" << dendl;
@@ -79,7 +77,8 @@ int MgrPyModule::load()
 
   // Find the class
   // TODO: let them call it what they want instead of just 'Module'
-  pClass = PyObject_GetAttrString(pModule, (const char*)"Module");
+  auto pClass = PyObject_GetAttrString(pModule, (const char*)"Module");
+  Py_DECREF(pModule);
   if (pClass == nullptr) {
     derr << "Class not found in module '" << module_name << "'" << dendl;
     return -EINVAL;
@@ -91,6 +90,7 @@ int MgrPyModule::load()
   auto pyHandle = PyString_FromString(module_name.c_str());
   auto pArgs = PyTuple_Pack(1, pyHandle);
   pClassInstance = PyObject_CallObject(pClass, pArgs);
+  Py_DECREF(pClass);
   Py_DECREF(pyHandle);
   Py_DECREF(pArgs);
   if (pClassInstance == nullptr) {
index b466d1ac20f4824da4357d59949df2fe8ef94c28..7d91275eacb4b552de01f8b0a1142f87ad46a0b3 100644 (file)
@@ -43,8 +43,6 @@ class MgrPyModule
 {
 private:
   const std::string module_name;
-  PyObject *pModule;
-  PyObject *pClass;
   PyObject *pClassInstance;
 
   std::vector<ModuleCommand> commands;