// 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);
"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);
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);
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);
}
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;
}
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 {
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*
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;
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 *
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
}
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) {
}
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
}
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
}
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;
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*
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;
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;
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*
-
#pragma once
-#include "PythonCompat.h"
+#include <Python.h>
extern PyTypeObject BaseMgrStandbyModuleType;
#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"
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)
char buf[LARGE_SIZE];
vsnprintf(buf, LARGE_SIZE, fmt, ap);
- dump_pyobject(name, PyString_FromString(buf));
+ dump_pyobject(name, PyUnicode_FromString(buf));
}
/**
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);
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;
}
#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>
// 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();
}
// 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();
}
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);
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);
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);
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";
} 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;
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;
}
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");
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);
}
}
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));
}
}
}
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));
}
}
}
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)
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 << "'"
// Python.h comes first because otherwise it clobbers ceph's assert
-#include "PythonCompat.h"
+#include <Python.h>
#include "PyModule.h"
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)
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;
}
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)
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,
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)
#pragma once
-#include <string>
-
-#include "PythonCompat.h"
-
+#include <Python.h>
+#include <string>
extern PyTypeObject BasePyOSDMapType;
extern PyTypeObject BasePyOSDMapIncrementalType;
// -*- 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,
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;
}
case Option::TYPE_UUID:
break;
}
- return PyString_FromString(value.c_str());
+ return PyUnicode_FromString(value.c_str());
}
#include <string>
-#include "Python.h"
+#include <Python.h>
+
#include "common/options.h"
PyObject *get_python_typed_option_value(
+++ /dev/null
-// -*- 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
-}
// 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);
#pragma once
-#include "PythonCompat.h"
-
#include <string>
#include <map>
+#include <Python.h>
+
#include "common/Thread.h"
#include "common/ceph_mutex.h"