From 8bb866895c9260fa91143e892a2a77bb1d3fff4b Mon Sep 17 00:00:00 2001 From: Anthony Messina Date: Fri, 14 Dec 2018 16:32:04 -0600 Subject: [PATCH] app_python3: fix Python 3.7 deprecation warnings - check for PY_VERSION_HEX >= 0x03070000 --- src/modules/app_python3/app_python3_mod.c | 8 ++++++++ src/modules/app_python3/python_support.c | 16 ++++++++++++++++ src/modules/app_python3/python_support.h | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/src/modules/app_python3/app_python3_mod.c b/src/modules/app_python3/app_python3_mod.c index fcc42fa8991..464caadb35d 100644 --- a/src/modules/app_python3/app_python3_mod.c +++ b/src/modules/app_python3/app_python3_mod.c @@ -177,7 +177,11 @@ static int child_init(int rank) return 0; } _apy_process_rank = rank; +#if PY_VERSION_HEX >= 0x03070000 + PyOS_AfterFork_Child(); +#else PyOS_AfterFork(); +#endif if (cfg_child_init()) { return -1; } @@ -431,7 +435,11 @@ int apy_init_script(int rank) { PyObject *pFunc, *pArgs, *pValue, *pResult; int rval = -1; +#if PY_VERSION_HEX >= 0x03070000 + const char *classname; +#else char *classname; +#endif PyGILState_STATE gstate; diff --git a/src/modules/app_python3/python_support.c b/src/modules/app_python3/python_support.c index e7dc47d5261..0a8216f133f 100644 --- a/src/modules/app_python3/python_support.c +++ b/src/modules/app_python3/python_support.c @@ -234,10 +234,18 @@ static char *make_message(const char *fmt, va_list ap) return NULL; // shall not happened, but who knows ;) } +#if PY_VERSION_HEX >= 0x03070000 +const char *get_class_name(PyObject *y) +#else char *get_class_name(PyObject *y) +#endif { PyObject *p; +#if PY_VERSION_HEX >= 0x03070000 + const char *name; +#else char *name; +#endif p = PyObject_GetAttrString(y, "__name__"); if (p == NULL || p == Py_None) @@ -253,10 +261,18 @@ char *get_class_name(PyObject *y) } +#if PY_VERSION_HEX >= 0x03070000 +const char *get_instance_class_name(PyObject *y) +#else char *get_instance_class_name(PyObject *y) +#endif { PyObject *p, *n; +#if PY_VERSION_HEX >= 0x03070000 + const char *name; +#else char *name; +#endif n = PyObject_GetAttrString(y, "__class__"); if (n == NULL || n == Py_None) diff --git a/src/modules/app_python3/python_support.h b/src/modules/app_python3/python_support.h index 4d255641197..97c4e72e3e1 100644 --- a/src/modules/app_python3/python_support.h +++ b/src/modules/app_python3/python_support.h @@ -30,7 +30,12 @@ PyObject *format_exc_obj; void python_handle_exception(const char *, ...); PyObject *InitTracebackModule(void); +#if PY_VERSION_HEX >= 0x03070000 +const char *get_class_name(PyObject *); +const char *get_instance_class_name(PyObject *); +#else char *get_class_name(PyObject *); char *get_instance_class_name(PyObject *); +#endif #endif