summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclExecute.c66
1 files changed, 23 insertions, 43 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 34d92d3..cd27f6b 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -5804,57 +5804,37 @@ TEBCresume(
* Remove substring using copying.
*/
- if (length3 == 0) {
- if (fromIdx > 0) {
- objResultPtr = Tcl_NewUnicodeObj(ustring1, fromIdx);
- if (toIdx < length) {
- Tcl_AppendUnicodeToObj(objResultPtr, ustring1 + toIdx + 1,
- length - toIdx);
- }
- } else {
- objResultPtr = Tcl_NewUnicodeObj(ustring1 + toIdx + 1,
- length - toIdx);
- }
- TclDecrRefCount(value3Ptr);
- TRACE_APPEND(("\"%.30s\"\n", O2S(objResultPtr)));
- NEXT_INST_F(1, 1, 1);
- }
-
- /*
- * Splice string pieces by full copying.
- */
-
+ objResultPtr = NULL;
if (fromIdx > 0) {
objResultPtr = Tcl_NewUnicodeObj(ustring1, fromIdx);
- Tcl_AppendObjToObj(objResultPtr, value3Ptr);
- if (toIdx < length) {
- Tcl_AppendUnicodeToObj(objResultPtr, ustring1 + toIdx + 1,
- length - toIdx);
+ }
+ if (length3 > 0) {
+ if (objResultPtr) {
+ Tcl_AppendObjToObj(objResultPtr, value3Ptr);
+ } else if (Tcl_IsShared(value3Ptr)) {
+ objResultPtr = Tcl_DuplicateObj(value3Ptr);
+ } else {
+ objResultPtr = value3Ptr;
}
- } else if (Tcl_IsShared(value3Ptr)) {
- objResultPtr = Tcl_DuplicateObj(value3Ptr);
- if (toIdx < length) {
+ }
+ if (toIdx < length) {
+ if (objResultPtr) {
Tcl_AppendUnicodeToObj(objResultPtr, ustring1 + toIdx + 1,
length - toIdx);
- }
- } else {
- /*
- * Be careful with splicing the stack in this case; we have a
- * refCount:1 object in value3Ptr and we want to append to it and
- * make it be the refCount:1 object at the top of the stack
- * afterwards. [Bug 82e7f67325]
- */
-
- if (toIdx < length) {
- Tcl_AppendUnicodeToObj(value3Ptr, ustring1 + toIdx + 1,
+ } else {
+ objResultPtr = Tcl_NewUnicodeObj(ustring1 + toIdx + 1,
length - toIdx);
}
- TRACE_APPEND(("\"%.30s\"\n", O2S(value3Ptr)));
- TclDecrRefCount(valuePtr);
- OBJ_AT_TOS = value3Ptr; /* Tricky! */
- NEXT_INST_F(1, 0, 0);
}
- TclDecrRefCount(value3Ptr);
+ if (objResultPtr == NULL) {
+ /* This has to be the case [string replace $s 0 end {}] */
+ /* which has result {} which is same as value3Ptr. */
+ objResultPtr = value3Ptr;
+ }
+ if (objResultPtr != value3Ptr) {
+ /* See [Bug 82e7f67325] */
+ TclDecrRefCount(value3Ptr);
+ }
TRACE_APPEND(("\"%.30s\"\n", O2S(objResultPtr)));
NEXT_INST_F(1, 1, 1);