Tcl Source Code

Artifact [37724aaa1e]
Login

Artifact 37724aaa1e4c7e1de2bfdc8a45197adf049340b7:

Attachment "zlib.patch" to ticket [dd260aaf72] added by anonymous 2016-04-16 06:58:13. (unpublished)
Index: doc/zlib.n
==================================================================
--- doc/zlib.n
+++ doc/zlib.n
@@ -172,11 +172,14 @@
 .TP
 \fB\-dictionary\fI binData\fR
 .VS "TIP 400"
 Sets the compression dictionary to use when working with compressing or
 decompressing the data to be \fIbinData\fR. Not valid for transformations that
-work with gzip-format data.
+work with gzip-format data.  The dictionary should consist of strings (byte
+sequences) that are likely to be encountered later in the data to be compressed,
+with the most commonly used strings preferably put towards the end of the
+dictionary.
 .VE
 .TP
 \fB\-header\fI dictionary\fR
 .
 Passes a description of the gzip header to create, in the same format that
@@ -205,15 +208,16 @@
 decompressing transforms, but not for the raw inflate and deflate formats. The
 compression algorithm depends on what format is being produced or consumed.
 .TP
 \fB\-dictionary\fI binData\fR
 .VS "TIP 400"
-This read-write options gets or sets the compression dictionary to use when
-working with compressing or decompressing the data to be \fIbinData\fR. It is
-not valid for transformations that work with gzip-format data, and should not
-normally be set on compressing transformations other than at the point where
-the transformation is stacked.
+This read-write options gets or sets the initial compression dictionary to use
+when working with compressing or decompressing the data to be \fIbinData\fR.
+It is not valid for transformations that work with gzip-format data, and should
+not normally be set on compressing transformations other than at the point where
+the transformation is stacked.  Note that this cannot be used to get the
+current compression dictionary mid-stream.
 .VE
 .TP
 \fB\-flush\fI type\fR
 .
 This write-only operation flushes the current state of the compressor to the

Index: generic/tclZlib.c
==================================================================
--- generic/tclZlib.c
+++ generic/tclZlib.c
@@ -3342,14 +3342,16 @@
 			Tcl_GetString(cd->compDictObj));
 	    } else {
 		Tcl_DStringAppendElement(dsPtr, "");
 	    }
 	} else {
-	    int len;
-	    const char *str = Tcl_GetStringFromObj(cd->compDictObj, &len);
-
-	    Tcl_DStringAppend(dsPtr, str, len);
+            if(cd->compDictObj) {
+                int len;
+                const char *str = Tcl_GetStringFromObj(cd->compDictObj, &len);
+                Tcl_DStringAppend(dsPtr, str, len);
+            }
+            return TCL_OK;
 	}
     }
 
     /*
      * The "header" option, which is only valid on inflating gzip channels,
@@ -3618,12 +3620,10 @@
 	if (cd->format == TCL_ZLIB_FORMAT_RAW && cd->compDictObj) {
 	    e = SetInflateDictionary(&cd->inStream, cd->compDictObj);
 	    if (e != Z_OK) {
 		goto error;
 	    }
-	    TclDecrRefCount(cd->compDictObj);
-	    cd->compDictObj = NULL;
 	}
     } else {
 	e = deflateInit2(&cd->outStream, level, Z_DEFLATED, wbits,
 		MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
 	if (e != Z_OK) {

Index: tests/zlib.test
==================================================================
--- tests/zlib.test
+++ tests/zlib.test
@@ -399,10 +399,31 @@
     close $f
     file size $file
 } -cleanup {
     removeFile $file
 } -result 57647
+test zlib-8.17 {Bug dd260aaf: fconfigure} -setup {
+    lassign [chan pipe] inSide outSide
+} -body {
+    zlib push inflate $inSide
+    zlib push deflate $outSide
+    list [chan configure $inSide -dictionary] [chan configure $outSide -dictionary]
+} -cleanup {
+    catch {close $inSide}
+    catch {close $outSide}
+} -result {{} {}}
+test zlib-8.18 {Bug dd260aaf: fconfigure} -setup {
+    lassign [chan pipe] inSide outSide
+} -body {
+    zlib push inflate $inSide -dictionary "one two"
+    zlib push deflate $outSide -dictionary "one two"
+    list [chan configure $inSide -dictionary] [chan configure $outSide -dictionary]
+} -cleanup {
+    catch {close $inSide}
+    catch {close $outSide}
+} -result {{one two} {one two}}
+
 
 test zlib-9.1 "check fcopy with push" -constraints zlib -setup {
     set sfile [makeFile {} testsrc.gz]
     set file [makeFile {} test.gz]
     set f [open $sfile wb]