[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Thu Aug 29 08:41:02 UTC 2024


The branch, master has been updated
       via  df103890f9f libndr: Streamline ndr_token_retrieve_cmp_fn
       via  f43ae1ab1a8 libndr: Simplify ndr_token_retrieve_cmp_fn()
      from  56c48154028 libcli/smb: Fix failure of Smb3UnixTests.test_create_context_reparse

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit df103890f9febd5551d5bbff5498179866ab890e
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 28 12:32:45 2024 +0200

    libndr: Streamline ndr_token_retrieve_cmp_fn
    
    Rename the public function to ndr_token_peek_cmp_fn, the only user
    does not remove the token. Factor out ndr_token_find to move the
    token-removing logic to ndr_token_retrieve, the only caller that does
    remove the token.
    
    Keep libndr at 6.0.0, this has not been released yet.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jennifer Sutton <josutton at catalyst.net.nz>
    
    Autobuild-User(master): Volker Lendecke <vl at samba.org>
    Autobuild-Date(master): Thu Aug 29 08:40:52 UTC 2024 on atb-devel-224

commit f43ae1ab1a8803d8c5ad4e5f3dad63ccbe91aa54
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 28 12:08:57 2024 +0200

    libndr: Simplify ndr_token_retrieve_cmp_fn()
    
    Avoid an if-statement inside by passing a pointer-comparing function
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jennifer Sutton <josutton at catalyst.net.nz>

-----------------------------------------------------------------------

Summary of changes:
 librpc/ABI/ndr-6.0.0.sigs  |  2 +-
 librpc/ndr/libndr.h        |  7 +++--
 librpc/ndr/ndr.c           | 68 ++++++++++++++++++++++++++++------------------
 librpc/ndr/ndr_dns_utils.c |  9 +++---
 4 files changed, 53 insertions(+), 33 deletions(-)


Changeset truncated at 500 lines:

diff --git a/librpc/ABI/ndr-6.0.0.sigs b/librpc/ABI/ndr-6.0.0.sigs
index cfc27b32a9a..3244948abcc 100644
--- a/librpc/ABI/ndr-6.0.0.sigs
+++ b/librpc/ABI/ndr-6.0.0.sigs
@@ -266,8 +266,8 @@ ndr_syntax_id_null: uuid = {time_low = 0, time_mid = 0, time_hi_and_version = 0,
 ndr_syntax_id_to_string: char *(TALLOC_CTX *, const struct ndr_syntax_id *)
 ndr_token_max_list_size: size_t (void)
 ndr_token_peek: enum ndr_err_code (struct ndr_token_list *, const void *, uint32_t *)
+ndr_token_peek_cmp_fn: enum ndr_err_code (struct ndr_token_list *, const void *, uint32_t *, comparison_fn_t)
 ndr_token_retrieve: enum ndr_err_code (struct ndr_token_list *, const void *, uint32_t *)
-ndr_token_retrieve_cmp_fn: enum ndr_err_code (struct ndr_token_list *, const void *, uint32_t *, comparison_fn_t, bool)
 ndr_token_store: enum ndr_err_code (TALLOC_CTX *, struct ndr_token_list *, const void *, uint32_t)
 ndr_transfer_syntax_ndr: uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\237\350", node = "\b\000+\020H`"}, if_version = 2
 ndr_transfer_syntax_ndr64: uuid = {time_low = 1903232307, time_mid = 48826, time_hi_and_version = 18743, clock_seq = "\203\031", node = "\265\333\357\234\3146"}, if_version = 1
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h
index aafdc1536eb..223501ab781 100644
--- a/librpc/ndr/libndr.h
+++ b/librpc/ndr/libndr.h
@@ -721,8 +721,11 @@ enum ndr_err_code ndr_token_store(TALLOC_CTX *mem_ctx,
 			 struct ndr_token_list *list,
 			 const void *key,
 			 uint32_t value);
-enum ndr_err_code ndr_token_retrieve_cmp_fn(struct ndr_token_list *list, const void *key, uint32_t *v,
-					    int(*_cmp_fn)(const void*,const void*), bool erase);
+enum ndr_err_code ndr_token_peek_cmp_fn(struct ndr_token_list *list,
+					const void *key,
+					uint32_t *v,
+					int (*_cmp_fn)(const void *,
+						       const void *));
 enum ndr_err_code ndr_token_retrieve(struct ndr_token_list *list, const void *key, uint32_t *v);
 enum ndr_err_code ndr_token_peek(struct ndr_token_list *list, const void *key, uint32_t *v);
 enum ndr_err_code ndr_pull_array_size(struct ndr_pull *ndr, const void *p);
diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c
index 9e538f68267..16dc54463b8 100644
--- a/librpc/ndr/ndr.c
+++ b/librpc/ndr/ndr.c
@@ -1044,36 +1044,36 @@ _PUBLIC_ enum ndr_err_code ndr_token_store(TALLOC_CTX *mem_ctx,
 /*
   retrieve a token from a ndr context, using cmp_fn to match the tokens
 */
-_PUBLIC_ enum ndr_err_code ndr_token_retrieve_cmp_fn(struct ndr_token_list *list,
-						     const void *key, uint32_t *v,
-						     comparison_fn_t _cmp_fn,
-						     bool erase)
+static enum ndr_err_code ndr_token_find(struct ndr_token_list *list,
+					const void *key,
+					uint32_t *v,
+					comparison_fn_t _cmp_fn,
+					unsigned *_i)
 {
 	struct ndr_token *tokens = list->tokens;
 	unsigned i;
-	if (_cmp_fn) {
-		for (i = list->count - 1; i < list->count; i--) {
-			if (_cmp_fn(tokens[i].key, key) == 0) {
-				goto found;
-			}
-		}
-	} else {
-		for (i = list->count - 1; i < list->count; i--) {
-			if (tokens[i].key == key) {
-				goto found;
-			}
+	for (i = list->count - 1; i < list->count; i--) {
+		if (_cmp_fn(tokens[i].key, key) == 0) {
+			*_i = i;
+			*v = tokens[i].value;
+			return NDR_ERR_SUCCESS;
 		}
 	}
 	return NDR_ERR_TOKEN;
-found:
-	*v = tokens[i].value;
-	if (erase) {
-		if (i != list->count - 1) {
-			tokens[i] = tokens[list->count - 1];
-		}
-		list->count--;
-	}
-	return NDR_ERR_SUCCESS;
+}
+
+_PUBLIC_ enum ndr_err_code ndr_token_peek_cmp_fn(struct ndr_token_list *list,
+						 const void *key,
+						 uint32_t *v,
+						 comparison_fn_t _cmp_fn)
+{
+	unsigned i;
+	return ndr_token_find(list, key, v, _cmp_fn, &i);
+}
+
+static int token_cmp_ptr(const void *a, const void *b)
+{
+	return (a == b) ? 0 : 1;
 }
 
 /*
@@ -1082,7 +1082,22 @@ found:
 _PUBLIC_ enum ndr_err_code ndr_token_retrieve(struct ndr_token_list *list,
 					      const void *key, uint32_t *v)
 {
-	return ndr_token_retrieve_cmp_fn(list, key, v, NULL, true);
+	enum ndr_err_code err;
+	uint32_t last;
+	unsigned i;
+
+	err = ndr_token_find(list, key, v, token_cmp_ptr, &i);
+	if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
+		return err;
+	}
+
+	last = list->count - 1;
+	if (i != last) {
+		list->tokens[i] = list->tokens[last];
+	}
+	list->count--;
+
+	return NDR_ERR_SUCCESS;
 }
 
 /*
@@ -1091,7 +1106,8 @@ _PUBLIC_ enum ndr_err_code ndr_token_retrieve(struct ndr_token_list *list,
 _PUBLIC_ enum ndr_err_code ndr_token_peek(struct ndr_token_list *list,
 					  const void *key, uint32_t *v)
 {
-	return ndr_token_retrieve_cmp_fn(list, key, v, NULL, false);
+	unsigned i;
+	return ndr_token_find(list, key, v, token_cmp_ptr, &i);
 }
 
 /*
diff --git a/librpc/ndr/ndr_dns_utils.c b/librpc/ndr/ndr_dns_utils.c
index a2e04640d52..fe9e060306e 100644
--- a/librpc/ndr/ndr_dns_utils.c
+++ b/librpc/ndr/ndr_dns_utils.c
@@ -50,10 +50,11 @@ enum ndr_err_code ndr_push_dns_string_list(struct ndr_push *ndr,
 			/* see if we have pushed the remaining string already,
 			 * if so we use a label pointer to this string
 			 */
-			ndr_err = ndr_token_retrieve_cmp_fn(string_list, s,
-							    &offset,
-							    (comparison_fn_t)strcmp,
-							    false);
+			ndr_err = ndr_token_peek_cmp_fn(string_list,
+							s,
+							&offset,
+							(comparison_fn_t)
+								strcmp);
 			if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
 				uint8_t b[2];
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list