The branch, master has been updated via 53e8d52 param: Use talloc_pooled_object via 0f600c3 param: Simplify set_param_opt() via 78d7512 lib: Remove unused parmlist code from 59e955b vfs_scannedonly: Remove vfs_scannedonly from samba source tree.
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 53e8d527f3e2d9ff0173263531105d29e7eabb20 Author: Volker Lendecke <v...@samba.org> Date: Mon Aug 17 21:12:56 2015 +0200 param: Use talloc_pooled_object Reduce memory fragmentation a bit and obsolete NULL checks Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> Autobuild-User(master): Volker Lendecke <v...@samba.org> Autobuild-Date(master): Fri Aug 21 14:45:58 CEST 2015 on sn-devel-104 commit 0f600c34599a61a4c338b1e10af438016bec0b14 Author: Volker Lendecke <v...@samba.org> Date: Mon Aug 17 21:07:37 2015 +0200 param: Simplify set_param_opt() "not_added" is not a very good boolean flag concept... An early return serves the same purpose just as well. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit 78d7512db9e0098c5ae16111b1338eaa80673d5e Author: Volker Lendecke <v...@samba.org> Date: Mon Aug 17 17:15:27 2015 +0200 lib: Remove unused parmlist code Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> ----------------------------------------------------------------------- Summary of changes: lib/param/loadparm.c | 34 ++++------- lib/param/loadparm.h | 13 ++++- lib/util/parmlist.c | 111 ------------------------------------ lib/util/parmlist.h | 57 ------------------ lib/util/tests/parmlist.c | 107 ---------------------------------- lib/util/wscript_build | 2 +- source4/torture/local/local.c | 1 - source4/torture/local/wscript_build | 2 +- 8 files changed, 26 insertions(+), 301 deletions(-) delete mode 100644 lib/util/parmlist.c delete mode 100644 lib/util/parmlist.h delete mode 100644 lib/util/tests/parmlist.c Changeset truncated at 500 lines: diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c index 0a1c29a..a0700a9 100644 --- a/lib/param/loadparm.c +++ b/lib/param/loadparm.c @@ -802,10 +802,8 @@ void set_param_opt(TALLOC_CTX *mem_ctx, unsigned priority) { struct parmlist_entry *new_opt, *opt; - bool not_added; opt = *opt_list; - not_added = true; /* Traverse destination */ while (opt) { @@ -821,31 +819,23 @@ void set_param_opt(TALLOC_CTX *mem_ctx, TALLOC_FREE(opt->list); opt->value = talloc_strdup(opt, opt_value); opt->priority = priority; - not_added = false; - break; + return; } opt = opt->next; } - if (not_added) { - new_opt = talloc(mem_ctx, struct parmlist_entry); - if (new_opt == NULL) { - smb_panic("OOM"); - } - - new_opt->key = talloc_strdup(new_opt, opt_name); - if (new_opt->key == NULL) { - smb_panic("talloc_strdup failed"); - } - - new_opt->value = talloc_strdup(new_opt, opt_value); - if (new_opt->value == NULL) { - smb_panic("talloc_strdup failed"); - } - new_opt->list = NULL; - new_opt->priority = priority; - DLIST_ADD(*opt_list, new_opt); + new_opt = talloc_pooled_object( + mem_ctx, struct parmlist_entry, + 2, strlen(opt_name) + 1 + strlen(opt_value) + 1); + if (new_opt == NULL) { + smb_panic("OOM"); } + new_opt->key = talloc_strdup(new_opt, opt_name); + new_opt->value = talloc_strdup(new_opt, opt_value); + + new_opt->list = NULL; + new_opt->priority = priority; + DLIST_ADD(*opt_list, new_opt); } /** diff --git a/lib/param/loadparm.h b/lib/param/loadparm.h index 89dcb17..b453aca 100644 --- a/lib/param/loadparm.h +++ b/lib/param/loadparm.h @@ -31,7 +31,18 @@ #define _LOADPARM_H #include <talloc.h> -#include "../lib/util/parmlist.h" + +struct parmlist_entry { + struct parmlist_entry *prev, *next; + char *key; + char *value; + char **list; /* For the source3 parametric options, to save the parsed list */ + int priority; +}; + +struct parmlist { + struct parmlist_entry *entries; +}; /* the following are used by loadparm for option lists */ typedef enum { diff --git a/lib/util/parmlist.c b/lib/util/parmlist.c deleted file mode 100644 index b3e1e9f..0000000 --- a/lib/util/parmlist.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Copyright (C) Jelmer Vernooij 2009 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" -#include "../lib/util/dlinklist.h" -#include "../lib/util/parmlist.h" - -#undef strcasecmp - -struct parmlist_entry *parmlist_get(struct parmlist *ctx, const char *name) -{ - struct parmlist_entry *e; - for (e = ctx->entries; e; e = e->next) { - if (strcasecmp(e->key, name) == 0) - return e; - } - - return NULL; -} - -int parmlist_get_int(struct parmlist *ctx, const char *name, int default_v) -{ - struct parmlist_entry *p = parmlist_get(ctx, name); - - if (p != NULL) - return strtol(p->value, NULL, 0); - - return default_v; -} - -bool parmlist_get_bool(struct parmlist *ctx, const char *name, bool default_v) -{ - struct parmlist_entry *p = parmlist_get(ctx, name); - bool ret; - - if (p == NULL) - return default_v; - - if (!set_boolean(p->value, &ret)) { - DEBUG(0,("lp_bool(%s): value is not boolean!\n", p->value)); - return default_v; - } - - return ret; -} - -const char *parmlist_get_string(struct parmlist *ctx, const char *name, - const char *default_v) -{ - struct parmlist_entry *p = parmlist_get(ctx, name); - - if (p == NULL) - return default_v; - - return p->value; -} - -const char **parmlist_get_string_list(struct parmlist *ctx, const char *name, - const char *separator) -{ - struct parmlist_entry *p = parmlist_get(ctx, name); - char **l; - - if (p == NULL) { - return NULL; - } - - l = str_list_make(ctx, p->value, separator); - return discard_const_p(const char *, l); -} - -static struct parmlist_entry *parmlist_get_add(struct parmlist *ctx, const char *name) -{ - struct parmlist_entry *e = parmlist_get(ctx, name); - - if (e != NULL) - return e; - - e = talloc(ctx, struct parmlist_entry); - if (e == NULL) - return NULL; - e->key = talloc_strdup(e, name); - DLIST_ADD(ctx->entries, e); - return e; -} - -int parmlist_set_string(struct parmlist *ctx, const char *name, - const char *value) -{ - struct parmlist_entry *e = parmlist_get_add(ctx, name); - if (e == NULL) - return -1; - - e->value = talloc_strdup(e, value); - return 0; -} diff --git a/lib/util/parmlist.h b/lib/util/parmlist.h deleted file mode 100644 index 9bc4f36..0000000 --- a/lib/util/parmlist.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Generic parameter parsing interface - Copyright (C) Jelmer Vernooij 2009 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef _PARMLIST_H /* _PARMLIST_H */ -#define _PARMLIST_H - -struct parmlist_entry { - struct parmlist_entry *prev, *next; - char *key; - char *value; - char **list; /* For the source3 parametric options, to save the parsed list */ - int priority; -}; - -struct parmlist { - struct parmlist_entry *entries; -}; - -/** Retrieve an integer from a parameter list. If not found, return default_v. */ -int parmlist_get_int(struct parmlist *ctx, const char *name, int default_v); - -/** Retrieve a string from a parameter list. If not found, return default_v. */ -const char *parmlist_get_string(struct parmlist *ctx, const char *name, - const char *default_v); - -/** Retrieve the struct for an entry in a parmlist. */ -struct parmlist_entry *parmlist_get(struct parmlist *ctx, const char *name); - -/** Retrieve a string list from a parameter list. - * separator can contain characters to consider separators or can be - * NULL for the default set. */ -const char **parmlist_get_string_list(struct parmlist *ctx, const char *name, - const char *separator); - -/** Retrieve boolean from a parameter list. If not set, return default_v. */ -bool parmlist_get_bool(struct parmlist *ctx, const char *name, bool default_v); - -/** Set a parameter. */ -int parmlist_set_string(struct parmlist *ctx, const char *name, const char *value); - -#endif /* _PARMLIST_H */ diff --git a/lib/util/tests/parmlist.c b/lib/util/tests/parmlist.c deleted file mode 100644 index df589ef..0000000 --- a/lib/util/tests/parmlist.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - parmlist testing - - Copyright (C) Jelmer Vernooij 2009 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "torture/torture.h" -#include "torture/local/proto.h" -#include "../lib/util/parmlist.h" - -static bool test_get_int(struct torture_context *tctx) -{ - struct parmlist *pctx = talloc_zero(tctx, struct parmlist); - parmlist_set_string(pctx, "bar", "3"); - parmlist_set_string(pctx, "notint", "bla"); - torture_assert_int_equal(tctx, 3, parmlist_get_int(pctx, "bar", 42), - "existing"); - torture_assert_int_equal(tctx, 42, parmlist_get_int(pctx, "foo", 42), - "default"); - torture_assert_int_equal(tctx, 0, parmlist_get_int(pctx, "notint", 42), - "Not an integer"); - return true; -} - -static bool test_get_string(struct torture_context *tctx) -{ - struct parmlist *pctx = talloc_zero(tctx, struct parmlist); - parmlist_set_string(pctx, "bar", "mystring"); - torture_assert_str_equal(tctx, "mystring", - parmlist_get_string(pctx, "bar", "bla"), "existing"); - torture_assert_str_equal(tctx, "bla", - parmlist_get_string(pctx, "foo", "bla"), "default"); - return true; -} - -static bool test_get(struct torture_context *tctx) -{ - struct parmlist *pctx = talloc_zero(tctx, struct parmlist); - struct parmlist_entry *e; - parmlist_set_string(pctx, "bar", "mystring"); - - e = parmlist_get(pctx, "bar"); - torture_assert(tctx, e != NULL, "entry"); - torture_assert_str_equal(tctx, e->key, "bar", "key"); - torture_assert_str_equal(tctx, e->value, "mystring", "value"); - - e = parmlist_get(pctx, "non-existent"); - torture_assert(tctx, e == NULL, "non-existent"); - return true; -} - -static bool test_get_bool(struct torture_context *tctx) -{ - struct parmlist *pctx = talloc_zero(tctx, struct parmlist); - parmlist_set_string(pctx, "bar", "true"); - parmlist_set_string(pctx, "gasoline", "invalid"); - - torture_assert(tctx, parmlist_get_bool(pctx, "bar", false), "set"); - torture_assert(tctx, !parmlist_get_bool(pctx, "foo", false), "default"); - torture_assert(tctx, !parmlist_get_bool(pctx, "gasoline", false), - "invalid"); - return true; -} - -static bool test_get_string_list(struct torture_context *tctx) -{ - struct parmlist *pctx = talloc_zero(tctx, struct parmlist); - const char **ret; - parmlist_set_string(pctx, "bar", "true, false"); - - ret = parmlist_get_string_list(pctx, "bar", NULL); - torture_assert_int_equal(tctx, str_list_length(ret), 2, "length"); - torture_assert_str_equal(tctx, "true", ret[0], "ret[0]"); - torture_assert_str_equal(tctx, "false", ret[1], "ret[1]"); - torture_assert(tctx, NULL == parmlist_get_string_list(pctx, "non-existent", NULL), "non-existent"); - - return true; -} - -struct torture_suite *torture_local_util_parmlist(TALLOC_CTX *mem_ctx) -{ - struct torture_suite *suite = torture_suite_create(mem_ctx, "parmlist"); - - torture_suite_add_simple_test(suite, "get_int", test_get_int); - torture_suite_add_simple_test(suite, "get_string", test_get_string); - torture_suite_add_simple_test(suite, "get", test_get); - torture_suite_add_simple_test(suite, "get_bool", test_get_bool); - torture_suite_add_simple_test(suite, "get_string_list", test_get_string_list); - - return suite; -} diff --git a/lib/util/wscript_build b/lib/util/wscript_build index e5c1a97..47d64c1 100755 --- a/lib/util/wscript_build +++ b/lib/util/wscript_build @@ -86,7 +86,7 @@ if not bld.env.SAMBA_UTIL_CORE_ONLY: params.c util_id.c util_net.c util_strlist.c util_paths.c idtree_random.c base64.c util_str.c util_str_common.c ms_fnmatch.c - server_id.c dprintf.c parmlist.c bitmap.c pidfile.c + server_id.c dprintf.c bitmap.c pidfile.c tevent_debug.c util_process.c memcache.c''', deps='samba-util-core DYNCONFIG close-low-fd tini tiniparser genrand', diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c index 5d3b4e1..91e67f8 100644 --- a/source4/torture/local/local.c +++ b/source4/torture/local/local.c @@ -35,7 +35,6 @@ torture_local_messaging, torture_local_irpc, torture_local_util_strlist, - torture_local_util_parmlist, torture_local_util_file, torture_local_util_str, torture_local_util_time, diff --git a/source4/torture/local/wscript_build b/source4/torture/local/wscript_build index 570222e..eb45df8 100644 --- a/source4/torture/local/wscript_build +++ b/source4/torture/local/wscript_build @@ -5,7 +5,7 @@ TORTURE_LOCAL_SOURCE = '''../../../lib/util/charset/tests/iconv.c ../../lib/messaging/tests/irpc.c ../../librpc/tests/binding_string.c ../../../lib/util/tests/idtree.c ../../../lib/util/tests/dlinklist.c ../../lib/socket/testsuite.c ../../libcli/resolve/testsuite.c - ../../../lib/util/tests/strlist.c ../../../lib/util/tests/parmlist.c + ../../../lib/util/tests/strlist.c ../../../lib/util/tests/str.c ../../../lib/util/tests/time.c ../../../lib/util/tests/asn1_tests.c ../../../lib/util/tests/data_blob.c ../../../lib/util/tests/file.c ../../../lib/util/tests/genrand.c -- Samba Shared Repository