]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr: drop the compatibility with python2
authorKefu Chai <kchai@redhat.com>
Wed, 18 Dec 2019 11:03:29 +0000 (19:03 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 19 Dec 2019 03:52:56 +0000 (11:52 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
17 files changed:
src/mgr/ActivePyModule.cc
src/mgr/ActivePyModules.cc
src/mgr/BaseMgrModule.cc
src/mgr/BaseMgrStandbyModule.cc
src/mgr/BaseMgrStandbyModule.h
src/mgr/Mgr.h
src/mgr/PyFormatter.cc
src/mgr/PyFormatter.h
src/mgr/PyModule.cc
src/mgr/PyModuleRunner.cc
src/mgr/PyOSDMap.cc
src/mgr/PyOSDMap.h
src/mgr/PyUtil.cc
src/mgr/PyUtil.h
src/mgr/PythonCompat.h [deleted file]
src/mgr/StandbyPyModules.cc
src/mgr/StandbyPyModules.h

index 78704f8769123665ce6acf88235e34eb15c0fac8..2110dea5725297e42856741e45524e32cdb0307a 100644 (file)
@@ -34,7 +34,7 @@ int ActivePyModule::load(ActivePyModules *py_modules)
   // with us in logging etc.
   auto pThisPtr = PyCapsule_New(this, nullptr, nullptr);
   auto pPyModules = PyCapsule_New(py_modules, nullptr, nullptr);
-  auto pModuleName = PyString_FromString(get_name().c_str());
+  auto pModuleName = PyUnicode_FromString(get_name().c_str());
   auto pArgs = PyTuple_Pack(3, pModuleName, pPyModules, pThisPtr);
 
   pClassInstance = PyObject_CallObject(py_module->pClass, pArgs);
@@ -230,9 +230,9 @@ int ActivePyModule::handle_command(
               "returned wrong type!" << dendl;
       r = -EINVAL;
     } else {
-      r = PyInt_AsLong(PyTuple_GetItem(pResult, 0));
-      *ds << PyString_AsString(PyTuple_GetItem(pResult, 1));
-      *ss << PyString_AsString(PyTuple_GetItem(pResult, 2));
+      r = PyLong_AsLong(PyTuple_GetItem(pResult, 0));
+      *ds << PyUnicode_AsUTF8(PyTuple_GetItem(pResult, 1));
+      *ss << PyUnicode_AsUTF8(PyTuple_GetItem(pResult, 2));
     }
 
     Py_DECREF(pResult);
index 4d38a6e1e0f21f857a2ad3628227dcaa42a0184b..5595a2e66077eec22f1d0ac84348f51edbbe7ccb 100644 (file)
@@ -183,7 +183,7 @@ PyObject *ActivePyModules::get_python(const std::string &what)
       osd_map.crush->encode(rdata, CEPH_FEATURES_SUPPORTED_DEFAULT);
     });
     std::string crush_text = rdata.to_str();
