From 801a887d781c6ba544ad21f0ec5268b2710e9c89 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 23 Sep 2004 23:26:25 +0000 Subject: [PATCH] * prof_tree.c (struct profile_node): Add new bitfield DELETED. (profile_add_node): Move variable CMP into inner block where it's used. Clear deleted flag. (profile_find_node): Skip deleted nodes. (profile_remove_node): Just set the deleted flag, don't modify the tree. * Makefile.in (profile_tcl.c): Target should be in srcdir. (profile_tcl.o): Depend on profile.h. (DO_TCL): New variable. (check-unix-tcl-, check-unix-tcl-ok): New targets. (check-unix): Depend on one of them, based on DO_TCL. * configure.in: Set and substitute DO_TCL. * prof_test1: New file. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16784 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/profile/ChangeLog | 15 ++++++++ src/util/profile/Makefile.in | 16 +++++++- src/util/profile/configure.in | 3 ++ src/util/profile/prof_set.c | 2 +- src/util/profile/prof_test1 | 70 +++++++++++++++++++++++++++++++++++ src/util/profile/prof_tree.c | 16 +++----- 6 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 src/util/profile/prof_test1 diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index a08a6107d..a1cdc5b6f 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,5 +1,19 @@ 2004-09-23 Ken Raeburn + * prof_tree.c (struct profile_node): Add new bitfield DELETED. + (profile_add_node): Move variable CMP into inner block where it's + used. Clear deleted flag. + (profile_find_node): Skip deleted nodes. + (profile_remove_node): Just set the deleted flag, don't modify the + tree. + * Makefile.in (profile_tcl.c): Target should be in srcdir. + (profile_tcl.o): Depend on profile.h. + (DO_TCL): New variable. + (check-unix-tcl-, check-unix-tcl-ok): New targets. + (check-unix): Depend on one of them, based on DO_TCL. + * configure.in: Set and substitute DO_TCL. + * prof_test1: New file. + * profile.swg: Only include tclsh.i if building for Tcl. (Tcl_SetResult, my_tcl_setresult): Compile hack only if building for Tcl. @@ -7,6 +21,7 @@ scripting language. Add Python code. (%typemap errcode_t, errcode_t*): Add placeholders for Python support. + * profile_tcl.c: Regenerated. 2004-08-28 Ken Raeburn diff --git a/src/util/profile/Makefile.in b/src/util/profile/Makefile.in index 6735909b7..76540a39e 100644 --- a/src/util/profile/Makefile.in +++ b/src/util/profile/Makefile.in @@ -112,9 +112,9 @@ prof_err.c: $(srcdir)/prof_err.et prof_err.o: prof_err.c # not built by default, but may be useful for testing -profile_tcl.c: profile.swg +$(srcdir)/profile_tcl.c: profile.swg (cd $(srcdir) && swig -tcl8 -o profile_tcl.c profile.swg) -profile_tcl.o: $(srcdir)/profile_tcl.c +profile_tcl.o: $(srcdir)/profile_tcl.c profile.h profile_tcl: profile_tcl.o libprofile.a $(CC_LINK) -o profile_tcl profile_tcl.o \ $(TCL_MAYBE_RPATH) \ @@ -129,6 +129,18 @@ clean-windows:: check-unix:: test_parse test_profile +DO_TCL=@DO_TCL@ +check-unix:: check-unix-tcl-$(DO_TCL) + +check-unix-tcl-: + @echo "+++" + @echo "+++ Tcl not available, some profile tests not run." + @echo "+++" + +check-unix-tcl-ok: profile_tcl + cp $(srcdir)/test.ini test2.ini + ./profile_tcl $(srcdir)/prof_test1 + check-windows:: $(OUTPRE)test_profile.exe $(OUTPRE)test_parse.exe $(RM) $(OUTPRE)*.obj $(OUTPRE)test_parse test.ini diff --git a/src/util/profile/configure.in b/src/util/profile/configure.in index da9d921e8..17e8b58a2 100644 --- a/src/util/profile/configure.in +++ b/src/util/profile/configure.in @@ -8,6 +8,9 @@ AC_CHECK_HEADERS(unistd.h stdlib.h pwd.h) AC_CHECK_FUNCS(stat access strdup getpwuid_r) AC_PROG_AWK AC_KRB5_TCL +DO_TCL= +test "$TCL_LIBS" != "" && DO_TCL=ok +AC_SUBST(DO_TCL) KRB5_BUILD_LIBOBJS KRB5_BUILD_PROGRAM KRB5_BUILD_LIBRARY_WITH_DEPS diff --git a/src/util/profile/prof_set.c b/src/util/profile/prof_set.c index f1e3daf63..310949b0e 100644 --- a/src/util/profile/prof_set.c +++ b/src/util/profile/prof_set.c @@ -81,7 +81,7 @@ static errcode_t rw_setup(profile_t profile) profile_unlock_global(); retval = profile_update_file(file); - + return retval; } diff --git a/src/util/profile/prof_test1 b/src/util/profile/prof_test1 new file mode 100644 index 000000000..42a6021f8 --- /dev/null +++ b/src/util/profile/prof_test1 @@ -0,0 +1,70 @@ +set wd [pwd] +set p [profile_init_path $wd/test2.ini] +set verbose 0 + +proc test1 {} { + global wd p verbose + set sect {{test section 1} child_section child} + set iter [profile_iterator_create $p $sect 0] + set done 0 + if $verbose { puts "Iterating over {$sect} entries:" } + while {!$done} { + set pair [profile_iterator $iter] + if [string match $pair {{} {}}] { + set done 1 + } else { + set val [lindex $pair 1] + if $verbose { puts -nonewline "\t$val" } + } + } + if $verbose { puts "" } + #profile_iterator_free $iter + + set iter [profile_iterator_create $p $sect 0] + set done 0 + if $verbose { puts "Iterating again, deleting:" } + while {!$done} { + set pair [profile_iterator $iter] + if [string match $pair {{} {}}] { + set done 1 + } else { + set val [lindex $pair 1] + if $verbose { puts -nonewline "\t$val" } + profile_update_relation $p $sect $val + } + } + if $verbose { puts "" } + #profile_iterator_free $iter + profile_flush $p + + if $verbose { puts "Reloading profile" } + set p [profile_init_path $wd/test2.ini] + set iter [profile_iterator_create $p $sect 0] + set done 0 + if $verbose { puts "Iterating again:" } + set found_some 0 + while {!$done} { + set pair [profile_iterator $iter] + if [string match $pair {{} {}}] { + set done 1 + } else { + set found_some 1 + set val [lindex $pair 1] + if $verbose { puts -nonewline "\t$val" } + } + } + #profile_iterator_free $iter + profile_abandon $p + + if {$found_some} { + if $verbose { puts "" } + puts stderr "Error: Deleting in iterator didn't get them all." + exit 1 + } else { + puts "OK: Deleting in iteration got rid of all entries." + } +} + +test1 + +exit 0 diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c index cf7f33f9c..1d96ffbb8 100644 --- a/src/util/profile/prof_tree.c +++ b/src/util/profile/prof_tree.c @@ -33,6 +33,7 @@ struct profile_node { char *value; int group_level; int final:1; /* Indicate don't search next file */ + int deleted:1; struct profile_node *first_child; struct profile_node *parent; struct profile_node *next, *prev; @@ -149,7 +150,6 @@ errcode_t profile_add_node(struct profile_node *section, const char *name, { errcode_t retval; struct profile_node *p, *last, *new; - int cmp = -1; CHECK_MAGIC(section); @@ -162,6 +162,7 @@ errcode_t profile_add_node(struct profile_node *section, const char *name, * order matters. */ for (p=section->first_child, last = 0; p; last = p, p = p->next) { + int cmp; cmp = strcmp(p->name, name); if (cmp > 0) break; @@ -170,6 +171,7 @@ errcode_t profile_add_node(struct profile_node *section, const char *name, if (retval) return retval; new->group_level = section->group_level+1; + new->deleted = 0; new->parent = section; new->prev = last; new->next = p; @@ -262,6 +264,8 @@ errcode_t profile_find_node(struct profile_node *section, const char *name, if (value && (strcmp(p->value, value))) continue; } + if (p->deleted) + continue; /* A match! */ if (node) *node = p; @@ -570,15 +574,7 @@ errcode_t profile_remove_node(struct profile_node *node) if (node->parent == 0) return PROF_EINVAL; /* Can't remove the root! */ - if (node->prev) - node->prev->next = node->next; - else - node->parent->first_child = node->next; - - if (node->next) - node->next->prev = node->prev; - - profile_free_node(node); + node->deleted = 1; return 0; } -- 2.26.2