py3: Remove PyStr_AsUTF8AndSize() compatability macro
authorAndrew Bartlett <abartlet@samba.org>
Fri, 7 Jun 2019 09:44:48 +0000 (11:44 +0200)
committerNoel Power <npower@samba.org>
Mon, 24 Jun 2019 17:24:27 +0000 (17:24 +0000)
We no longer need Samba to be py2/py3 compatible so we choose to return to the standard
function names.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Noel Power <noel.power@suse.com>
lib/ldb/pyldb.c
python/py3compat.h
source4/auth/pyauth.c
source4/librpc/ndr/py_misc.c

index 1fd0965b2f1d1d1944022f9ef984833b1b78698a..214f1d0d3dde6b4a951fbb5212b87c0c31989d76 100644 (file)
@@ -85,7 +85,6 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 static PyTypeObject PyLdbBytesType;
 
 #if PY_MAJOR_VERSION >= 3
-#define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
 #define PyInt_FromLong PyLong_FromLong
 
 #define PYARG_STR_UNI "es"
@@ -104,16 +103,6 @@ static PyObject *PyLdbBytes_FromStringAndSize(const char *msg, int size)
 
 #define PYARG_STR_UNI "et"
 
-const char *PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr);
-const char *
-PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr)
-{
-       const char * ret = PyString_AsString(pystr);
-       if (ret == NULL)
-               return NULL;
-       *sizeptr = PyString_Size(pystr);
-       return ret;
-}
 #endif
 
 static PyObject *richcmp(int cmp_val, int op)
@@ -1150,7 +1139,7 @@ static const char **PyList_AsStrList(TALLOC_CTX *mem_ctx, PyObject *list,
                        talloc_free(ret);
                        return NULL;
                }
-               str = PyStr_AsUTF8AndSize(item, &size);
+               str = PyUnicode_AsUTF8AndSize(item, &size);
                if (str == NULL) {
                        talloc_free(ret);
                        return NULL;
@@ -3007,7 +2996,7 @@ static struct ldb_message_element *PyObject_AsMessageElement(
                        }
                        msg = _msg;
                } else {
-                       msg = PyStr_AsUTF8AndSize(set_obj, &size);
+                       msg = PyUnicode_AsUTF8AndSize(set_obj, &size);
                        if (msg == NULL) {
                                talloc_free(me);
                                return NULL;
@@ -3032,7 +3021,7 @@ static struct ldb_message_element *PyObject_AsMessageElement(
                                }
                                msg = _msg;
                        } else if (PyUnicode_Check(obj)) {
-                               msg = PyStr_AsUTF8AndSize(obj, &size);
+                               msg = PyUnicode_AsUTF8AndSize(obj, &size);
                                if (msg == NULL) {
                                        talloc_free(me);
                                        return NULL;
@@ -3216,7 +3205,7 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
                                result = PyBytes_AsStringAndSize(py_elements, &_msg, &size);
                                msg = _msg;
                        } else {
-                               msg = PyStr_AsUTF8AndSize(py_elements, &size);
+                               msg = PyUnicode_AsUTF8AndSize(py_elements, &size);
                                result = (msg == NULL) ? -1 : 0;
                        }
                        if (result != 0) {
@@ -3245,7 +3234,7 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
                                        result = PyBytes_AsStringAndSize(item, &_msg, &size);
                                        msg = _msg;
                                } else if (PyUnicode_Check(item)) {
-                                       msg = PyStr_AsUTF8AndSize(item, &size);
+                                       msg = PyUnicode_AsUTF8AndSize(item, &size);
                                        result = (msg == NULL) ? -1 : 0;
                                } else {
                                        PyErr_Format(PyExc_TypeError, 
index 4eca97513d1380430ffa7d0d0ad01a0a7703780c..d2adb24c6a210a2ad58624292e9dd55d743de3eb 100644 (file)
@@ -54,8 +54,6 @@
 
 /* Strings */
 
-#define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
-
 /* description of bytes objects */
 #define PY_DESC_PY3_BYTES "bytes"
 
index b4963e8eab6c70c60e921b8bf5ea2ca8ecde92f0..92fad3d20f0ef2fcd6f7bf5090ad2923beafd3d8 100644 (file)
@@ -305,7 +305,7 @@ static const char **PyList_AsStringList(TALLOC_CTX *mem_ctx, PyObject *list,
                        PyErr_Format(PyExc_TypeError, "%s should be strings", paramname);
                        return NULL;
                }
-               value = PyStr_AsUTF8AndSize(item, &size);
+               value = PyUnicode_AsUTF8AndSize(item, &size);
                if (value == NULL) {
                        talloc_free(ret);
                        return NULL;
index d3c91a46d6b51d8c911fb2535a94a375c5de186a..975235490ad8a306aa096708cb798f9db53c6277 100644 (file)
@@ -105,7 +105,7 @@ static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs)
                if (!IsPy3Bytes(str)) {
                        guid_val.data =
                                discard_const_p(uint8_t,
-                                               PyStr_AsUTF8AndSize(str, &_size));
+                                               PyUnicode_AsUTF8AndSize(str, &_size));
                } else {
                        guid_val.data =
                                discard_const_p(uint8_t,