-    return PyString_FromString(crush_text.c_str());
+    return PyUnicode_FromString(crush_text.c_str());
   } else if (what.substr(0, 7) == "osd_map") {
     cluster_state.with_osdmap([&f, &what, &tstate](const OSDMap &osd_map){
       PyEval_RestoreThread(tstate);
index 7d603d45a6e3c6b401708d85ead694914a7e7dfe..baa8426a42a57c9655daa1b8d8391684024bb00c 100644 (file)
@@ -91,9 +91,9 @@ public:
       auto set_fn = PyObject_GetAttrString(python_completion, "complete");
       ceph_assert(set_fn != nullptr);
 
-      auto pyR = PyInt_FromLong(r);
-      auto pyOutBl = PyString_FromString(outbl.to_str().c_str());
-      auto pyOutS = PyString_FromString(outs.c_str());
+      auto pyR = PyLong_FromLong(r);
+      auto pyOutBl = PyUnicode_FromString(outbl.to_str().c_str());
+      auto pyOutS = PyUnicode_FromString(outs.c_str());
       auto args = PyTuple_Pack(3, pyR, pyOutBl, pyOutS);
       Py_DECREF(pyR);
       Py_DECREF(pyOutBl);
@@ -287,26 +287,27 @@ ceph_set_health_checks(BaseMgrModule *self, PyObject *args)
       }
       string ks(k);
       if (ks == "severity") {
-       if (auto [vs, valid] = PyString_ToString(v); !valid) {
+       if (!PyUnicode_Check(v)) {
          derr << __func__ << " check " << check_name
               << " severity value not string" << dendl;
          continue;
-       } else if (vs == "warning") {
+       }
+       if (const string vs = PyUnicode_AsUTF8(v); vs == "warning") {
          severity = HEALTH_WARN;
        } else if (vs == "error") {
          severity = HEALTH_ERR;
        }
       } else if (ks == "summary") {
-       if (auto [vs, valid] = PyString_ToString(v); !valid) {
+       if (!PyUnicode_Check(v)) {
          derr << __func__ << " check " << check_name
               << " summary value not [unicode] string" << dendl;
          continue;
        } else {
-         summary = std::move(vs);
+         summary = PyUnicode_AsUTF8(v);
        }
       } else if (ks == "count") {
-       if (PyInt_Check(v)) {
-         count = PyInt_AsLong(v);
+       if (PyLong_Check(v)) {
+         count = PyLong_AsLong(v);
        } else {
          derr << __func__ << " check " << check_name
               << " count value not int" << dendl;
@@ -320,12 +321,12 @@ ceph_set_health_checks(BaseMgrModule *self, PyObject *args)
        }
        for (int k = 0; k < PyList_Size(v); ++k) {
          PyObject *di = PyList_GET_ITEM(v, k);
-         if (auto [vs, valid] = PyString_ToString(di); !valid) {
+         if (!PyUnicode_Check(di)) {
            derr << __func__ << " check " << check_name
                 << " detail item " << k << " not a [unicode] string" << dendl;
            continue;
          } else {
-           detail.push_back(std::move(vs));
+           detail.push_back(PyUnicode_AsUTF8(di));
          }
        }
       } else {
@@ -383,7 +384,7 @@ ceph_get_server(BaseMgrModule *self, PyObject *args)
 static PyObject*
 ceph_get_mgr_id(BaseMgrModule *self, PyObject *args)
 {
-  return PyString_FromString(g_conf()->name.get_id().c_str());
+  return PyUnicode_FromString(g_conf()->name.get_id().c_str());
 }
 
 static PyObject*
@@ -477,7 +478,7 @@ ceph_store_get(BaseMgrModule *self, PyObject *args)
       what, &value);
   if (found) {
     dout(10) << "ceph_store_get " << what << " found: " << value.c_str() << dendl;
-    return PyString_FromString(value.c_str());
+    return PyUnicode_FromString(value.c_str());
   } else {
     dout(4) << "ceph_store_get " << what << " not found " << dendl;
     Py_RETURN_NONE;
@@ -570,13 +571,13 @@ ceph_cluster_log(BaseMgrModule *self, PyObject *args)
 static PyObject *
 ceph_get_version(BaseMgrModule *self, PyObject *args)
 {
-  return PyString_FromString(pretty_version_to_str().c_str());
+  return PyUnicode_FromString(pretty_version_to_str().c_str());
 }
 
 static PyObject *
 ceph_get_release_name(BaseMgrModule *self, PyObject *args)
 {
-  return PyString_FromString(ceph_release_to_str());
+  return PyUnicode_FromString(ceph_release_to_str());
 }
 
 static PyObject *
@@ -849,12 +850,12 @@ ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args)
             Py_RETURN_NONE;
           }
           if (param_name == NAME_SUB_KEY_TYPE) {
-            if (!PyString_Check(param_value)) {
+            if (!PyUnicode_Check(param_value)) {
               derr << __func__ << " query " << query_param_name << " item " << j
                    << " contains invalid param " << param_name << dendl;
               Py_RETURN_NONE;
             }
-            auto type = PyString_AsString(param_value);
+            auto type = PyUnicode_AsUTF8(param_value);
             auto it = sub_key_types.find(type);
             if (it == sub_key_types.end()) {
               derr << __func__ << " query " << query_param_name << " item " << j
@@ -863,12 +864,12 @@ ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args)
             }
             d.type = it->second;
           } else if (param_name == NAME_SUB_KEY_REGEX) {
-            if (!PyString_Check(param_value)) {
+            if (!PyUnicode_Check(param_value)) {
               derr << __func__ << " query " << query_param_name << " item " << j
                    << " contains invalid param " << param_name << dendl;
               Py_RETURN_NONE;
             }
-            d.regex_str = PyString_AsString(param_value);
+            d.regex_str = PyUnicode_AsUTF8(param_value);
             try {
               d.regex = d.regex_str.c_str();
             } catch (const std::regex_error& e) {
@@ -903,12 +904,12 @@ ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args)
       }
       for (int j = 0; j < PyList_Size(query_param_val); j++) {
         PyObject *py_type = PyList_GET_ITEM(query_param_val, j);
-        if (!PyString_Check(py_type)) {
+        if (!PyUnicode_Check(py_type)) {
           derr << __func__ << " query " << query_param_name << " item " << j
                << " not a string" << dendl;
           Py_RETURN_NONE;
         }
-        auto type = PyString_AsString(py_type);
+        auto type = PyUnicode_AsUTF8(py_type);
         auto it = counter_types.find(type);
         if (it == counter_types.end()) {
           derr << __func__ << " query " << query_param_name << " item " << type
@@ -939,12 +940,12 @@ ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args)
         }
 
         if (limit_param_name == NAME_LIMIT_ORDER_BY) {
-          if (!PyString_Check(limit_param_val)) {
+          if (!PyUnicode_Check(limit_param_val)) {
             derr << __func__ << " " << limit_param_name << " not a string"
                  << dendl;
             Py_RETURN_NONE;
           }
-          auto order_by = PyString_AsString(limit_param_val);
+          auto order_by = PyUnicode_AsUTF8(limit_param_val);
           auto it = counter_types.find(order_by);
           if (it == counter_types.end()) {
             derr << __func__ << " limit " << limit_param_name
@@ -953,12 +954,12 @@ ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args)
           }
           limit->order_by = it->second;
         } else if (limit_param_name == NAME_LIMIT_MAX_COUNT) {
-          if (!PyInt_Check(limit_param_val)) {
+          if (!PyLong_Check(limit_param_val)) {
             derr << __func__ << " " << limit_param_name << " not an int"
                  << dendl;
             Py_RETURN_NONE;
           }
-          limit->max_count = PyInt_AsLong(limit_param_val);
+          limit->max_count = PyLong_AsLong(limit_param_val);
         } else {
           derr << __func__ << " unknown limit param: " << limit_param_name
                << dendl;
index 59f97d8172b9f98df1c5aff3aad613680df5af6a..84c9b79f2f7bab51d3045235021873e259ffeea3 100644 (file)
@@ -57,7 +57,7 @@ BaseMgrStandbyModule_init(BaseMgrStandbyModule *self, PyObject *args, PyObject *
 static PyObject*
 ceph_get_mgr_id(BaseMgrStandbyModule *self, PyObject *args)
 {
-  return PyString_FromString(g_conf()->name.get_id().c_str());
+  return PyUnicode_FromString(g_conf()->name.get_id().c_str());
 }
 
 static PyObject*
@@ -110,7 +110,7 @@ ceph_option_get(BaseMgrStandbyModule *self, PyObject *args)
   int r = g_conf().get_val(string(what), &value);
   if (r >= 0) {
     dout(10) << "ceph_option_get " << what << " found: " << value << dendl;
-    return PyString_FromString(value.c_str());
+    return PyUnicode_FromString(value.c_str());
   } else {
     dout(4) << "ceph_option_get " << what << " not found " << dendl;
     Py_RETURN_NONE;
@@ -136,7 +136,7 @@ ceph_store_get(BaseMgrStandbyModule *self, PyObject *args)
 
   if (found) {
     dout(10) << "ceph_store_get " << what << " found: " << value.c_str() << dendl;
-    return PyString_FromString(value.c_str());
+    return PyUnicode_FromString(value.c_str());
   } else {
     dout(4) << "ceph_store_get " << what << " not found " << dendl;
     Py_RETURN_NONE;
@@ -146,7 +146,7 @@ ceph_store_get(BaseMgrStandbyModule *self, PyObject *args)
 static PyObject*
 ceph_get_active_uri(BaseMgrStandbyModule *self, PyObject *args)
 {
-  return PyString_FromString(self->this_module->get_active_uri().c_str());
+  return PyUnicode_FromString(self->this_module->get_active_uri().c_str());
 }
 
 static PyObject*
index c4cf267304c94a212fc65f348f6cce6e98e76e15..82bda9105b8c3ed06e6ce22ae6d45db8d7ed8f22 100644 (file)
@@ -1,7 +1,6 @@
-
 #pragma once
 
-#include "PythonCompat.h"
+#include <Python.h>
 
 extern PyTypeObject BaseMgrStandbyModuleType;
 
index d38a75cac931f8c7f492050b70715a8d6cf04173..9a712edcc7648448b999d8d54285943a45be55c0 100644 (file)
@@ -15,7 +15,7 @@
 #define CEPH_MGR_H_
 
 // Python.h comes first because otherwise it clobbers ceph's assert
-#include "PythonCompat.h"
+#include <Python.h>
 
 #include "mds/FSMap.h"
 #include "messages/MFSMap.h"
index a90674734eac767738d063a6152487d79885fa72..5dc64a1f4e5dea4bb61289b6e342faa33717ac80 100644 (file)
@@ -57,7 +57,7 @@ void PyFormatter::dump_float(const char *name, double d)
 
 void PyFormatter::dump_string(const char *name, std::string_view s)
 {
-  dump_pyobject(name, PyString_FromString(s.data()));
+  dump_pyobject(name, PyUnicode_FromString(s.data()));
 }
 
 void PyFormatter::dump_bool(const char *name, bool b)
@@ -90,7 +90,7 @@ void PyFormatter::dump_format_va(const char *name, const char *ns, bool quoted,
   char buf[LARGE_SIZE];
   vsnprintf(buf, LARGE_SIZE, fmt, ap);
 
-  dump_pyobject(name, PyString_FromString(buf));
+  dump_pyobject(name, PyUnicode_FromString(buf));
 }
 
 /**
@@ -102,7 +102,7 @@ void PyFormatter::dump_pyobject(const char *name, PyObject *p)
     PyList_Append(cursor, p);
     Py_DECREF(p);
   } else if (PyDict_Check(cursor)) {
-    PyObject *key = PyString_FromString(name);
+    PyObject *key = PyUnicode_FromString(name);
     PyDict_SetItem(cursor, key, p);
     Py_DECREF(key);
     Py_DECREF(p);
@@ -118,7 +118,7 @@ void PyFormatter::finish_pending_streams()
     cursor = i->cursor;
     dump_pyobject(
         i->name.c_str(),
-        PyString_FromString(i->stream.str().c_str()));
+        PyUnicode_FromString(i->stream.str().c_str()));
     cursor = tmp_cur;
   }
 
index e30ae9f054ab372fa3dd50aefaa2940f13b05501..e7503cc153998ed897ed9aa46da930a996b86b83 100644 (file)
@@ -18,7 +18,7 @@
 #define PY_FORMATTER_H_
 
 // Python.h comes first because otherwise it clobbers ceph's assert
-#include "PythonCompat.h"
+#include <Python.h>
 
 #include <stack>
 #include <string>
index 30df62e75fb05b8e68c0c2a6ea287645d9592b17..004325a3c6f5a0144b0703c596f2c3825baaa6e5 100644 (file)
@@ -54,7 +54,7 @@ std::string handle_pyerror()
           // returning only the exception string value
           PyObject *name_attr = PyObject_GetAttrString(exc, "__name__");
           std::stringstream ss;
-          ss << PyString_AsString(name_attr) << ": " << PyString_AsString(val);
+          ss << PyUnicode_AsUTF8(name_attr) << ": " << PyUnicode_AsUTF8(val);
           Py_XDECREF(name_attr);
           return ss.str();
         }
@@ -67,7 +67,7 @@ std::string handle_pyerror()
           // returning only the exception string value
           PyObject *name_attr = PyObject_GetAttrString(exc, "__name__");
           std::stringstream ss;
-          ss << PyString_AsString(name_attr) << ": " << PyString_AsString(val);
+          ss << PyUnicode_AsUTF8(name_attr) << ": " << PyUnicode_AsUTF8(val);
           Py_XDECREF(name_attr);
           return ss.str();
         }
@@ -87,7 +87,7 @@ std::string peek_pyerror()
   ceph_assert(ptype);
   ceph_assert(pvalue);
   PyObject *pvalue_str = PyObject_Str(pvalue);
-  std::string exc_msg = PyString_AsString(pvalue_str);
+  std::string exc_msg = PyUnicode_AsUTF8(pvalue_str);
   Py_DECREF(pvalue_str);
   PyErr_Restore(ptype, pvalue, ptraceback);
 
@@ -202,7 +202,7 @@ std::string PyModule::get_site_packages()
       if (i != 0) {
         site_packages << ":";
       }
-      site_packages << PyString_AsString(PyList_GetItem(site_packages_list, i));
+      site_packages << PyUnicode_AsUTF8(PyList_GetItem(site_packages_list, i));
     }
 
     Py_DECREF(site_packages_list);
@@ -231,13 +231,13 @@ std::string PyModule::get_site_packages()
     auto n = PyList_Size(sys_path);
     bool first = true;
     for (Py_ssize_t i = 0; i < n; ++i) {
-      dout(1) << "  " << PyString_AsString(PyList_GetItem(sys_path, i)) << dendl;
+      dout(1) << "  " << PyUnicode_AsUTF8(PyList_GetItem(sys_path, i)) << dendl;
       if (first) {
         first = false;
       } else {
         site_packages << ":";
       }
-      site_packages << PyString_AsString(PyList_GetItem(sys_path, i));
+      site_packages << PyUnicode_AsUTF8(PyList_GetItem(sys_path, i));
     }
 
     Py_DECREF(sys_path);
@@ -401,7 +401,7 @@ int PyModule::load(PyThreadState *pMainThreadState)
       if (PyTuple_Check(pCanRunTuple) && PyTuple_Size(pCanRunTuple) == 2) {
         PyObject *pCanRun = PyTuple_GetItem(pCanRunTuple, 0);
         PyObject *can_run_str = PyTuple_GetItem(pCanRunTuple, 1);
-        if (!PyBool_Check(pCanRun) || !PyString_Check(can_run_str)) {
+        if (!PyBool_Check(pCanRun) || !PyUnicode_Check(can_run_str)) {
           derr << "Module " << get_name()
                << " returned wrong type in can_run" << dendl;
           error_string = "wrong type returned from can_run";
@@ -409,7 +409,7 @@ int PyModule::load(PyThreadState *pMainThreadState)
         } else {
           can_run = (pCanRun == Py_True);
           if (!can_run) {
-            error_string = PyString_AsString(can_run_str);
+            error_string = PyUnicode_AsUTF8(can_run_str);
             dout(4) << "Module " << get_name()
                     << " reported that it cannot run: "
                     << error_string << dendl;
@@ -491,22 +491,22 @@ int PyModule::load_commands()
 
     PyObject *pCmd = PyDict_GetItemString(pCommand, "cmd");
     ceph_assert(pCmd != nullptr);
-    command.cmdstring = PyString_AsString(pCmd);
+    command.cmdstring = PyUnicode_AsUTF8(pCmd);
 
     dout(20) << "loaded command " << command.cmdstring << dendl;
 
     PyObject *pDesc = PyDict_GetItemString(pCommand, "desc");
     ceph_assert(pDesc != nullptr);
-    command.helpstring = PyString_AsString(pDesc);
+    command.helpstring = PyUnicode_AsUTF8(pDesc);
 
     PyObject *pPerm = PyDict_GetItemString(pCommand, "perm");
     ceph_assert(pPerm != nullptr);
-    command.perm = PyString_AsString(pPerm);
+    command.perm = PyUnicode_AsUTF8(pPerm);
 
     command.polling = false;
     PyObject *pPoll = PyDict_GetItemString(pCommand, "poll");
     if (pPoll) {
-      std::string polling = PyString_AsString(pPoll);
+      std::string polling = PyUnicode_AsUTF8(pPoll);
       if (boost::iequals(polling, "true")) {
         command.polling = true;
       }
@@ -531,40 +531,40 @@ int PyModule::load_options()
     PyObject *p;
     p = PyDict_GetItemString(pOption, "name");
     ceph_assert(p != nullptr);
-    option.name = PyString_AsString(p);
+    option.name = PyUnicode_AsUTF8(p);
     option.type = Option::TYPE_STR;
     p = PyDict_GetItemString(pOption, "type");
-    if (p && PyObject_TypeCheck(p, &PyString_Type)) {
-      std::string s = PyString_AsString(p);
+    if (p && PyObject_TypeCheck(p, &PyUnicode_Type)) {
+      std::string s = PyUnicode_AsUTF8(p);
       int t = Option::str_to_type(s);
       if (t >= 0) {
        option.type = t;
       }
     }
     p = PyDict_GetItemString(pOption, "desc");
-    if (p && PyObject_TypeCheck(p, &PyString_Type)) {
-      option.desc = PyString_AsString(p);
+    if (p && PyObject_TypeCheck(p, &PyUnicode_Type)) {
+      option.desc = PyUnicode_AsUTF8(p);
     }
     p = PyDict_GetItemString(pOption, "long_desc");
-    if (p && PyObject_TypeCheck(p, &PyString_Type)) {
-      option.long_desc = PyString_AsString(p);
+    if (p && PyObject_TypeCheck(p, &PyUnicode_Type)) {
+      option.long_desc = PyUnicode_AsUTF8(p);
     }
     p = PyDict_GetItemString(pOption, "default");
     if (p) {
       auto q = PyObject_Str(p);
-      option.default_value = PyString_AsString(q);
+      option.default_value = PyUnicode_AsUTF8(q);
       Py_DECREF(q);
     }
     p = PyDict_GetItemString(pOption, "min");
     if (p) {
       auto q = PyObject_Str(p);
-      option.min = PyString_AsString(q);
+      option.min = PyUnicode_AsUTF8(q);
       Py_DECREF(q);
     }
     p = PyDict_GetItemString(pOption, "max");
     if (p) {
       auto q = PyObject_Str(p);
-      option.max = PyString_AsString(q);
+      option.max = PyUnicode_AsUTF8(q);
       Py_DECREF(q);
     }
     p = PyDict_GetItemString(pOption, "enum_allowed");
@@ -573,7 +573,7 @@ int PyModule::load_options()
        auto q = PyList_GetItem(p, i);
        if (q) {
          auto r = PyObject_Str(q);
-         option.enum_allowed.insert(PyString_AsString(r));
+         option.enum_allowed.insert(PyUnicode_AsUTF8(r));
          Py_DECREF(r);
        }
       }
@@ -582,8 +582,8 @@ int PyModule::load_options()
     if (p && PyObject_TypeCheck(p, &PyList_Type)) {
       for (unsigned i = 0; i < PyList_Size(p); ++i) {
        auto q = PyList_GetItem(p, i);
-       if (q && PyObject_TypeCheck(q, &PyString_Type)) {
-         option.see_also.insert(PyString_AsString(q));
+       if (q && PyObject_TypeCheck(q, &PyUnicode_Type)) {
+         option.see_also.insert(PyUnicode_AsUTF8(q));
        }
       }
     }
@@ -591,8 +591,8 @@ int PyModule::load_options()
     if (p && PyObject_TypeCheck(p, &PyList_Type)) {
       for (unsigned i = 0; i < PyList_Size(p); ++i) {
        auto q = PyList_GetItem(p, i);
-       if (q && PyObject_TypeCheck(q, &PyString_Type)) {
-         option.tags.insert(PyString_AsString(q));
+       if (q && PyObject_TypeCheck(q, &PyUnicode_Type)) {
+         option.tags.insert(PyUnicode_AsUTF8(q));
        }
       }
     }
@@ -630,7 +630,7 @@ PyObject *PyModule::get_typed_option_value(const std::string& name,
   if (p != options.end()) {
     return get_python_typed_option_value((Option::type_t)p->second.type, value);
   }
-  return PyString_FromString(value.c_str());
+  return PyUnicode_FromString(value.c_str());
 }
 
 int PyModule::load_subclass_of(const char* base_class, PyObject** py_class)
@@ -675,7 +675,7 @@ int PyModule::load_subclass_of(const char* base_class, PyObject** py_class)
     if (PyObject_RichCompareBool(value, mgr_module_type, Py_EQ)) {
       continue;
     }
-    auto class_name = PyString_AsString(key);
+    auto class_name = PyUnicode_AsUTF8(key);
     if (*py_class) {
       derr << __func__ << ": ignoring '"
           << module_name << "." << class_name << "'"
index c5408bd9da2761b980c72094aa44f3c07778481c..e27f7f40551327eb536d7dcf21e4e45892be62f6 100644 (file)
@@ -13,7 +13,7 @@
 
 
 // Python.h comes first because otherwise it clobbers ceph's assert
-#include "PythonCompat.h"
+#include <Python.h>
 
 #include "PyModule.h"
 
index 681546a8f7f8a567dde8c31ef2ca989a6d542e15..a4715d67352166032806296f0916a926259a66fc 100644 (file)
@@ -35,12 +35,12 @@ typedef struct {
 
 static PyObject *osdmap_get_epoch(BasePyOSDMap *self, PyObject *obj)
 {
-  return PyInt_FromLong(self->osdmap->get_epoch());
+  return PyLong_FromLong(self->osdmap->get_epoch());
 }
 
 static PyObject *osdmap_get_crush_version(BasePyOSDMap* self, PyObject *obj)
 {
-  return PyInt_FromLong(self->osdmap->get_crush_version());
+  return PyLong_FromLong(self->osdmap->get_crush_version());
 }
 
 static PyObject *osdmap_dump(BasePyOSDMap* self, PyObject *obj)
@@ -128,14 +128,14 @@ static PyObject *osdmap_calc_pg_upmaps(BasePyOSDMap* self, PyObject *args)
   set<int64_t> pools;
   for (auto i = 0; i < PyList_Size(pool_list); ++i) {
     PyObject *pool_name = PyList_GET_ITEM(pool_list, i);
-    if (!PyString_Check(pool_name)) {
+    if (!PyUnicode_Check(pool_name)) {
       derr << __func__ << " " << pool_name << " not a string" << dendl;
       return nullptr;
     }
     auto pool_id = self->osdmap->lookup_pg_pool_name(
-      PyString_AsString(pool_name));
+      PyUnicode_AsUTF8(pool_name));
     if (pool_id < 0) {
-      derr << __func__ << " pool '" << PyString_AsString(pool_name)
+      derr << __func__ << " pool '" << PyUnicode_AsUTF8(pool_name)
            << "' does not exist" << dendl;
       return nullptr;
     }
@@ -155,7 +155,7 @@ static PyObject *osdmap_calc_pg_upmaps(BasePyOSDMap* self, PyObject *args)
                                 incobj->inc);
   PyEval_RestoreThread(tstate);
   dout(10) << __func__ << " r = " << r << dendl;
-  return PyInt_FromLong(r);
+  return PyLong_FromLong(r);
 }
 
 static PyObject *osdmap_map_pool_pgs_up(BasePyOSDMap* self, PyObject *args)
@@ -377,7 +377,7 @@ BasePyOSDMapIncremental_dealloc(BasePyOSDMapIncremental *self)
 static PyObject *osdmap_inc_get_epoch(BasePyOSDMapIncremental *self,
     PyObject *obj)
 {
-  return PyInt_FromLong(self->inc->epoch);
+  return PyLong_FromLong(self->inc->epoch);
 }
 
 static PyObject *osdmap_inc_dump(BasePyOSDMapIncremental *self,
@@ -560,7 +560,7 @@ static PyObject *crush_get_item_name(BasePyCRUSH *self, PyObject *args)
   if (!self->crush->item_exists(item)) {
     Py_RETURN_NONE;
   }
-  return PyString_FromString(self->crush->get_item_name(item));
+  return PyUnicode_FromString(self->crush->get_item_name(item));
 }
 
 static PyObject *crush_get_item_weight(BasePyCRUSH *self, PyObject *args)
index 9d737424913b896b570902396ba9f6af382a2d3b..2cc30dfe266691b77646d80850e2ae3ec86c9225 100644 (file)
@@ -3,11 +3,9 @@
 
 #pragma once
 
-#include <string>
-
-#include "PythonCompat.h"
-
+#include <Python.h>
 
+#include <string>
 
 extern PyTypeObject BasePyOSDMapType;
 extern PyTypeObject BasePyOSDMapIncrementalType;
index 04a3a5d1fa5258b2540c987fe974349d539c9db0..bfecdb35423091577c060263fa6a94ad1e79b5e9 100644 (file)
@@ -1,8 +1,9 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 
+#include <Python.h>
+
 #include "PyUtil.h"
-#include "PythonCompat.h"
 
 PyObject *get_python_typed_option_value(
   Option::type_t type,
@@ -12,12 +13,12 @@ PyObject *get_python_typed_option_value(
   case Option::TYPE_INT:
   case Option::TYPE_UINT:
   case Option::TYPE_SIZE:
-    return PyInt_FromString((char *)value.c_str(), nullptr, 0);
+    return PyLong_FromString((char *)value.c_str(), nullptr, 0);
   case Option::TYPE_SECS:
   case Option::TYPE_FLOAT:
     {
-      PyObject *s = PyString_FromString(value.c_str());
-      PyObject *f = PyFloat_FromString(s, nullptr);
+      PyObject *s = PyUnicode_FromString(value.c_str());
+      PyObject *f = PyFloat_FromString(s);
       Py_DECREF(s);
       return f;
     }
@@ -36,5 +37,5 @@ PyObject *get_python_typed_option_value(
   case Option::TYPE_UUID:
     break;
   }
-  return PyString_FromString(value.c_str());
+  return PyUnicode_FromString(value.c_str());
 }
index 3d8bc7b984fd1119aa321c967e7ceff3b7df7a80..188b3d28fc3be037fd61e47bf1a3e776942863fb 100644 (file)
@@ -5,7 +5,8 @@
 
 #include <string>
 
-#include "Python.h"
+#include <Python.h>
+
 #include "common/options.h"
 
 PyObject *get_python_typed_option_value(
diff --git a/src/mgr/PythonCompat.h b/src/mgr/PythonCompat.h
deleted file mode 100644 (file)
index 14f98ef..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-
-#pragma once
-
-#include <Python.h>
-#include <string>
-
-// Python's pyconfig-64.h conflicts with ceph's acconfig.h
-#undef HAVE_SYS_WAIT_H
-#undef HAVE_UNISTD_H
-#undef HAVE_UTIME_H
-#undef _POSIX_C_SOURCE
-#undef _XOPEN_SOURCE
-
-#if PY_MAJOR_VERSION >= 3
-inline PyObject* PyString_FromString(const char *v) {
-  return PyUnicode_FromFormat("%s", v);
-}
-inline const char* PyString_AsString(PyObject *string) {
-  return PyUnicode_AsUTF8(string);
-}
-inline int PyInt_Check(PyObject *o) {
-  return PyLong_Check(o);
-}
-inline long PyInt_AsLong(PyObject *io) {
-  return PyLong_AsLong(io);
-}
-inline PyObject* PyInt_FromLong(long ival) {
-  return PyLong_FromLong(ival);
-}
-inline int PyString_Check(PyObject *o) {
-  return PyUnicode_Check(o);
-}
-inline PyObject* PyFloat_FromString(PyObject *s, void *arg) {
-  return PyFloat_FromString(s);
-}
-inline PyObject* PyInt_FromString(const char *str, char **pend, int base) {
-  return PyLong_FromString(str, pend, base);
-}
-#define PyString_Type PyUnicode_Type
-#endif
-
-inline std::pair<std::string, bool> PyString_ToString(PyObject *o) {
-#if PY_MAJOR_VERSION >= 3
-  if (PyUnicode_Check(o)) {
-    return {PyUnicode_AsUTF8(o), true};
-  } else {
-    return {{}, false};
-  }
-#else
-  if (PyString_Check(o) || PyUnicode_Check(o)) {
-    return {PyString_AsString(o), true};
-  } else {
-    return {{}, false};
-  }
-#endif
-}
index cff60aded2ab61f258edc45a302c89a3b3cfd93c..62f063a14039f3abd104e275b7c50321f9dde94a 100644 (file)
@@ -109,7 +109,7 @@ int StandbyPyModule::load()
   // with us in logging etc.
   auto pThisPtr = PyCapsule_New(this, nullptr, nullptr);
   ceph_assert(pThisPtr != nullptr);
-  auto pModuleName = PyString_FromString(get_name().c_str());
+  auto pModuleName = PyUnicode_FromString(get_name().c_str());
   ceph_assert(pModuleName != nullptr);
   auto pArgs = PyTuple_Pack(2, pModuleName, pThisPtr);
   Py_DECREF(pThisPtr);
index d8d5e1a07ef615c5c9171c2f9fe7666813d93838..b434c917c7aec15b984f211b451a4ea26b832113 100644 (file)
 
 #pragma once
 
-#include "PythonCompat.h"
-
 #include <string>
 #include <map>
 
+#include <Python.h>
+
 #include "common/Thread.h"
 #include "common/ceph_mutex.h"