This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit ddc424a4ade10e5c7c5e1305cbce23285d39d046
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 13:37:46 2019 +0300
python: Add PyBytes argument converter
Provide converter for parsing PyBytes argument with
no-regression behavior for Py2, allowing it to accept
unicode string object within ascii chars range.
Usage implications:
- Py2 : no-regression in accepting both PyBytes and
Unicodes within ascii range. TypeError will be
raised otherwise.
- Py3 : will accept only bytes. TypeError will be raised
otherwise.
---
python/sanlock.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/python/sanlock.c b/python/sanlock.c
index cec5c9b..86aec94 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -309,6 +309,43 @@ py_get_alignment(PyObject *self __unused, PyObject *args)
return Py_BuildValue("i", rv);
}
+/*
+ * Convert parsed arg into PyBytes object.
+ * For Python 2:
+ * If arg is unicode onject, ascii encode it to new PyBytes object passed by addr.
+ * If arg is a bytes object, inc its refcount and pass it in addr.
+ * Set TypeError and return 0 if arg doens not comply to any of the above.
+ * Return 1 on a successful conversion.
+ * For Python 3:
+ * If arg is a bytes object, inc its refcount and pass it in addr.
+ * Set TypeError and return 0 otherwise.
+ * Return 1 on a successful conversion.
+*/
+static int
+convert_to_pybytes(PyObject* arg, void *addr)
+{
+ assert(arg && "convert_to_pybytes called with NULL arg");
+
+#if PY_MAJOR_VERSION == 2
+ if (PyUnicode_Check(arg)) {
+ PyObject *bytes = PyUnicode_AsASCIIString(arg);
+ if (bytes == NULL)
+ return 0;
+ *(PyObject **)addr = bytes;
+ return 1;
+ }
+#endif
+
+ if (PyBytes_Check(arg)) {
+ Py_INCREF(arg);
+ *(PyObject **)addr = arg;
+ return 1;
+ }
+
+ set_error(PyExc_TypeError, "Argument type is not bytes: %s", arg);
+ return 0;
+}
+
/* init_lockspace */
PyDoc_STRVAR(pydoc_init_lockspace, "\
init_lockspace(lockspace, path, offset=0, max_hosts=0, num_hosts=0, \
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
Show replies by thread