py3: Remove PyStr_AsUTF8() compatability macro
authorAndrew Bartlett <abartlet@samba.org>
Fri, 7 Jun 2019 09:21:15 +0000 (11:21 +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
lib/ldb/pyldb_util.c
lib/tevent/pytevent.c
python/py3compat.h

index 148faf5bc320a72501a3534fc86663815246d479..1fd0965b2f1d1d1944022f9ef984833b1b78698a 100644 (file)
@@ -85,7 +85,6 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 static PyTypeObject PyLdbBytesType;
 
 #if PY_MAJOR_VERSION >= 3
-#define PyStr_AsUTF8 PyUnicode_AsUTF8
 #define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
 #define PyInt_FromLong PyLong_FromLong
 
@@ -101,7 +100,6 @@ static PyObject *PyLdbBytes_FromStringAndSize(const char *msg, int size)
        return result;
 }
 #else
-#define PyStr_AsUTF8 PyString_AsString
 #define PyLdbBytes_FromStringAndSize PyString_FromStringAndSize
 
 #define PYARG_STR_UNI "et"
@@ -593,7 +591,7 @@ static PyObject *py_ldb_dn_repr(PyLdbDnObject *self)
                Py_DECREF(str);
                return NULL;
        }
-       result = PyUnicode_FromFormat("Dn(%s)", PyStr_AsUTF8(repr));
+       result = PyUnicode_FromFormat("Dn(%s)", PyUnicode_AsUTF8(repr));
        Py_DECREF(str);
        Py_DECREF(repr);
        return result;
@@ -1385,7 +1383,7 @@ static struct ldb_message *PyDict_AsMessage(TALLOC_CTX *mem_ctx,
        }
 
        while (PyDict_Next(py_obj, &dict_pos, &key, &value)) {
-               const char *key_str = PyStr_AsUTF8(key);
+               const char *key_str = PyUnicode_AsUTF8(key);
                if (ldb_attr_cmp(key_str, "dn") != 0) {
                        msg_el = PyObject_AsMessageElement(msg->elements, value,
                                                           mod_flags, key_str);
@@ -3295,9 +3293,9 @@ static PyObject *py_ldb_msg_element_repr(PyLdbMessageElementObject *self)
                PyObject *o = py_ldb_msg_element_find(self, i);
                repr = PyObject_Repr(o);
                if (element_str == NULL)
-                       element_str = talloc_strdup(NULL, PyStr_AsUTF8(repr));
+                       element_str = talloc_strdup(NULL, PyUnicode_AsUTF8(repr));
                else
-                       element_str = talloc_asprintf_append(element_str, ",%s", PyStr_AsUTF8(repr));
+                       element_str = talloc_asprintf_append(element_str, ",%s", PyUnicode_AsUTF8(repr));
                Py_DECREF(repr);
        }
 
@@ -3433,7 +3431,7 @@ static PyObject *py_ldb_msg_getitem_helper(PyLdbMessageObject *self, PyObject *p
        struct ldb_message_element *el;
        const char *name;
        struct ldb_message *msg = pyldb_Message_AsMessage(self);
-       name = PyStr_AsUTF8(py_name);
+       name = PyUnicode_AsUTF8(py_name);
        if (name == NULL) {
                PyErr_SetNone(PyExc_TypeError);
                return NULL;
@@ -3633,7 +3631,7 @@ static int py_ldb_msg_setitem(PyLdbMessageObject *self, PyObject *name, PyObject
 {
        const char *attr_name;
 
-       attr_name = PyStr_AsUTF8(name);
+       attr_name = PyUnicode_AsUTF8(name);
        if (attr_name == NULL) {
                PyErr_SetNone(PyExc_TypeError);
                return -1;
@@ -3777,7 +3775,7 @@ static PyObject *py_ldb_msg_repr(PyLdbMessageObject *self)
                Py_DECREF(dict);
                return NULL;
        }
-       ret = PyUnicode_FromFormat("Message(%s)", PyStr_AsUTF8(repr));
+       ret = PyUnicode_FromFormat("Message(%s)", PyUnicode_AsUTF8(repr));
        Py_DECREF(repr);
        Py_DECREF(dict);
        return ret;
@@ -4160,7 +4158,7 @@ static PyObject *py_register_module(PyObject *module, PyObject *args)
        }
 
        tmp = PyObject_GetAttrString(input, discard_const_p(char, "name"));
-       ops->name = talloc_strdup(ops, PyStr_AsUTF8(tmp));
+       ops->name = talloc_strdup(ops, PyUnicode_AsUTF8(tmp));
 
        Py_XDECREF(tmp);
        Py_INCREF(input);
index b153d878351fff0295730ba026a63d12a8fe182d..3889bfe4face5a23531ccf5053acaa3349ebfa61 100644 (file)
 
 static PyObject *ldb_module = NULL;
 
-#if PY_MAJOR_VERSION >= 3
-#define PyStr_AsUTF8 PyUnicode_AsUTF8
-#else
-#define PyStr_AsUTF8 PyString_AsString
-#endif
-
 /**
  * Find out PyTypeObject in ldb module for a given typename
  */
@@ -69,7 +63,7 @@ bool pyldb_Object_AsDn(TALLOC_CTX *mem_ctx, PyObject *object,
        PyTypeObject *PyLdb_Dn_Type;
 
        if (ldb_ctx != NULL && (PyUnicode_Check(object) || PyUnicode_Check(object))) {
-               odn = ldb_dn_new(mem_ctx, ldb_ctx, PyStr_AsUTF8(object));
+               odn = ldb_dn_new(mem_ctx, ldb_ctx, PyUnicode_AsUTF8(object));
                *dn = odn;
                return true;
        }
index c39769f2f7931eb4a0ad007468be737c5a242b22..99b27636b2824bc655f589626af365d9594205e3 100644 (file)
 #include <tevent.h>
 
 #if PY_MAJOR_VERSION >= 3
-#define PyStr_AsUTF8 PyUnicode_AsUTF8
 #define PyInt_FromLong PyLong_FromLong
-#else
-#define PyStr_AsUTF8 PyString_AsString
 #endif
 
 /* discard signature of 'func' in favour of 'target_sig' */
@@ -193,7 +190,7 @@ static PyObject *py_register_backend(PyObject *self, PyObject *args)
                return NULL;
        }
 
-       if (!tevent_register_backend(PyStr_AsUTF8(name), &py_tevent_ops)) { /* FIXME: What to do with backend */
+       if (!tevent_register_backend(PyUnicode_AsUTF8(name), &py_tevent_ops)) { /* FIXME: What to do with backend */
                PyErr_SetNone(PyExc_RuntimeError);
                Py_DECREF(name);
                return NULL;
index c9751a9754c7d5121a65d4a13c227506db5463ac..4eca97513d1380430ffa7d0d0ad01a0a7703780c 100644 (file)
@@ -54,7 +54,6 @@
 
 /* Strings */
 
-#define PyStr_AsUTF8 PyUnicode_AsUTF8
 #define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
 
 /* description of bytes objects */