From 24656c280590bbc66e98685342c461af58f478a1 Mon Sep 17 00:00:00 2001 From: pooryorick Date: Sat, 14 Jan 2023 22:07:21 +0000 Subject: Properly quote contents of Make variables to pass through gdb.run file. --- unix/Makefile.in | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/unix/Makefile.in b/unix/Makefile.in index eac47a6..21d4085 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -270,6 +270,8 @@ VALGRINDARGS = --tool=memcheck --num-callers=24 \ --keep-debuginfo=yes \ --suppressions=$(TOOL_DIR)/valgrind_suppress +shquotequote = $(subst ",\",$(subst ',\',$(1))) +shquotesingle = $(subst ','\'',$(1)) #-------------------------------------------------------------------------- # The information below should be usable as is. The configure script won't # modify it and you shouldn't need to modify it either. @@ -816,9 +818,12 @@ test-tcl: ${TCLTEST_EXE} $(SHELL_ENV) ./${TCLTEST_EXE} $(TOP_DIR)/tests/all.tcl $(TESTFLAGS) gdb-test: ${TCLTEST_EXE} - @echo "set env @LD_LIBRARY_PATH_VAR@=`pwd`:$${@LD_LIBRARY_PATH_VAR@}" > gdb.run - @echo "set env TCL_LIBRARY=${TCL_BUILDTIME_LIBRARY}" >> gdb.run - @echo "set args $(TOP_DIR)/tests/all.tcl $(TESTFLAGS) -singleproc 1" >> gdb.run + @printf '%s ' set env @LD_LIBRARY_PATH_VAR@=\"`pwd`$${@LD_LIBRARY_PATH_VAR@:+:$${@LD_LIBRARY_PATH_VAR}}\" > gdb.run + @printf '\n' >>gdb.run + @printf '%s ' set env TCL_LIBRARY=\'$(call shquotesingle,${TCL_BUILDTIME_LIBRARY})\' >> gdb.run + @printf '\n' >>gdb.run + @printf '%s ' set args $(call shquotequote,$(TOP_DIR))/tests/all.tcl\ + $(call shquotequote,$(TESTFLAGS)) -singleproc 1 >> gdb.run $(GDB) ./${TCLTEST_EXE} --command=gdb.run rm gdb.run -- cgit v0.12 From 81262438a784ae0087c36fabd189c15a2433df33 Mon Sep 17 00:00:00 2001 From: pooryorick Date: Sun, 15 Jan 2023 19:26:36 +0000 Subject: Fix issue [8f7fdea2d], string-2.20.1 fails on big endian, and also fix issues in TclStringCmp when checkEq is 1. --- generic/tclCmdMZ.c | 38 ++++++++++++++++++++++++-------------- tests/stringComp.test | 6 +++--- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 53e12c5..a97f309 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -2629,7 +2629,7 @@ StringEqualCmd( */ objv += objc-2; - match = TclStringCmp(objv[0], objv[1], 0, nocase, reqlength); + match = TclStringCmp(objv[0], objv[1], 1, nocase, reqlength); Tcl_SetObjResult(interp, Tcl_NewBooleanObj(match ? 0 : 1)); return TCL_OK; } @@ -2702,8 +2702,8 @@ TclStringCmp( Tcl_Obj *value2Ptr, int checkEq, /* comparison is only for equality */ int nocase, /* comparison is not case sensitive */ - int reqlength) /* requested length; -1 to compare whole - * strings */ + int reqlength) /* requested length in characters; -1 to + * compare whole strings */ { const char *s1, *s2; int empty, length, match, s1len, s2len; @@ -2731,10 +2731,10 @@ TclStringCmp( } else if ((value1Ptr->typePtr == &tclStringType) && (value2Ptr->typePtr == &tclStringType)) { /* - * Do a unicode-specific comparison if both of the args are of String + * Do a Unicode-specific comparison if both of the args are of String * type. If the char length == byte length, we can do a memcmp. In * benchmark testing this proved the most efficient check between the - * unicode and string comparison operations. + * Unicode and string comparison operations. */ if (nocase) { @@ -2748,6 +2748,9 @@ TclStringCmp( && (value1Ptr->bytes != NULL) && (s2len == value2Ptr->length) && (value2Ptr->bytes != NULL)) { + /* each byte represents one character so s1l3n, s2l3n, and + * reqlength are in both bytes and characters + */ s1 = value1Ptr->bytes; s2 = value2Ptr->bytes; memCmpFn = memcmp; @@ -2756,14 +2759,17 @@ TclStringCmp( s2 = (char *) Tcl_GetUnicode(value2Ptr); if ( #if defined(WORDS_BIGENDIAN) && (TCL_UTF_MAX != 4) - 1 + 1 #else - checkEq + checkEq #endif /* WORDS_BIGENDIAN */ - ) { + ) { memCmpFn = memcmp; s1len *= sizeof(Tcl_UniChar); s2len *= sizeof(Tcl_UniChar); + if (reqlength > 0) { + reqlength *= sizeof(Tcl_UniChar); + } } else { memCmpFn = (memCmpFn_t) Tcl_UniCharNcmp; } @@ -2805,7 +2811,7 @@ TclStringCmp( s2 = TclGetStringFromObj(value2Ptr, &s2len); } - if (!nocase && checkEq) { + if (!nocase && checkEq && reqlength < 0) { /* * When we have equal-length we can check only for (in)equality. * We can use memcmp() in all (n)eq cases because we don't need to @@ -2826,24 +2832,28 @@ TclStringCmp( s1len = Tcl_NumUtfChars(s1, s1len); s2len = Tcl_NumUtfChars(s2, s2len); memCmpFn = (memCmpFn_t) - (nocase ? Tcl_UtfNcasecmp : Tcl_UtfNcmp); + (nocase ? Tcl_UtfNcasecmp : Tcl_UtfNcmp); } } } + /* At this point s1len, s2len, and reqlength should by now have been + * adjusted so that they are all in the units expected by the selected + * comparison function. + */ + length = (s1len < s2len) ? s1len : s2len; if (reqlength > 0 && reqlength < length) { length = reqlength; } else if (reqlength < 0) { /* - * The requested length is negative, so we ignore it by setting it to - * length + 1 so we correct the match var. + * The requested length is negative, so ignore it by setting it to + * length + 1 to correct the match var. */ - reqlength = length + 1; } - if (checkEq && (s1len != s2len)) { + if (checkEq && reqlength < 0 && (s1len != s2len)) { match = 1; /* This will be reversed below. */ } else { /* diff --git a/tests/stringComp.test b/tests/stringComp.test index a17390d..95a738c 100644 --- a/tests/stringComp.test +++ b/tests/stringComp.test @@ -100,7 +100,7 @@ foreach {tname tbody tresult tcode} { {unicode} {string compare \334 \u00fc} -1 {} {unicode} {string compare \334\334\334\374\374 \334\334\334\334\334} 1 {} {high bit} { - # This test will fail if the underlying comparison + # This test fails if the underlying comparison # is using signed chars instead of unsigned chars. # (like SunOS's default memcmp thus the compat/memcmp.c) string compare "\x80" "@" @@ -156,10 +156,10 @@ foreach {tname tbody tresult tcode} { {-nocase null strings} { string compare -nocase foo "" } 1 {} - {with length, unequal strings} { + {with length, unequal strings, partial first string} { string compare -length 2 abc abde } 0 {} - {with length, unequal strings} { + {with length, unequal strings 2, full first string} { string compare -length 2 ab abde } 0 {} {with NUL character vs. other ASCII} { -- cgit v0.12