From f178daa854dc4ea9cb917d17cd4c8a876356e981 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 7 Jun 2019 11:16:25 +0200 Subject: [PATCH] py3: Remove PyStr_AsString() compatability macro 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 Reviewed-by: Noel Power --- libcli/nbt/pynbt.c | 12 +++++----- python/py3compat.h | 2 -- source3/passdb/py_passdb.c | 38 +++++++++++++++---------------- source4/auth/gensec/pygensec.c | 2 +- source4/dsdb/pydsdb.c | 6 ++--- source4/lib/registry/pyregistry.c | 2 +- source4/librpc/rpc/pyrpc.c | 2 +- source4/param/provision.c | 2 +- source4/param/pyparam.c | 2 +- source4/param/pyparam_util.c | 4 ++-- 10 files changed, 35 insertions(+), 37 deletions(-) diff --git a/libcli/nbt/pynbt.c b/libcli/nbt/pynbt.c index bcc98b78722..c440ec933c4 100644 --- a/libcli/nbt/pynbt.c +++ b/libcli/nbt/pynbt.c @@ -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; } diff --git a/python/py3compat.h b/python/py3compat.h index 2db77d1b1dd..c9751a9754c 100644 --- a/python/py3compat.h +++ b/python/py3compat.h @@ -54,8 +54,6 @@ /* Strings */ -#define PyStr_AsString PyUnicode_AsUTF8 - #define PyStr_AsUTF8 PyUnicode_AsUTF8 #define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize diff --git a/source3/passdb/py_passdb.c b/source3/passdb/py_passdb.c index 0c0f1be5055..f7e80c47397 100644 --- a/source3/passdb/py_passdb.c +++ b/source3/passdb/py_passdb.c @@ -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); diff --git a/source4/auth/gensec/pygensec.c b/source4/auth/gensec/pygensec.c index 8996ac2bc33..b2c1e9c279a 100644 --- a/source4/auth/gensec/pygensec.c +++ b/source4/auth/gensec/pygensec.c @@ -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; } diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c index 11b19c6499c..2c7779bad89 100644 --- a/source4/dsdb/pydsdb.c +++ b/source4/dsdb/pydsdb.c @@ -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; diff --git a/source4/lib/registry/pyregistry.c b/source4/lib/registry/pyregistry.c index daa9ba903c2..5b02a79787d 100644 --- a/source4/lib/registry/pyregistry.c +++ b/source4/lib/registry/pyregistry.c @@ -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); diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 067dadf54a2..cca31a58764 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -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; diff --git a/source4/param/provision.c b/source4/param/provision.c index 177fb93f18c..395516dc3ae 100644 --- a/source4/param/provision.c +++ b/source4/param/provision.c @@ -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"); diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c index fc5965e6245..78018fe0769 100644 --- a/source4/param/pyparam.c +++ b/source4/param/pyparam.c @@ -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; diff --git a/source4/param/pyparam_util.c b/source4/param/pyparam_util.c index 7bde8c9c714..998d731f49e 100644 --- a/source4/param/pyparam_util.c +++ b/source4/param/pyparam_util.c @@ -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; -- 2.47.3