[sanlock] 23/23: travis: Add python 3 builds
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit ad65e49c89c8d0b38ec88d18ac759cea263a1124
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Fri May 17 23:25:16 2019 +0300
travis: Add python 3 builds
All tests pass now with python 2 and 3, so we can start testing every
push with all python versions.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
.travis.yml | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 7c1749c..7b3fbe5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,12 @@
dist: xenial
+
language: python
-python: 2.7
+
+python:
+ - "2.7"
+ - "3.6"
+ - "3.7"
+ - "3.8-dev"
addons:
apt:
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 22/23: python: Use Py_BuildValue("i",
...) to create py integers
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit b227f1d3b63ca8d247554ff2d7cabe2121e9ff3a
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sat May 18 19:26:16 2019 +0300
python: Use Py_BuildValue("i", ...) to create py integers
Preserve compatibility for both Py3 and Py2.
- Py2: will construct new PyInt
- Py3: will construct new PyLong
Both Py versions will build and pass tests at this point.
---
python/sanlock.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 6477afe..b412b6a 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -273,7 +273,7 @@ py_register(PyObject *self __unused, PyObject *args)
return NULL;
}
- return PyInt_FromLong(sanlockfd);
+ return Py_BuildValue("i", sanlockfd);
}
/* get_alignment */
@@ -306,7 +306,7 @@ py_get_alignment(PyObject *self __unused, PyObject *args)
return NULL;
}
- return PyInt_FromLong(rv);
+ return Py_BuildValue("i", rv);
}
/* init_lockspace */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 21/23: python: Refactor build of dictionary entries for
py_read_resource
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit add27e4b3de78fa42ab25cb86bbe226730a50a31
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sat May 18 16:58:50 2019 +0300
python: Refactor build of dictionary entries for py_read_resource
Use Py_BuildValue("{...}",...) for creating dictionary information
for resource.
Using helper to determine the build value format:
- Py2: Handle lockspace and resource name as PyString with "s" format.
- Py3: Handle lockspace and resource name as PyBytes with "y" format.
Current status:
- Py2: will build and pass tests.
- Py3: build will fail for missing respective API calls.
---
python/sanlock.c | 37 +++++++++++--------------------------
1 file changed, 11 insertions(+), 26 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 5870081..6477afe 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -538,7 +538,7 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
long align = ALIGNMENT_1M;
const char *path;
struct sanlk_resource *rs;
- PyObject *rs_info = NULL, *rs_entry = NULL;
+ PyObject *rs_info = NULL;
static char *kwlist[] = {"path", "offset", "align", "sector", NULL};
@@ -582,31 +582,16 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* prepare the dictionary holding the information */
- if ((rs_info = PyDict_New()) == NULL)
- goto exit_fail;
-
- /* fill the dictionary information: lockspace */
- if ((rs_entry = PyString_FromString(rs->lockspace_name)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(rs_info, "lockspace", rs_entry);
- Py_DECREF(rs_entry);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: resource */
- if ((rs_entry = PyString_FromString(rs->name)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(rs_info, "resource", rs_entry);
- Py_DECREF(rs_entry);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: version */
- if ((rs_entry = PyLong_FromUnsignedLong(rs->lver)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(rs_info, "version", rs_entry);
- Py_DECREF(rs_entry);
- if (rv != 0)
+ rs_info = Py_BuildValue(
+#if PY_MAJOR_VERSION == 2
+ "{s:s,s:s,s:K}",
+#else
+ "{s:y,s:y,s:K}",
+#endif
+ "lockspace", rs->lockspace_name,
+ "resource", rs->name,
+ "version", rs->lver);
+ if (rs_info == NULL)
goto exit_fail;
/* success */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 20/23: python: Refactor build of dictionary entries for
py_read_lockspace
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit aafbc4d719ce3a2b87fa5326f062189f0b6ed9df
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sat May 18 16:40:01 2019 +0300
python: Refactor build of dictionary entries for py_read_lockspace
Use Py_BuildValue("{...}",...) for creating dictionary information
for lockspace.
Using helper to determine the build value format:
- Py2: Handle lockspace name as PyString with "s" format.
- Py3: Handle lockspace name as PyBytes with "y" format.
Current status:
- Py2: will build and pass tests.
- Py3: will fail to build for missing respective API calls.
---
python/sanlock.c | 37 ++++++++++++-------------------------
1 file changed, 12 insertions(+), 25 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index e4b1407..5870081 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -475,7 +475,7 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
uint32_t io_timeout = 0;
const char *path;
struct sanlk_lockspace ls;
- PyObject *ls_info = NULL, *ls_entry = NULL;
+ PyObject *ls_info = NULL;
static char *kwlist[] = {"path", "offset", "align", "sector", NULL};
@@ -508,33 +508,20 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
return NULL;
}
- /* prepare the dictionary holding the information */
- if ((ls_info = PyDict_New()) == NULL)
- goto exit_fail;
-
- /* fill the dictionary information: lockspace */
- if ((ls_entry = PyString_FromString(ls.name)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_info, "lockspace", ls_entry);
- Py_DECREF(ls_entry);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: iotimeout */
- if ((ls_entry = PyInt_FromLong(io_timeout)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_info, "iotimeout", ls_entry);
- Py_DECREF(ls_entry);
- if (rv != 0)
- goto exit_fail;
+ /* fill the information dictionary */
+ ls_info = Py_BuildValue(
+#if PY_MAJOR_VERSION == 2
+ "{s:s,s:I}",
+#else
+ "{s:y,s:I}",
+#endif
+ "lockspace", ls.name,
+ "iotimeout", io_timeout);
+ if (ls_info == NULL)
+ return NULL;
/* success */
return ls_info;
-
- /* failure */
-exit_fail:
- Py_XDECREF(ls_info);
- return NULL;
}
/* read_resource */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 19/23: python: Refactor build of dictionary entries for
py_get_lockspaces
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit ee2ac66782e926b62eb4740cd1f5f154f43928e9
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sat May 18 16:00:38 2019 +0300
python: Refactor build of dictionary entries for py_get_lockspaces
Use Py_BuildValue("{...}",...) for creating each dictionary entry
in lockspaces list.
Using helper for different path formats:
- Py2: will treat path as PyString using the "s" format.
- Py3: will treat path as PyBytes using the "y" format.
Current status:
- Py2: will build and pass tests.
- Py3: will fail to build for missing respective API calls.
---
python/sanlock.c | 55 ++++++++++++++-----------------------------------------
1 file changed, 14 insertions(+), 41 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 5d45b6a..e4b1407 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -878,7 +878,7 @@ py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv, i, lss_count;
struct sanlk_lockspace *lss = NULL;
- PyObject *ls_list = NULL, *ls_entry = NULL, *ls_value = NULL;
+ PyObject *ls_list = NULL, *ls_entry = NULL;
/* get all the lockspaces (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -895,47 +895,20 @@ py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject *keywds)
goto exit_fail;
for (i = 0; i < lss_count; i++) {
- if ((ls_entry = PyDict_New()) == NULL)
- goto exit_fail;
-
- /* fill the dictionary information: lockspace */
- if ((ls_value = PyString_FromString(lss[i].name)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "lockspace", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: host_id */
- if ((ls_value = PyInt_FromLong(lss[i].host_id)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "host_id", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: path */
- if ((ls_value = PyString_FromString(lss[i].host_id_disk.path)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "path", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
- goto exit_fail;
- /* fill the dictionary information: offset */
- if ((ls_value = PyInt_FromLong(lss[i].host_id_disk.offset)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "offset", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: flags */
- if ((ls_value = PyInt_FromLong(lss[i].flags)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "flags", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
+ /* fill the dictionary information */
+ ls_entry = Py_BuildValue(
+#if PY_MAJOR_VERSION == 2
+ "{s:s,s:K,s:s,s:K,s:I}",
+#else
+ "{s:y,s:K,s:s,s:K,s:I}",
+#endif
+ "lockspace", lss[i].name,
+ "host_id", lss[i].host_id,
+ "path", lss[i].host_id_disk.path,
+ "offset", lss[i].host_id_disk.offset,
+ "flags", lss[i].flags);
+ if (ls_entry == NULL)
goto exit_fail;
if (PyList_Append(ls_list, ls_entry) != 0)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 18/23: python: Simplify parse_resource() with
PyArg_ParseTuple
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 47eb3d9651b9c047d1ace2769a9f5daab3b4fb26
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Fri May 17 17:46:08 2019 +0300
python: Simplify parse_resource() with PyArg_ParseTuple
Replace complex manual parsing code with se PyArg_ParseTuple, avoiding
the backward compatibility issue, and greatly simplifying the code.
The test for invalid resource was modifed to test more types and
combinations, including incorrect number of items, and invalid types for
the path and offset.
Current status:
- Py2: will build and pass tests.
- Py3: will fail to build for missing respective API calls.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 42 ++++++++++++------------------------------
tests/python_test.py | 24 ++++++++++++++++--------
2 files changed, 28 insertions(+), 38 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index b4533f2..5d45b6a 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -124,44 +124,26 @@ __parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
res->num_disks = num_disks;
for (i = 0; i < num_disks; i++) {
- const char *p = NULL;
- PyObject *tuple, *path = NULL, *offset = NULL;
+ PyObject *disk;
+ const char *path;
+ uint64_t offset;
- tuple = PyList_GetItem(obj, i);
+ disk = PyList_GetItem(obj, i);
- if (PyTuple_Check(tuple)) {
- if (PyTuple_Size(tuple) != 2) {
- __set_exception(EINVAL, "Invalid resource tuple");
- goto exit_fail;
- }
-
- path = PyTuple_GetItem(tuple, 0);
- offset = PyTuple_GetItem(tuple, 1);
-
- p = pystring_as_cstring(path);
-
- if (!PyInt_Check(offset)) {
- __set_exception(EINVAL, "Invalid resource offset");
- goto exit_fail;
- }
- } else {
- /* handle invalid non-tuple resource input */
- set_value_error("invalid disk value: %s", tuple);
+ if (!PyTuple_Check(disk)) {
+ set_value_error("Invalid disk %s", disk);
goto exit_fail;
+
}
- if (p == NULL) {
- __set_exception(EINVAL, "Invalid resource path");
+ if (!PyArg_ParseTuple(disk, "sK", &path, &offset)) {
+ /* Override the error since it confusing in this context. */
+ set_value_error("Invalid disk %s", disk);
goto exit_fail;
}
- strncpy(res->disks[i].path, p, SANLK_PATH_LEN - 1);
-
- if (offset == NULL) {
- res->disks[i].offset = 0;
- } else {
- res->disks[i].offset = PyInt_AsLong(offset);
- }
+ strncpy(res->disks[i].path, path, SANLK_PATH_LEN - 1);
+ res->disks[i].offset = offset;
}
*res_ret = res;
diff --git a/tests/python_test.py b/tests/python_test.py
index a24990d..cfbdf9c 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -454,16 +454,24 @@ def test_write_resource_invalid_align_sector(
"ls_name", "res_name", disks, align=align, sector=sector)
-(a)pytest.mark.parametrize("resource", [
- "invalid resource tuple",
- b"invalid resource tuple",
+(a)pytest.mark.parametrize("disk", [
+ # Not a tuple - unicode and bytes:
+ "not a tuple",
+ b"not a tuple",
u'\u05e9\u05dc\u05d5\u05dd',
- b"\xd7\x90"
+ b"\xd7\x90",
+ # Tuple with incorrect length:
+ (),
+ ("path",),
+ ("path", 0, "extra"),
+ # Tuple with invalid content:
+ (0, "path"),
+ ("path", "not an offset"),
])
-def test_write_resource_invalid_path(tmpdir, sanlock_daemon, resource):
- # Test parsing a resource which is not a list of tuples
- disks = [resource]
+def test_write_resource_invalid_disk(tmpdir, sanlock_daemon, disk):
+ # Test parsing disks list with invalid content.
+ disks = [disk]
with pytest.raises(ValueError) as e:
sanlock.write_resource("ls_name", "res_name", disks)
- assert repr(resource) in str(e.value)
+ assert repr(disk) in str(e.value)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 17/23: python: Refactor build of dictionary entries for
hosts_to_list
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit af2d588dcb8a5921e4fca71e63363fadbb0cea0a
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Fri May 17 14:27:47 2019 +0300
python: Refactor build of dictionary entries for hosts_to_list
Use Py_BuildValue("{...}",...) for creating each dictionary entry
in hosts list.
Current status:
- Py2: will build and pass tests.
- Py3: will fail to build for missing respective API calls.
---
python/sanlock.c | 53 +++++++++++------------------------------------------
1 file changed, 11 insertions(+), 42 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 9109032..b4533f2 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -235,55 +235,24 @@ set_value_error(const char* format, PyObject* obj)
static PyObject *
__hosts_to_list(struct sanlk_host *hss, int hss_count)
{
- int i, rv;
- PyObject *ls_list = NULL, *ls_entry = NULL, *ls_value = NULL;
+ int i;
+ PyObject *ls_list = NULL, *ls_entry = NULL;
/* prepare the dictionary holding the information */
if ((ls_list = PyList_New(0)) == NULL)
goto exit_fail;
for (i = 0; i < hss_count; i++) {
- if ((ls_entry = PyDict_New()) == NULL)
- goto exit_fail;
-
- /* fill the dictionary information: host_id */
- if ((ls_value = PyInt_FromLong(hss[i].host_id)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "host_id", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: generation */
- if ((ls_value = PyInt_FromLong(hss[i].generation)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "generation", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
- goto exit_fail;
- /* fill the dictionary information: timestamp */
- if ((ls_value = PyInt_FromLong(hss[i].timestamp)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "timestamp", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: io_timeout */
- if ((ls_value = PyInt_FromLong(hss[i].io_timeout)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "io_timeout", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: flags */
- if ((ls_value = PyInt_FromLong(hss[i].flags)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_entry, "flags", ls_value);
- Py_DECREF(ls_value);
- if (rv != 0)
+ /* fill the dictionary information */
+ ls_entry = Py_BuildValue(
+ "{s:K,s:K,s:K,s:I,s:I}",
+ "host_id", hss[i].host_id,
+ "generation", hss[i].generation,
+ "timestamp", hss[i].timestamp,
+ "io_timeout", hss[i].io_timeout,
+ "flags", hss[i].flags);
+ if (ls_entry == NULL)
goto exit_fail;
if (PyList_Append(ls_list, ls_entry) != 0)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 16/23: python: Provide helper for Py{Int,
Long}_AsUnsignedLongLongMask
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 6640e5a8a91b41aa98d9532f86c5dc0e75fa4cdc
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Fri May 17 13:55:52 2019 +0300
python: Provide helper for Py{Int,Long}_AsUnsignedLongLongMask
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
@@ -71,6 +71,16 @@ __set_exception(int en, char *msg)
}
}
+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.
*
@@ -1092,7 +1102,7 @@ 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;
@@ -1208,7 +1218,7 @@ py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
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;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 15/23: python: Add pystring_as_cstring function
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 91e7b09e08c651855efbe7dea94d844437bec2e1
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Thu May 16 17:45:35 2019 +0300
python: Add pystring_as_cstring function
This helper allows accessing the inner bytes of
PyObject according to python version:
- Py2: String object
- Py3: Unicode object
This method is mostly used for paths as a temp
solution until we add the path convertor.
---
python/sanlock.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index aa3b9a8..108a7b8 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -71,6 +71,28 @@ __set_exception(int en, char *msg)
}
}
+/*
+ * 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]
+ *
+ * The returned pointer refers to the internal buffer of string, not a copy. It must not be
+ * deallocated, and the object must be kept alive as long as the retruned pointer is used.
+ * [1] https://docs.python.org/2/c-api/string.html#c.PyString_AsString
+ * [2] https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUTF8
+ *
+ */
+static const char*
+pystring_as_cstring(PyObject *obj)
+{
+#if PY_MAJOR_VERSION == 2
+ return PyString_AsString(obj);
+#else
+ return PyUnicode_AsUTF8(obj);
+#endif
+}
+
static int
__parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
{
@@ -92,7 +114,7 @@ __parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
res->num_disks = num_disks;
for (i = 0; i < num_disks; i++) {
- char *p = NULL;
+ const char *p = NULL;
PyObject *tuple, *path = NULL, *offset = NULL;
tuple = PyList_GetItem(obj, i);
@@ -106,7 +128,7 @@ __parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
path = PyTuple_GetItem(tuple, 0);
offset = PyTuple_GetItem(tuple, 1);
- p = PyString_AsString(path);
+ p = pystring_as_cstring(path);
if (!PyInt_Check(offset)) {
__set_exception(EINVAL, "Invalid resource offset");
@@ -195,7 +217,7 @@ set_value_error(const char* format, PyObject* obj)
const char* str_rep = "";
PyObject* rep = PyObject_Repr(obj);
if (rep)
- str_rep = PyString_AsString(rep);
+ str_rep = pystring_as_cstring(rep);
PyErr_Format(PyExc_ValueError, format, str_rep);
Py_XDECREF(rep);
}
@@ -1315,7 +1337,7 @@ py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds)
size_t arg_len;
item = PyList_GetItem(argslist, i);
- p = PyString_AsString(item);
+ p = pystring_as_cstring(item);
if (p == NULL) {
__set_exception(EINVAL, "Killpath argument not a string");
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 14/23: sanlock: Add module init for Python 3
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 9c7bb27f5a18c18f27a41a8d80082ebc39b4bf9b
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Thu May 16 15:38:11 2019 +0300
sanlock: Add module init for Python 3
At this stage building the sanlock module for Py3 is
expected to fail as we have modifications to be done
in upcoming patches to fill in missing Py3 API calls.
---
python/sanlock.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/python/sanlock.c b/python/sanlock.c
index 420b4ba..aa3b9a8 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1777,6 +1777,34 @@ module_init(PyObject* m)
return 0;
}
+#if PY_MAJOR_VERSION >= 3 /* Python 3 module init */
+
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ MODULE_NAME,
+ pydoc_sanlock,
+ -1,
+ sanlock_methods,
+};
+
+PyMODINIT_FUNC
+PyInit_sanlock(void)
+{
+ PyObject *m = PyModule_Create(&moduledef);
+
+ if (m == NULL)
+ return NULL;
+
+ if (module_init(m)) {
+ Py_DECREF(m);
+ return NULL;
+ }
+
+ return m;
+}
+
+#else /* Python 2 module init */
+
PyMODINIT_FUNC
initsanlock(void)
{
@@ -1792,4 +1820,6 @@ initsanlock(void)
module_init(m);
}
+#endif
+
/* vim: set expandtab shiftwidth=4 tabstop=4 : */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months