summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2015-09-23 09:40:46 (GMT)
committerdgp <dgp@users.sourceforge.net>2015-09-23 09:40:46 (GMT)
commit58cebf8eebe511c29bb83d3d64ee229d2e72b594 (patch)
treee435fea0bd8575ed68fbd4faf6a3ef45f864f01a /generic/tclIO.c
parent0dd1c1bcd3ae099f29d58227fcbe02b66a65c410 (diff)
downloadtcl-58cebf8eebe511c29bb83d3d64ee229d2e72b594.zip
tcl-58cebf8eebe511c29bb83d3d64ee229d2e72b594.tar.gz
tcl-58cebf8eebe511c29bb83d3d64ee229d2e72b594.tar.bz2
WIP
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c50
1 files changed, 47 insertions, 3 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 564df27..d4db7ec 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -113,11 +113,32 @@ typedef struct CopyState {
Tcl_WideInt total; /* Total bytes transferred (written). */
Tcl_Interp *interp; /* Interp that started the copy. */
Tcl_Obj *cmdPtr; /* Command to be invoked at completion. */
+ int refCount; /* Claim count on the struct */
int bufSize; /* Size of appended buffer. */
char buffer[1]; /* Copy buffer, this must be the last
* field. */
} CopyState;
+static void
+PreserveCopyState(
+ CopyState *csPtr)
+{
+ csPtr->refCount++;
+fprintf(stdout, "PRESERVE -> %d %p\n", csPtr->refCount, csPtr); fflush(stdout);
+}
+
+static void
+ReleaseCopyState(
+ CopyState *csPtr)
+{
+fprintf(stdout, "%d -> RELEASE %p\n", csPtr->refCount, csPtr); fflush(stdout);
+ if (--csPtr->refCount) {
+ return;
+ }
+fprintf(stdout, "FREE %p\n", csPtr); fflush(stdout);
+ ckfree((char *) csPtr);
+}
+
/*
* All static variables used in this file are collected into a single instance
* of the following structure. For multi-threaded implementations, there is
@@ -8642,9 +8663,12 @@ TclCopyChannel(
Tcl_IncrRefCount(cmdPtr);
}
csPtr->cmdPtr = cmdPtr;
+ csPtr->refCount = 1;
inStatePtr->csPtrR = csPtr;
+ PreserveCopyState(csPtr);
outStatePtr->csPtrW = csPtr;
+ PreserveCopyState(csPtr);
/*
* Special handling of -size 0 async transfers, so that the -command is
@@ -8696,6 +8720,9 @@ CopyData(
/* Encoding control */
int underflow; /* Input underflow */
+fprintf(stdout, "CD: %p\n", csPtr); fflush(stdout);
+ PreserveCopyState(csPtr);
+
inChan = (Tcl_Channel) csPtr->readPtr;
outChan = (Tcl_Channel) csPtr->writePtr;
inStatePtr = csPtr->readPtr->state;
@@ -8807,6 +8834,8 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+fprintf(stdout, "ECD 1: %p\n", csPtr); fflush(stdout);
+ ReleaseCopyState(csPtr);
return TCL_OK;
}
}
@@ -8898,6 +8927,8 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+fprintf(stdout, "ECD 2: %p\n", csPtr); fflush(stdout);
+ ReleaseCopyState(csPtr);
return TCL_OK;
}
@@ -8920,6 +8951,8 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+fprintf(stdout, "ECD 3: %p\n", csPtr); fflush(stdout);
+ ReleaseCopyState(csPtr);
return TCL_OK;
}
} /* while */
@@ -8971,6 +9004,8 @@ CopyData(
}
}
}
+fprintf(stdout, "ECD 4: %p\n", csPtr); fflush(stdout);
+ ReleaseCopyState(csPtr);
return result;
}
@@ -9253,6 +9288,7 @@ StopCopy(
return;
}
+fprintf(stdout, "SC: %p\n", csPtr); fflush(stdout);
inStatePtr = csPtr->readPtr->state;
outStatePtr = csPtr->writePtr->state;
@@ -9285,9 +9321,17 @@ StopCopy(
}
TclDecrRefCount(csPtr->cmdPtr);
}
- inStatePtr->csPtrR = NULL;
- outStatePtr->csPtrW = NULL;
- ckfree((char *) csPtr);
+ if (inStatePtr->csPtrR) {
+ ReleaseCopyState(inStatePtr->csPtrR);
+ inStatePtr->csPtrR = NULL;
+ }
+ if (outStatePtr->csPtrW) {
+ ReleaseCopyState(outStatePtr->csPtrW);
+ outStatePtr->csPtrW = NULL;
+ }
+ ReleaseCopyState(csPtr);
+// ckfree((char *) csPtr);
+fprintf(stdout, "ESC: %p\n", csPtr); fflush(stdout);
}
/*