py3: Remove PyStr_AsString() compatability macro
authorAndrew Bartlett <abartlet@samba.org>
Fri, 7 Jun 2019 09:16:25 +0000 (11:16 +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>
libcli/nbt/pynbt.c
python/py3compat.h
source3/passdb/py_passdb.c
source4/auth/gensec/pygensec.c
source4/dsdb/pydsdb.c
source4/lib/registry/pyregistry.c
source4/librpc/rpc/pyrpc.c
source4/param/provision.c
source4/param/pyparam.c
source4/param/pyparam_util.c

index bcc98b78722e49d4b1ec3d2c9211e86a71ad1130..c440ec933c47279826e516bf5ead4196e1c1630f 100644 (file)
@@ -58,7 +58,7 @@ static PyObject *py_nbt_node_init(PyTypeObject *self, PyObject *args, PyObject *
 static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, uint16_t *dest_port)
 {
        if (PyUnicode_Check(obj) || PyUnicode_Check(obj)) {
-               *dest_addr = PyStr_AsString(obj);
+               *dest_addr = PyUnicode_AsUTF8(obj);
                *dest_port = NBT_NAME_SERVICE_PORT;
                return true;
        }
@@ -74,7 +74,7 @@ static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, u
                        return false;
                }
 
-               *dest_addr = PyStr_AsString(obj);
+               *dest_addr = PyUnicode_AsUTF8(obj);
 
                if (PyTuple_Size(obj) == 1) {
                        *dest_port = NBT_NAME_SERVICE_PORT;
@@ -96,7 +96,7 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *name_socke
 {
        if (PyTuple_Check(obj)) {
                if (PyTuple_Size(obj) == 2) {
-                       name->name = PyStr_AsString(PyTuple_GetItem(obj, 0));
+                       name->name = PyUnicode_AsUTF8(PyTuple_GetItem(obj, 0));
                        if (name->name == NULL) {
                                goto err;
                        }
@@ -107,11 +107,11 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *name_socke
                        name->scope = NULL;
                        return true;
                } else if (PyTuple_Size(obj) == 3) {
-                       name->name = PyStr_AsString(PyTuple_GetItem(obj, 0));
+                       name->name = PyUnicode_AsUTF8(PyTuple_GetItem(obj, 0));
                        if (name->name == NULL) {
                                goto err;
                        }
-                       name->scope = PyStr_AsString(PyTuple_GetItem(obj, 1));
+                       name->scope = PyUnicode_AsUTF8(PyTuple_GetItem(obj, 1));
                        if (name->scope == NULL) {
                                goto err;
                        }
@@ -128,7 +128,7 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *name_socke
 
        if (PyUnicode_Check(obj) || PyUnicode_Check(obj)) {
                /* FIXME: Parse string to be able to interpret things like RHONWYN<02> ? */
-               name->name = PyStr_AsString(obj);
+               name->name = PyUnicode_AsUTF8(obj);
                if (name->name == NULL) {
                        goto err;
                }
index 2db77d1b1ddb547a651f488bef9ba0e0551218cd..c9751a9754c7d5121a65d4a13c227506db5463ac 100644 (file)
@@ -54,8 +54,6 @@
 
 /* Strings */
 
-#define PyStr_AsString PyUnicode_AsUTF8
-
 #define PyStr_AsUTF8 PyUnicode_AsUTF8
 #define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
 
index 0c0f1be50557af720a070db93d1012cc23c9391d..f7e80c473976a87b06f75746652aa44d20538ce3 100644 (file)
@@ -250,7 +250,7 @@ static int py_samu_set_username(PyObject *obj, PyObject *value, void *closure)
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_username(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_username(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -281,7 +281,7 @@ static int py_samu_set_domain(PyObject *obj, PyObject *value, void *closure)
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_domain(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_domain(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -312,7 +312,7 @@ static int py_samu_set_nt_username(PyObject *obj, PyObject *value, void *closure
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_nt_username(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_nt_username(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -343,7 +343,7 @@ static int py_samu_set_full_name(PyObject *obj, PyObject *value, void *closure)
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_fullname(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_fullname(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -374,7 +374,7 @@ static int py_samu_set_home_dir(PyObject *obj, PyObject *value, void *closure)
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_homedir(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_homedir(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -405,7 +405,7 @@ static int py_samu_set_dir_drive(PyObject *obj, PyObject *value, void *closure)
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_dir_drive(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_dir_drive(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -436,7 +436,7 @@ static int py_samu_set_logon_script(PyObject *obj, PyObject *value, void *closur
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_logon_script(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_logon_script(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -467,7 +467,7 @@ static int py_samu_set_profile_path(PyObject *obj, PyObject *value, void *closur
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_profile_path(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_profile_path(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -498,7 +498,7 @@ static int py_samu_set_acct_desc(PyObject *obj, PyObject *value, void *closure)
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_acct_desc(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_acct_desc(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -529,7 +529,7 @@ static int py_samu_set_workstations(PyObject *obj, PyObject *value, void *closur
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_workstations(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_workstations(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -560,7 +560,7 @@ static int py_samu_set_comment(PyObject *obj, PyObject *value, void *closure)
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_comment(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_comment(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -591,7 +591,7 @@ static int py_samu_set_munged_dial(PyObject *obj, PyObject *value, void *closure
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
        PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
-       if (!pdb_set_munged_dial(sam_acct, PyStr_AsString(value), PDB_CHANGED)) {
+       if (!pdb_set_munged_dial(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
                talloc_free(frame);
                return -1;
        }
@@ -805,7 +805,7 @@ static int py_samu_set_plaintext_passwd(PyObject *obj, PyObject *value, void *cl
        TALLOC_CTX *frame = talloc_stackframe();
        struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
 
-       if (!pdb_set_plaintext_passwd(sam_acct, PyStr_AsString(value))) {
+       if (!pdb_set_plaintext_passwd(sam_acct, PyUnicode_AsUTF8(value))) {
                talloc_free(frame);
                return -1;
        }
@@ -1361,7 +1361,7 @@ static int py_groupmap_set_nt_name(PyObject *obj, PyObject *value, void *closure
        if (value == Py_None) {
                fstrcpy(group_map->nt_name, NULL);
        } else {
-               fstrcpy(group_map->nt_name, PyStr_AsString(value));
+               fstrcpy(group_map->nt_name, PyUnicode_AsUTF8(value));
        }
        talloc_free(frame);
        return 0;
@@ -1391,7 +1391,7 @@ static int py_groupmap_set_comment(PyObject *obj, PyObject *value, void *closure
        if (value == Py_None) {
                fstrcpy(group_map->comment, NULL);
        } else {
-               fstrcpy(group_map->comment, PyStr_AsString(value));
+               fstrcpy(group_map->comment, PyUnicode_AsUTF8(value));
        }
        talloc_free(frame);
        return 0;
@@ -2430,13 +2430,13 @@ static PyObject *py_pdb_set_aliasinfo(PyObject *self, PyObject *args)
 
        alias_sid = pytalloc_get_ptr(py_alias_sid);
 
-       alias_info.acct_name = talloc_strdup(frame, PyStr_AsString(PyDict_GetItemString(py_alias_info, "acct_name")));
+       alias_info.acct_name = talloc_strdup(frame, PyUnicode_AsUTF8(PyDict_GetItemString(py_alias_info, "acct_name")));
        if (alias_info.acct_name == NULL) {
                PyErr_Format(py_pdb_error, "Unable to allocate memory");
                talloc_free(frame);
                return NULL;
        }
-       alias_info.acct_desc = talloc_strdup(frame, PyStr_AsString(PyDict_GetItemString(py_alias_info, "acct_desc")));
+       alias_info.acct_desc = talloc_strdup(frame, PyUnicode_AsUTF8(PyDict_GetItemString(py_alias_info, "acct_desc")));
        if (alias_info.acct_desc == NULL) {
                PyErr_Format(py_pdb_error, "Unable to allocate memory");
                talloc_free(frame);
@@ -3303,10 +3303,10 @@ static PyObject *py_pdb_set_trusted_domain(PyObject *self, PyObject *args)
        }
 
        py_tmp = PyDict_GetItemString(py_td_info, "domain_name");
-       td_info.domain_name = discard_const_p(char, PyStr_AsString(py_tmp));
+       td_info.domain_name = discard_const_p(char, PyUnicode_AsUTF8(py_tmp));
 
        py_tmp = PyDict_GetItemString(py_td_info, "netbios_name");
-       td_info.netbios_name = discard_const_p(char, PyStr_AsString(py_tmp));
+       td_info.netbios_name = discard_const_p(char, PyUnicode_AsUTF8(py_tmp));
 
        py_tmp = PyDict_GetItemString(py_td_info, "security_identifier");
        td_info.security_identifier = *pytalloc_get_type(py_tmp, struct dom_sid);
index 8996ac2bc33b0a82febd2ad30d2f2aaa99d84a65..b2c1e9c279a8d85a613e97bcbfa1f41ad94998c2 100644 (file)
@@ -73,7 +73,7 @@ static struct gensec_settings *settings_from_object(TALLOC_CTX *mem_ctx, PyObjec
                return NULL;
        }
 
-       s->target_hostname = PyStr_AsString(py_hostname);
+       s->target_hostname = PyUnicode_AsUTF8(py_hostname);
        s->lp_ctx = lpcfg_from_py_object(s, py_lp_ctx);
        return s;
 }
index 11b19c6499c0f78c38d1386fc10913f0958dc06c..2c7779bad89b2f3e436b1ed58f7c28fe5d8e1086 100644 (file)
@@ -140,7 +140,7 @@ static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
        
        PyErr_LDB_OR_RAISE(py_ldb, ldb);
 
-       sid = dom_sid_parse_talloc(NULL, PyStr_AsString(py_sid));
+       sid = dom_sid_parse_talloc(NULL, PyUnicode_AsUTF8(py_sid));
        if (sid == NULL) {
                PyErr_NoMemory();
                return NULL;
@@ -782,7 +782,7 @@ static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
                return NULL;
 
        PyErr_LDB_OR_RAISE(py_ldb, ldb);
-       GUID_from_string(PyStr_AsString(py_guid), &guid);
+       GUID_from_string(PyUnicode_AsUTF8(py_guid), &guid);
 
        if (GUID_all_zero(&guid)) {
                PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id rejected due to all-zero invocation ID");
@@ -1282,7 +1282,7 @@ static PyObject *py_dsdb_garbage_collect_tombstones(PyObject *self, PyObject *ar
        length = PyList_GET_SIZE(py_list_dn);
 
        for (i = 0; i < length; i++) {
-               const char *part_str = PyStr_AsString(PyList_GetItem(py_list_dn, i));
+               const char *part_str = PyUnicode_AsUTF8(PyList_GetItem(py_list_dn, i));
                struct ldb_dn *p;
                struct dsdb_ldb_dn_list_node *node;
 
index daa9ba903c25171ee2c94465841b4998698c976f..5b02a79787d95eab4b7d4b44db78abc5d78a4d28 100644 (file)
@@ -121,7 +121,7 @@ static PyObject *py_mount_hive(PyObject *self, PyObject *args)
                int i;
                elements = talloc_array(NULL, const char *, PyList_Size(py_elements));
                for (i = 0; i < PyList_Size(py_elements); i++)
-                       elements[i] = PyStr_AsString(PyList_GetItem(py_elements, i));
+                       elements[i] = PyUnicode_AsUTF8(PyList_GetItem(py_elements, i));
        }
 
        SMB_ASSERT(ctx != NULL);
index 067dadf54a202ea4750539c8ea3edd62f8090ded..cca31a587649a31e6e08fb83fc1d7bca4a4a4f99 100644 (file)
@@ -41,7 +41,7 @@ static PyTypeObject *ndr_syntax_id_Type;
 static bool PyString_AsGUID(PyObject *object, struct GUID *uuid)
 {
        NTSTATUS status;
-       status = GUID_from_string(PyStr_AsString(object), uuid);
+       status = GUID_from_string(PyUnicode_AsUTF8(object), uuid);
        if (NT_STATUS_IS_ERR(status)) {
                PyErr_SetNTSTATUS(status);
                return false;
index 177fb93f18c0fbfcd3f740b24422aef7df69b27b..395516dc3ae2361a98705d8102cb5963f673ec17 100644 (file)
@@ -270,7 +270,7 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
        }
 
        py_domaindn = PyObject_GetAttrString(py_result, "domaindn");
-       result->domaindn = talloc_strdup(mem_ctx, PyStr_AsString(py_domaindn));
+       result->domaindn = talloc_strdup(mem_ctx, PyUnicode_AsUTF8(py_domaindn));
 
        /* FIXME paths */
        py_lp_ctx = PyObject_GetAttrString(py_result, "lp");
index fc5965e624553ae154f0084176a2fe1b30a75ddc..78018fe0769dd5bec89a6bc3a172b6804951ecc0 100644 (file)
@@ -538,7 +538,7 @@ static PyObject *py_lp_ctx_getitem(PyObject *self, PyObject *name)
                PyErr_SetString(PyExc_TypeError, "Only string subscripts are supported");
                return NULL;
        }
-       service = lpcfg_service(PyLoadparmContext_AsLoadparmContext(self), PyStr_AsString(name));
+       service = lpcfg_service(PyLoadparmContext_AsLoadparmContext(self), PyUnicode_AsUTF8(name));
        if (service == NULL) {
                PyErr_SetString(PyExc_KeyError, "No such section");
                return NULL;
index 7bde8c9c7140407f642053298f836d2b6520915f..998d731f49e5d056ebd7787300c69a1c3fb1547a 100644 (file)
@@ -39,9 +39,9 @@ _PUBLIC_ struct loadparm_context *lpcfg_from_py_object(TALLOC_CTX *mem_ctx, PyOb
                if (lp_ctx == NULL) {
                        return NULL;
                }
-               if (!lpcfg_load(lp_ctx, PyStr_AsString(py_obj))) {
+               if (!lpcfg_load(lp_ctx, PyUnicode_AsUTF8(py_obj))) {
                        PyErr_Format(PyExc_RuntimeError, "Unable to load %s", 
-                                    PyStr_AsString(py_obj));
+                                    PyUnicode_AsUTF8(py_obj));
                        return NULL;
                }
                return lp_ctx;