Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:eeich
ganglia
python-modules-Fix-PyInt_-and-PyString_-for-Pyt...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File python-modules-Fix-PyInt_-and-PyString_-for-Python-3.patch of Package ganglia
From: Egbert Eich <eich@suse.com> Date: Fri Feb 23 12:33:47 2018 +0100 Subject: python-modules: Fix PyInt_ and PyString_ for Python 3 Patch-mainline: never Git-commit: 8ca81536e093341b04e3c5e0e2631fbd04298ae1 References: Kept code backward compatible and still readable by avoiding Signed-off-by: Egbert Eich <eich@suse.com> --- gmond/modules/python/mod_python.c | 117 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 6 deletions(-) diff --git a/gmond/modules/python/mod_python.c b/gmond/modules/python/mod_python.c index ed5a401..393ee07 100644 --- a/gmond/modules/python/mod_python.c +++ b/gmond/modules/python/mod_python.c @@ -51,11 +51,15 @@ /* * Backward compatibility for 2.1 to 2.4 */ -#if PY_MINOR_VERSION < 5 -#define Py_ssize_t int -#if PY_MINOR_VERSION < 3 -#define PyInt_AsUnsignedLongMask PyInt_AsLong -#endif +#if PY_MAJOR_VERSION < 3 +# if PY_MINOR_VERSION < 5 +# define Py_ssize_t int +# if PY_MINOR_VERSION < 3 +# define PyInt_AsUnsignedLongMask PyInt_AsLong +# endif +# endif +#else +#define PY3K #endif /* @@ -120,6 +124,7 @@ get_python_string_value(PyObject* dv, char* bfr, int len) long v = PyLong_AsLong(dv); snprintf(bfr, len, "%ld", v); } +#ifndef PY3K else if (PyInt_Check(dv)) { long v = PyInt_AsLong(dv); snprintf(bfr, len, "%ld", v); @@ -128,6 +133,16 @@ get_python_string_value(PyObject* dv, char* bfr, int len) char* v = PyString_AsString(dv); snprintf(bfr, len, "%s", v); } +#else + else if (PyUnicode_Check(dv)) { + char* v = PyUnicode_AsUTF8(dv); + snprintf(bfr, len, "%ls", v); + } + else if (PyByteArray_Check(dv)) { + char* v = PyByteArray_AsString(dv); + snprintf(bfr, len, "%s", v); + } +#endif else if (PyFloat_Check(dv)) { double v = PyFloat_AsDouble(dv); snprintf(bfr, len, "%f", v); @@ -166,7 +181,10 @@ int get_python_uint_value(PyObject* dv, unsigned int* pint) { int cc = 1; - if (PyInt_Check(dv) || PyLong_Check(dv)) { +#ifndef PY3K + if ( + PyInt_Check(dv) || + PyLong_Check(dv)) { unsigned long v = PyInt_AsUnsignedLongMask(dv); *pint = (unsigned int)v; } @@ -181,6 +199,35 @@ get_python_uint_value(PyObject* dv, unsigned int* pint) else *pint = (unsigned int)tid; } +#else + if ( + PyLong_Check(dv)) { + unsigned long v = PyLong_AsUnsignedLongMask(dv); + *pint = (unsigned int)v; + } + else if (PyUnicode_Check(dv)) { + /* Convert from string to int */ + unsigned long tid; + char *endptr; + char* p = PyUnicode_AsUTF8(dv); + tid = strtoul(p, &endptr, 10); + if(endptr == p || *endptr) + cc = -1; /* Invalid numeric format */ + else + *pint = (unsigned int)tid; + } + else if (PyByteArray_Check(dv)) { + /* Convert from string to int */ + unsigned long tid; + char *endptr; + char* p = PyByteArray_AsString(dv); + tid = strtoul(p, &endptr, 10); + if(endptr == p || *endptr) + cc = -1; /* Invalid numeric format */ + else + *pint = (unsigned int)tid; + } +#endif else { cc = -1; /* Don't know how to convert this */ } @@ -195,6 +242,7 @@ get_python_int_value(PyObject* dv, int* pint) long v = PyLong_AsLong(dv); *pint = (int)v; } +#ifndef PY3K else if (PyInt_Check(dv)) { long v = PyInt_AsLong(dv); *pint = (int)v; @@ -210,6 +258,30 @@ get_python_int_value(PyObject* dv, int* pint) else *pint = (int)tid; } +#else + else if (PyUnicode_Check(dv)) { + /* Convert from string to int */ + long tid; + char *endptr; + char* p = PyUnicode_AsUTF8(dv); + tid = strtol(p, &endptr, 10); + if(endptr == p || *endptr) + cc = -1; /* Invalid numeric format */ + else + *pint = (int)tid; + } + else if (PyByteArray_Check(dv)) { + /* Convert from string to int */ + long tid; + char *endptr; + char* p = PyByteArray_AsString(dv); + tid = strtol(p, &endptr, 10); + if(endptr == p || *endptr) + cc = -1; /* Invalid numeric format */ + else + *pint = (int)tid; + } +#endif else { cc = -1; /* Don't know how to convert this */ } @@ -247,6 +319,7 @@ get_python_float_value(PyObject* dv, double* pnum) long v = PyLong_AsLong(dv); *pnum = (double)v; } +#ifndef PY3K else if (PyInt_Check(dv)) { long v = PyInt_AsLong(dv); *pnum = (double)v; @@ -262,6 +335,30 @@ get_python_float_value(PyObject* dv, double* pnum) else *pnum = tid; } +#else + else if (PyUnicode_Check(dv)) { + /* Convert from string to int */ + double tid; + char *endptr; + char* p = PyUnicode_AsUTF8(dv); + tid = strtod(p, &endptr); + if(endptr == p || *endptr) + cc = -1; /* Invalid format for double */ + else + *pnum = tid; + } + else if (PyByteArray_Check(dv)) { + /* Convert from string to int */ + double tid; + char *endptr; + char* p = PyByteArray_AsString(dv); + tid = strtod(p, &endptr); + if(endptr == p || *endptr) + cc = -1; /* Invalid format for double */ + else + *pnum = tid; + } +#endif else { cc = -1; /* Don't know how to convert this */ } @@ -518,7 +615,11 @@ static PyObject* build_params_dict(cfg_t *pymodule) param = cfg_getnsec(pymodule, "param", k); name = apr_pstrdup(pool, param->title); value = apr_pstrdup(pool, cfg_getstr(param, "value")); +#ifdef PY3K + pyvalue = PyUnicode_FromString(value); +#else pyvalue = PyString_FromString(value); +#endif if (name && pyvalue) { PyDict_SetItemString(params_dict, name, pyvalue); Py_DECREF(pyvalue); @@ -587,7 +688,11 @@ static int pyth_metric_init (apr_pool_t *p) Py_InitModule("ganglia", GangliaMethods); PyObject *sys_path = PySys_GetObject("path"); +#ifdef PY3K + PyObject *addpath = PyUnicode_FromString(path); +#else PyObject *addpath = PyString_FromString(path); +#endif PyList_Append(sys_path, addpath); PyEval_InitThreads();
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor