From: Amit Bawer <abawer(a)redhat.com>
This is part of patches for making numerical API compatible
with Py3 and Py2.
All use-cases of this function assigns value to uint64_t vars
so we switch to respective AsUnsignedLongLongMask APIs.
Current status:
- Py2: build and testing should be Okay.
- Py3: build will fail for missing numerical APIs.
Signed-off-by: Amit Bawer <abawer(a)redhat.com>
---
python/sanlock.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 108a7b8..9109032 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -69,10 +69,20 @@ __set_exception(int en, char *msg)
PyErr_SetObject(py_exception, exc_tuple);
Py_DECREF(exc_tuple);
}
}
+static uint64_t
+pyinteger_as_unsigned_long_long_mask(PyObject *obj)
+{
+#if PY_MAJOR_VERSION == 2
+ return PyInt_AsUnsignedLongLongMask(obj);
+#else
+ return PyLong_AsUnsignedLongLongMask(obj);
+#endif
+}
+
/*
* Returns NULL-terminated representation of the contents of obj.
*
* obj must be a string object (py2) or Unicode object (py3), otherwise returns NULL
* and raises TypeError.[1][2]
@@ -1090,11 +1100,11 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject
*keywds)
}
/* prepare the resource version */
if (version != Py_None) {
res->flags |= SANLK_RES_LVER;
- res->lver = PyInt_AsUnsignedLongMask(version);
+ res->lver = pyinteger_as_unsigned_long_long_mask(version);
if (res->lver == -1) {
__set_exception(EINVAL, "Unable to convert the version value");
goto exit_fail;
}
}
@@ -1206,11 +1216,11 @@ py_request(PyObject *self __unused, PyObject *args, PyObject
*keywds)
/* prepare the resource version */
if (version == Py_None) {
flags = SANLK_REQUEST_NEXT_LVER;
} else {
res->flags |= SANLK_RES_LVER;
- res->lver = PyInt_AsUnsignedLongMask(version);
+ res->lver = pyinteger_as_unsigned_long_long_mask(version);
if (res->lver == -1) {
__set_exception(EINVAL, "Unable to convert the version value");
goto exit_fail;
}
}
--
2.17.2