You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2015/12/02 20:38:15 UTC
svn commit: r1717670 -
/qpid/trunk/qpid/cpp/include/qpid/swig_python_typemaps.i
Author: gsim
Date: Wed Dec 2 19:38:15 2015
New Revision: 1717670
URL: http://svn.apache.org/viewvc?rev=1717670&view=rev
Log:
QPID-6858: update swig type mapping to compile with both python 2 and 3
Modified:
qpid/trunk/qpid/cpp/include/qpid/swig_python_typemaps.i
Modified: qpid/trunk/qpid/cpp/include/qpid/swig_python_typemaps.i
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/swig_python_typemaps.i?rev=1717670&r1=1717669&r2=1717670&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/swig_python_typemaps.i (original)
+++ qpid/trunk/qpid/cpp/include/qpid/swig_python_typemaps.i Wed Dec 2 19:38:15 2015
@@ -50,7 +50,11 @@ typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif
-
+#if PY_VERSION_HEX < 0x03000000
+#define PyLong_AS_LONG PyInt_AS_LONG
+#else
+#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
+#endif
PyObject* MapToPy(const qpid::types::Variant::Map*);
PyObject* ListToPy(const qpid::types::Variant::List*);
@@ -59,11 +63,11 @@ typedef int Py_ssize_t;
void PyToList(PyObject*, qpid::types::Variant::List*);
qpid::types::Variant PyToVariant(PyObject* value) {
- if (PyBool_Check(value)) return qpid::types::Variant(bool(PyInt_AS_LONG(value) ? true : false));
+ if (PyBool_Check(value)) return qpid::types::Variant(bool(PyLong_AS_LONG(value) ? true : false));
if (PyFloat_Check(value)) return qpid::types::Variant(PyFloat_AS_DOUBLE(value));
- if (PyInt_Check(value)) return qpid::types::Variant(int64_t(PyInt_AS_LONG(value)));
if (PyLong_Check(value)) return qpid::types::Variant(int64_t(PyLong_AsLongLong(value)));
- if (PyString_Check(value)) return qpid::types::Variant(std::string(PyString_AS_STRING(value)));
+ if (PyInt_Check(value)) return qpid::types::Variant(int64_t(PyLong_AS_LONG(value)));
+ if (PyString_Check(value)) return qpid::types::Variant(std::string(PyBytes_AS_STRING(value)));
if (PyUnicode_Check(value)) {
qpid::types::Variant v(std::string(PyUnicode_AS_DATA(value)));
v.setEncoding("utf8");
@@ -128,7 +132,7 @@ typedef int Py_ssize_t;
if (v->getEncoding() == "utf8")
result = PyUnicode_DecodeUTF8(val.c_str(), val.size(), NULL);
else
- result = PyString_FromStringAndSize(val.c_str(), val.size());
+ result = PyBytes_FromStringAndSize(val.c_str(), val.size());
break;
}
case qpid::types::VAR_MAP : {
@@ -161,7 +165,7 @@ typedef int Py_ssize_t;
PyObject* pyval = VariantToPy(&(iter->second));
if (pyval == 0)
return 0;
- PyDict_SetItem(result, PyString_FromStringAndSize(key.c_str(), key.size()), pyval);
+ PyDict_SetItem(result, PyBytes_FromStringAndSize(key.c_str(), key.size()), pyval);
}
return result;
}
@@ -189,7 +193,7 @@ typedef int Py_ssize_t;
PyObject* pArgs = PyTuple_New(0);
PyObject* pKw = PyDict_New();
- PyObject* pData = PyString_FromStringAndSize(
+ PyObject* pData = PyBytes_FromStringAndSize(
(const char*)(uuid->data()), 16);
PyDict_SetItemString(pKw, "bytes", pData);
@@ -210,7 +214,7 @@ typedef int Py_ssize_t;
PyObject *key;
PyObject *val;
while (PyDict_Next(obj, &iter, &key, &val))
- (*map)[std::string(PyString_AS_STRING(key))] = PyToVariant(val);
+ (*map)[std::string(PyBytes_AS_STRING(key))] = PyToVariant(val);
}
void PyToList(PyObject* obj, qpid::types::Variant::List* list) {
@@ -242,10 +246,10 @@ typedef int Py_ssize_t;
/* unsigned16 Convert from Python --> C */
%typemap(in) uint16_t {
- if (PyInt_Check($input)) {
- $1 = (uint16_t) PyInt_AsUnsignedLongMask($input);
- } else if (PyLong_Check($input)) {
+ if (PyLong_Check($input)) {
$1 = (uint16_t) PyLong_AsUnsignedLong($input);
+ } else if (PyInt_Check($input)) {
+ $1 = (uint16_t) PyInt_AsUnsignedLongMask($input);
} else {
SWIG_exception_fail(SWIG_ValueError, "unknown integer type");
}
@@ -259,10 +263,10 @@ typedef int Py_ssize_t;
/* signed32 Convert from Python --> C */
%typemap(in) int32_t {
- if (PyInt_Check($input)) {
- $1 = (int32_t) PyInt_AsLong($input);
- } else if (PyLong_Check($input)) {
+ if (PyLong_Check($input)) {
$1 = (int32_t) PyLong_AsLong($input);
+ } else if (PyInt_Check($input)) {
+ $1 = (int32_t) PyInt_AsLong($input);
} else {
SWIG_exception_fail(SWIG_ValueError, "unknown integer type");
}
@@ -280,7 +284,7 @@ typedef int Py_ssize_t;
if (PyLong_Check($input)) {
$1 = (uint64_t)PyLong_AsUnsignedLongLong($input);
} else if (PyInt_Check($input)) {
- $1 = (uint64_t)PyInt_AsUnsignedLongLongMask($input);
+ $1 = (uint64_t)PyLong_AS_LONG($input);
} else
%#endif
{
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org