{"flush", log_flush, METH_VARARGS, "flush"},
{nullptr, nullptr, 0, nullptr}
};
+
+#if PY_MAJOR_VERSION >= 3
+ static PyModuleDef ceph_logger_module = {
+ PyModuleDef_HEAD_INIT,
+ "ceph_logger",
+ nullptr,
+ -1,
+ log_methods,
+ };
+#endif
}
pMyThreadState.set(thread_state);
// Some python modules do not cope with an unpopulated argv, so lets
// fake one. This step also picks up site-packages into sys.path.
+#if PY_MAJOR_VERSION >= 3
+ const wchar_t *argv[] = {L"ceph-mgr"};
+ PySys_SetArgv(1, (wchar_t**)argv);
+#else
const char *argv[] = {"ceph-mgr"};
PySys_SetArgv(1, (char**)argv);
+#endif
if (g_conf->daemonize) {
- auto py_logger = Py_InitModule("ceph_logger", log_methods);
#if PY_MAJOR_VERSION >= 3
+ auto py_logger = PyModule_Create(&ceph_logger_module);
PySys_SetObject("stderr", py_logger);
PySys_SetObject("stdout", py_logger);
#else
+ auto py_logger = Py_InitModule("ceph_logger", log_methods);
PySys_SetObject(const_cast<char*>("stderr"), py_logger);
PySys_SetObject(const_cast<char*>("stdout"), py_logger);
#endif
}
// Configure sys.path to include mgr_module_path
- std::string sys_path = std::string(Py_GetPath()) + ":" + get_site_packages()
- + ":" + g_conf->get_val<std::string>("mgr_module_path");
- dout(10) << "Computed sys.path '" << sys_path << "'" << dendl;
-
+ string paths = (":" + get_site_packages() +
+ ":" + g_conf->get_val<std::string>("mgr_module_path"));
+#if PY_MAJOR_VERSION >= 3
+ wstring sys_path(Py_GetPath() + wstring(begin(paths), end(paths)));
+ PySys_SetPath(const_cast<wchar_t*>(sys_path.c_str()));
+ dout(10) << "Computed sys.path '"
+ << string(begin(sys_path), end(sys_path)) << "'" << dendl;
+#else
+ string sys_path(Py_GetPath() + paths);
PySys_SetPath(const_cast<char*>(sys_path.c_str()));
+ dout(10) << "Computed sys.path '" << sys_path << "'" << dendl;
+#endif
}
- PyMethodDef ModuleMethods[] = {
+ static PyMethodDef module_methods[] = {
{nullptr}
};
+#if PY_MAJOR_VERSION >= 3
+ static PyModuleDef ceph_module_def = {
+ PyModuleDef_HEAD_INIT,
+ "ceph_module",
+ nullptr,
+ -1,
+ module_methods,
+ };
+#endif
// Initialize module
- PyObject *ceph_module = Py_InitModule("ceph_module", ModuleMethods);
+#if PY_MAJOR_VERSION >= 3
+ PyObject *ceph_module = PyModule_Create(&ceph_module_def);
+#else
+ PyObject *ceph_module = Py_InitModule("ceph_module", module_methods);
+#endif
assert(ceph_module != nullptr);
auto load_class = [ceph_module](const char *name, PyTypeObject *type)
-#undef dout_prefix
-#define dout_prefix *_dout << "mgr " << __func__ << " "
-
int PyModuleRegistry::init(const MgrMap &map)
{
Mutex::Locker locker(lock);
config_prefix = std::string(g_conf->name.get_type_str()) + "/";
// Set up global python interpreter
+#if PY_MAJOR_VERSION >= 3
+#define WCHAR(s) L ## #s
+ Py_SetProgramName(const_cast<wchar_t*>(WCHAR(PYTHON_EXECUTABLE)));
+#undef WCHAR
+#else
Py_SetProgramName(const_cast<char*>(PYTHON_EXECUTABLE));
+#endif
Py_InitializeEx(0);
// Let CPython know that we will be calling it back from other
--- /dev/null
+#pragma once
+
+#include <Python.h>
+
+// 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 char* PyString_AsString(PyObject *string) {
+ return PyUnicode_AsUTF8(string);
+}
+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);
+}
+#endif