From phk at FreeBSD.org Mon Dec 1 10:13:04 2025 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 1 Dec 2025 10:13:04 +0000 (UTC) Subject: [master] 243e7c4e3 Polish vmodtool.py a bit Message-ID: <20251201101304.887FA11681D@lists.vinyl-cache.org> commit 243e7c4e3a7d99d1eb3d89fadef2543f45ece461 Author: Poul-Henning Kamp Date: Mon Dec 1 10:11:43 2025 +0000 Polish vmodtool.py a bit diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py index 682138e4b..d03c9fba1 100755 --- a/lib/libvcc/vmodtool.py +++ b/lib/libvcc/vmodtool.py @@ -725,14 +725,14 @@ class FunctionMethodStanzaBase(Stanza): def rstdoc(self, fo, unused_man): super().rstdoc(fo,unused_man) - if (self.restrict is not None): + if self.restrict is not None: fo.write("\nRestricted to: ``%s``.\n\n" % '``, ``'.join(self.restrict.restrict_toks)) self.restrict.rstdoc(fo, unused_man) def json(self, jl): self.proto.jsonproto(jl[-1], self.proto.cname()) - if (self.restrict is not None): + if self.restrict is not None: self.restrict.json(jl) @@ -873,12 +873,12 @@ class RestrictStanza(Stanza): if len(self.toks) < 2: self.syntax() p = self.vcc.contents[-1] - if (isinstance(p, ObjectStanza)): - if(p.methods): + if isinstance(p, ObjectStanza): + if p.methods: p.methods[-1].restrict = self else: err("$Restrict should be after $Method or $Function", False) - elif (isinstance(p, FunctionStanza)): + elif isinstance(p, FunctionStanza): p.restrict = self else : err("$Restrict should be after $Method or $Function", False) @@ -1206,6 +1206,8 @@ class vcc(): # parts from varnish-cache include/generate.py def version(self): srcdir = os.path.dirname(self.inputfile) + if not srcdir: + srcdir = "." pkgstr = "NOVERSION" @@ -1226,13 +1228,30 @@ class vcc(): # parts from varnish-cache include/generate.py def vcs(self): srcdir = os.path.dirname(self.inputfile) + if not srcdir: + srcdir = "." - gitver = subprocess.check_output([ - "git -C %s rev-parse HEAD 2>/dev/null || echo NOGIT" % - srcdir], shell=True, universal_newlines=True).strip() + gitver = "NOGIT" gitfile = "vmod_vcs_version.txt" - if gitver == "NOGIT": + status = subprocess.run( + [ + "git", + "-C", + srcdir, + "rev-parse", + "HEAD" + ], + shell=False, + universal_newlines=True, + capture_output=True + ) + + if status.returncode == 0: + gitver = status.stdout.strip() + with open(gitfile, "w") as fh: + fh.write(gitver) + else: for d in [".", srcdir]: f = os.path.join(d, gitfile) if not os.path.exists(f): @@ -1243,10 +1262,6 @@ class vcc(): gitver = fh.read() fh.close() break; - else: - fh = open(gitfile, "w") - fh.write(gitver) - fh.close() if gitver == "NOGIT": print("WARNING: Neither git nor vmod_vcs_version.txt found.\n\t" + From walid.boudebouda at gmail.com Mon Dec 1 16:44:04 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Mon, 1 Dec 2025 16:44:04 +0000 (UTC) Subject: [master] e8b8e9579 v31.vtc: Add coverage for unreferenced subs Message-ID: <20251201164404.E6EC9123B73@lists.vinyl-cache.org> commit e8b8e95799f5242ec8bde1af8859bec2d8cfc337 Author: Walid Boudebouda Date: Mon Dec 1 17:41:29 2025 +0100 v31.vtc: Add coverage for unreferenced subs diff --git a/bin/varnishtest/tests/v00031.vtc b/bin/varnishtest/tests/v00031.vtc index a6a5d0fbe..a2b439c68 100644 --- a/bin/varnishtest/tests/v00031.vtc +++ b/bin/varnishtest/tests/v00031.vtc @@ -15,6 +15,7 @@ varnish v1 -vcl { varnish v1 -vcl { backend default none; probe p { } + sub sb { } } varnish v1 -cliok "param.set vcc_feature +err_unref" @@ -28,3 +29,7 @@ varnish v1 -errvcl {Unused probe p, defined:} { backend default none; probe p { } } + +varnish v1 -errvcl {Unused sub sb, defined:} { + sub sb { } +} From phk at FreeBSD.org Mon Dec 1 17:27:04 2025 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 1 Dec 2025 17:27:04 +0000 (UTC) Subject: [master] 1959515e8 Revert part of previous commit, to compatible with old versions of python3 Message-ID: <20251201172704.77C8656DA@lists.vinyl-cache.org> commit 1959515e87e0a079ddcf5507c6c2f5637210136a Author: Poul-Henning Kamp Date: Mon Dec 1 17:25:55 2025 +0000 Revert part of previous commit, to compatible with old versions of python3 diff --git a/bin/varnishtest/vtest2 b/bin/varnishtest/vtest2 index 9038ec694..931baeb3c 160000 --- a/bin/varnishtest/vtest2 +++ b/bin/varnishtest/vtest2 @@ -1 +1 @@ -Subproject commit 9038ec69478866fa318b20c64aa89be8a75ba6a6 +Subproject commit 931baeb3cd2c2f57e165285218d4cb22789c9d2b diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py index d03c9fba1..76ae54c6c 100755 --- a/lib/libvcc/vmodtool.py +++ b/lib/libvcc/vmodtool.py @@ -1206,8 +1206,6 @@ class vcc(): # parts from varnish-cache include/generate.py def version(self): srcdir = os.path.dirname(self.inputfile) - if not srcdir: - srcdir = "." pkgstr = "NOVERSION" @@ -1228,30 +1226,13 @@ class vcc(): # parts from varnish-cache include/generate.py def vcs(self): srcdir = os.path.dirname(self.inputfile) - if not srcdir: - srcdir = "." - gitver = "NOGIT" + gitver = subprocess.check_output([ + "git -C %s rev-parse HEAD 2>/dev/null || echo NOGIT" % + srcdir], shell=True, universal_newlines=True).strip() gitfile = "vmod_vcs_version.txt" - status = subprocess.run( - [ - "git", - "-C", - srcdir, - "rev-parse", - "HEAD" - ], - shell=False, - universal_newlines=True, - capture_output=True - ) - - if status.returncode == 0: - gitver = status.stdout.strip() - with open(gitfile, "w") as fh: - fh.write(gitver) - else: + if gitver == "NOGIT": for d in [".", srcdir]: f = os.path.join(d, gitfile) if not os.path.exists(f): @@ -1262,6 +1243,10 @@ class vcc(): gitver = fh.read() fh.close() break; + else: + fh = open(gitfile, "w") + fh.write(gitver) + fh.close() if gitver == "NOGIT": print("WARNING: Neither git nor vmod_vcs_version.txt found.\n\t" + From nils.goroll at uplex.de Tue Dec 2 10:05:04 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 2 Dec 2025 10:05:04 +0000 (UTC) Subject: [master] 3e1a23545 doc: Document status quo regarding == and != operator behavior Message-ID: <20251202100504.B168D1208B4@lists.vinyl-cache.org> commit 3e1a235457965442efecf3eb393aa597ebf476f9 Author: Nils Goroll Date: Tue Dec 2 11:02:13 2025 +0100 doc: Document status quo regarding == and != operator behavior diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index aae98629e..4814bc92d 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -103,6 +103,27 @@ The following operators are available in VCL: ``&&`` / ``||`` Logical and/or. +On Equality +~~~~~~~~~~~ + +In this section, "compare equal" means that the ``==`` operator returns ``true`` +and, conversely, the ``!=`` operator returns ``false``. + +The VCL types ``INT``, ``DURATION``, ``BYTES``, ``REAL`` and ``TIME`` compare +equal if their values compare equal numerically. + +Notice that ``DURATION``, ``REAL`` and ``TIME`` are represented as floating +point numbers, and hence testing for (in)equality might be unreliable. + +``IP`` compares equal for equal address. + +``STRING`` and ``STRANDS`` compare equal if the represented strings are equal. + +``BOOL`` compares equal if the truth value is the same. + +The VCL types ``BACKEND``, ``ACL``, ``PROBE``, ``STEVEDORE``, ``SUB`` and +``INSTANCE`` compare equal if they represent the same object. Different objects +with the same properties will never compare equal. Conditionals ------------ From nils.goroll at uplex.de Tue Dec 2 16:47:04 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 2 Dec 2025 16:47:04 +0000 (UTC) Subject: [master] 3af5034d5 Update vtest2 Message-ID: <20251202164704.C882E103D59@lists.vinyl-cache.org> commit 3af5034d59e1eaf18ee732c4043384b1a0a7ad50 Author: Nils Goroll Date: Tue Dec 2 17:46:33 2025 +0100 Update vtest2 diff --git a/bin/varnishtest/vtest2 b/bin/varnishtest/vtest2 index 931baeb3c..9038ec694 160000 --- a/bin/varnishtest/vtest2 +++ b/bin/varnishtest/vtest2 @@ -1 +1 @@ -Subproject commit 931baeb3cd2c2f57e165285218d4cb22789c9d2b +Subproject commit 9038ec69478866fa318b20c64aa89be8a75ba6a6 From nils.goroll at uplex.de Tue Dec 2 17:00:06 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 2 Dec 2025 17:00:06 +0000 (UTC) Subject: [master] d6983f5a1 Update vtest2 Message-ID: <20251202170006.9FAC310461C@lists.vinyl-cache.org> commit d6983f5a110a88f698a0f807c1d34bfa642441ef Author: Nils Goroll Date: Tue Dec 2 17:59:41 2025 +0100 Update vtest2 diff --git a/bin/varnishtest/vtest2 b/bin/varnishtest/vtest2 index 9038ec694..cffabbb55 160000 --- a/bin/varnishtest/vtest2 +++ b/bin/varnishtest/vtest2 @@ -1 +1 @@ -Subproject commit 9038ec69478866fa318b20c64aa89be8a75ba6a6 +Subproject commit cffabbb558599869fae2425bab76645d67e845cc From walid.boudebouda at gmail.com Wed Dec 3 09:58:05 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 3 Dec 2025 09:58:05 +0000 (UTC) Subject: [master] 1cd5efac3 vcc_parse: Point to the right symbol in error message Message-ID: <20251203095805.61A9763EAC@lists.vinyl-cache.org> commit 1cd5efac35e27076cd66378fc436208bd4bdeb47 Author: Walid Boudebouda Date: Wed Dec 3 10:50:07 2025 +0100 vcc_parse: Point to the right symbol in error message VCC_SymbolGet moves the cursor to the next symbol. diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c index f579e2d0b..e00b133e0 100644 --- a/lib/libvcc/vcc_parse.c +++ b/lib/libvcc/vcc_parse.c @@ -188,13 +188,13 @@ vcc_Compound(struct vcc *tl) SYMTAB_PARTIAL, XREF_NONE); if (sym == NULL) { VSB_printf(tl->sb, "Symbol not found.\n"); - vcc_ErrWhere(tl, tl->t); + vcc_ErrWhere(tl, t); return; } if (sym->action == NULL) { VSB_printf(tl->sb, "Symbol cannot be used here.\n"); - vcc_ErrWhere(tl, tl->t); + vcc_ErrWhere(tl, t); return; } if (sym->action_mask != 0) From nils.goroll at uplex.de Wed Dec 3 15:31:05 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 3 Dec 2025 15:31:05 +0000 (UTC) Subject: [master] a2ef267af Revert "vcc: make vgc probes actual pointers to compound literals" Message-ID: <20251203153105.CDD7110D829@lists.vinyl-cache.org> commit a2ef267af8142ff43427c485feb6d82c3991e7f4 Author: Nils Goroll Date: Wed Dec 3 16:24:25 2025 +0100 Revert "vcc: make vgc probes actual pointers to compound literals" The compound literal is not supported as a constant expression by older compilers, and trying to avoid it (by defining the probe as a struct literal and then taking a pointer to it) comes with another set of problems around unreferenced symbols. So all in all I must say that the single element array "hack" has many more benefits than were apparent to me and I now changed my mind that they actually are, objectively, the better solution - except for the fact that arrays can not be compared, but that will be fixed with #4418. This reverts commit 7a88cab9fe0ea567e3ceac9fa9a9cd7108e85504. Ref #4418 Ref #4410 diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 8feb20df4..90d0f6bad 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -214,8 +214,7 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **namep) bprintf(buf, "vgc_probe__%d", tl->nprobe++); name = buf; } - Fh(tl, 0, "static const struct vrt_backend_probe * const %s =\n", name); - Fh(tl, 0, " &(const struct vrt_backend_probe){\n"); + Fh(tl, 0, "static const struct vrt_backend_probe %s[] = {{\n", name); Fh(tl, 0, "\t.magic = VRT_BACKEND_PROBE_MAGIC,\n"); if (sym != NULL) { Fh(tl, 0, "\t.vcl_name = \"%s\",\n", sym->name); @@ -340,7 +339,7 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **namep) if (status > 0) Fh(tl, 0, "\t.exp_status = %u,\n", status); Fh(tl, 0, "\t.exp_close = %u,\n", exp_close); - Fh(tl, 0, "};\n"); + Fh(tl, 0, "}};\n"); SkipToken(tl, '}'); } From walid.boudebouda at gmail.com Wed Dec 3 15:36:04 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 3 Dec 2025 15:36:04 +0000 (UTC) Subject: [master] 09f8b3423 vcc: New VPI_Ptr_Cmp function Message-ID: <20251203153604.DF84910DC34@lists.vinyl-cache.org> commit 09f8b3423ce7ef5b3def25cf0aff2e0f4f41d179 Author: Walid Boudebouda Date: Thu Nov 27 17:10:07 2025 +0100 vcc: New VPI_Ptr_Cmp function This is just a wrapper around pointers comparison, it avoids C-compiler failures like: error: self-comparison always evaluates to true error: array comparison always evaluates to false Fixes: #4410 diff --git a/bin/varnishd/cache/cache_vpi.c b/bin/varnishd/cache/cache_vpi.c index 9b3b3db1c..5ed3fdbf0 100644 --- a/bin/varnishd/cache/cache_vpi.c +++ b/bin/varnishd/cache/cache_vpi.c @@ -302,3 +302,10 @@ VPI_Call_End(VRT_CTX, unsigned n) AN(vbm); vbit_clr(vbm, n); } + +VCL_BOOL +VPI_PtrCmp(const void *p1, const void *p2) +{ + + return (p1 != p2); +} diff --git a/bin/varnishtest/tests/r04417.vtc b/bin/varnishtest/tests/r04417.vtc index 2fc299279..52347e9ff 100644 --- a/bin/varnishtest/tests/r04417.vtc +++ b/bin/varnishtest/tests/r04417.vtc @@ -11,11 +11,25 @@ varnish v1 -vcl { probe p1 { } probe p2 { } + acl a1 { "localhost"; } + sub vcl_recv { return (synth(200)); } sub vcl_synth { + if (a1 == a1) { + set resp.http.be-cmp = "true"; + } + if (be == be) { + set resp.http.be-cmp = "true"; + } + if (p1 == p1) { + set resp.http.pb-cmp = "true"; + } + if (p1 == p2) { + set resp.http.false = "false"; + } set resp.http.self-cmp = (p1 == p1); set resp.http.cmp = (p1 == p2); set resp.http.name = p1 + "/" + p2; @@ -28,4 +42,7 @@ client c1 { expect resp.http.cmp == false expect resp.http.self-cmp == true expect resp.http.name == p1/p2 + expect resp.http.be-cmp == "true" + expect resp.http.pb-cmp == "true" + expect resp.http.false == } -run diff --git a/include/vcc_interface.h b/include/vcc_interface.h index 529ab9ed1..3304ca289 100644 --- a/include/vcc_interface.h +++ b/include/vcc_interface.h @@ -118,3 +118,4 @@ enum vcl_func_fail_e VPI_Call_Check(VRT_CTX, const struct VCL_conf *conf, unsigned methods, unsigned n); void VPI_Call_Begin(VRT_CTX, unsigned n); void VPI_Call_End(VRT_CTX, unsigned n); +VCL_BOOL VPI_PtrCmp(const void *p1, const void *p2); \ No newline at end of file diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 280476245..4f1d41c95 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -1215,6 +1215,10 @@ cmp_string(struct vcc *tl, struct expr **e, const struct cmps *cp) } } +#define PTR_REL(typ) \ + {typ, T_EQ, cmp_simple, "!VPI_PtrCmp(\v1, \v2)" }, \ + {typ, T_NEQ, cmp_simple, "VPI_PtrCmp(\v1, \v2)" } + #define IDENT_REL(typ) \ {typ, T_EQ, cmp_simple, "(\v1 == \v2)" }, \ {typ, T_NEQ, cmp_simple, "(\v1 != \v2)" } @@ -1232,9 +1236,9 @@ static const struct cmps vcc_cmps[] = { NUM_REL(BYTES), NUM_REL(REAL), NUM_REL(TIME), - IDENT_REL(BACKEND), - IDENT_REL(ACL), - IDENT_REL(PROBE), + PTR_REL(BACKEND), + PTR_REL(ACL), + PTR_REL(PROBE), IDENT_REL(STEVEDORE), IDENT_REL(SUB), IDENT_REL(INSTANCE), From nils.goroll at uplex.de Wed Dec 3 16:39:05 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 3 Dec 2025 16:39:05 +0000 (UTC) Subject: [master] 7287112b9 polish previous Message-ID: <20251203163905.D7072110171@lists.vinyl-cache.org> commit 7287112b92e9cb777fb8da19c6c772e6f54dd7a5 Author: Nils Goroll Date: Wed Dec 3 17:37:54 2025 +0100 polish previous add newline, should avoid error on solaris vtesters: "../../include/vcc_interface.h", line 121: newline not last character in file (E_NEWLINE_NOT_LAST) diff --git a/include/vcc_interface.h b/include/vcc_interface.h index 3304ca289..586961122 100644 --- a/include/vcc_interface.h +++ b/include/vcc_interface.h @@ -118,4 +118,4 @@ enum vcl_func_fail_e VPI_Call_Check(VRT_CTX, const struct VCL_conf *conf, unsigned methods, unsigned n); void VPI_Call_Begin(VRT_CTX, unsigned n); void VPI_Call_End(VRT_CTX, unsigned n); -VCL_BOOL VPI_PtrCmp(const void *p1, const void *p2); \ No newline at end of file +VCL_BOOL VPI_PtrCmp(const void *p1, const void *p2); From phk at FreeBSD.org Mon Dec 8 13:19:04 2025 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 8 Dec 2025 13:19:04 +0000 (UTC) Subject: [master] d7cb65d04 Add VSB_QUOTE_ABBREVIATE which appreviates the input with "[...]" if it is longer than specified. Message-ID: <20251208131904.784121137AE@lists.vinyl-cache.org> commit d7cb65d0423c2bb5552eebcef9fb02caf04383c7 Author: Poul-Henning Kamp Date: Mon Dec 8 12:46:01 2025 +0000 Add VSB_QUOTE_ABBREVIATE which appreviates the input with "[...]" if it is longer than specified. diff --git a/include/vsb.h b/include/vsb.h index f8ab8b150..6787a587c 100644 --- a/include/vsb.h +++ b/include/vsb.h @@ -123,6 +123,11 @@ void VSB_destroy(struct vsb **); * Not valid with VSB_QUOTE_JSON and VSB_QUOTE_HEX */ +#define VSB_QUOTE_ABBREVIATE 64 + /* + * Abbreviate with "[...]" If longer than specified length + */ + void VSB_quote_pfx(struct vsb *, const char*, const void *, int len, int how); void VSB_quote(struct vsb *, const void *, int len, int how); diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c index 2a405987a..42ae51c7e 100644 --- a/lib/libvarnish/vsb.c +++ b/lib/libvarnish/vsb.c @@ -543,6 +543,15 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how) how |= VSB_QUOTE_NONL; assert(p != NULL); + if (how & VSB_QUOTE_ABBREVIATE) { + assert (len > 5); + if (strlen(v) < len) { + len = strlen(v); + how &= ~VSB_QUOTE_ABBREVIATE; + } else { + len -= 5; + } + } if (len == -1) len = strlen(v); @@ -582,6 +591,8 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how) if (!quote) { VSB_bcat(s, p, len); + if (how & VSB_QUOTE_ABBREVIATE) + VSB_cat(s, "[...]"); if ((how & VSB_QUOTE_NONL) && p[len-1] != '\n') (void)VSB_putc(s, '\n'); @@ -640,6 +651,8 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how) break; } } + if (how & VSB_QUOTE_ABBREVIATE) + VSB_cat(s, "[...]"); if (how & VSB_QUOTE_CSTR) VSB_putc(s, '"'); if ((how & VSB_QUOTE_NONL) && !nl) diff --git a/lib/libvarnish/vsb_test.c b/lib/libvarnish/vsb_test.c index 373e4bada..593c05cd3 100644 --- a/lib/libvarnish/vsb_test.c +++ b/lib/libvarnish/vsb_test.c @@ -126,6 +126,11 @@ static struct tc tcs[] = { -1, "\n\t", "PFX\nPFX\\t\n" }, + { + VSB_QUOTE_CSTR | VSB_QUOTE_ABBREVIATE, + 11, "Hello World\n", + "PFX\"Hello [...]\"", + }, { 0, -1, NULL, NULL } @@ -180,6 +185,8 @@ main(int argc, char *argv[]) VSB_cat(vsbo, "\n\tVSB_QUOTE_UNSAFE"); if (tc->how & VSB_QUOTE_ESCHEX) VSB_cat(vsbo, "\n\tVSB_QUOTE_ESCHEX"); + if (tc->how & VSB_QUOTE_ABBREVIATE) + VSB_cat(vsbo, "\n\tVSB_QUOTE_ABBREVIATE"); VSB_cat(vsbo, "\n\n"); err = 1; } From phk at FreeBSD.org Mon Dec 8 13:19:04 2025 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 8 Dec 2025 13:19:04 +0000 (UTC) Subject: [master] 70631ecbf Put the abbreviation marker outside the (optional) double quotes, and be consistent about the order of the ending. Message-ID: <20251208131904.8BBBD1137B1@lists.vinyl-cache.org> commit 70631ecbff738f8f0ed2ff0223dfb768b4d825eb Author: Poul-Henning Kamp Date: Mon Dec 8 12:54:07 2025 +0000 Put the abbreviation marker outside the (optional) double quotes, and be consistent about the order of the ending. diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c index 42ae51c7e..bdf42594e 100644 --- a/lib/libvarnish/vsb.c +++ b/lib/libvarnish/vsb.c @@ -591,13 +591,13 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how) if (!quote) { VSB_bcat(s, p, len); + if (how & VSB_QUOTE_CSTR) + VSB_putc(s, '"'); if (how & VSB_QUOTE_ABBREVIATE) VSB_cat(s, "[...]"); if ((how & VSB_QUOTE_NONL) && p[len-1] != '\n') (void)VSB_putc(s, '\n'); - if (how & VSB_QUOTE_CSTR) - VSB_putc(s, '"'); return; } @@ -651,10 +651,10 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how) break; } } - if (how & VSB_QUOTE_ABBREVIATE) - VSB_cat(s, "[...]"); if (how & VSB_QUOTE_CSTR) VSB_putc(s, '"'); + if (how & VSB_QUOTE_ABBREVIATE) + VSB_cat(s, "[...]"); if ((how & VSB_QUOTE_NONL) && !nl) VSB_putc(s, '\n'); } diff --git a/lib/libvarnish/vsb_test.c b/lib/libvarnish/vsb_test.c index 593c05cd3..7353dc73b 100644 --- a/lib/libvarnish/vsb_test.c +++ b/lib/libvarnish/vsb_test.c @@ -129,7 +129,7 @@ static struct tc tcs[] = { { VSB_QUOTE_CSTR | VSB_QUOTE_ABBREVIATE, 11, "Hello World\n", - "PFX\"Hello [...]\"", + "PFX\"Hello \"[...]", }, { 0, -1, NULL, NULL From phk at FreeBSD.org Mon Dec 8 13:19:04 2025 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 8 Dec 2025 13:19:04 +0000 (UTC) Subject: [master] 23ada53ba Simplify vpi_ref_panic() with VSB_QUOTE_ABBREVIATE Message-ID: <20251208131904.A59F51137B4@lists.vinyl-cache.org> commit 23ada53ba73331ff4ea50a9e5c8bb9d644fa2dfd Author: Poul-Henning Kamp Date: Mon Dec 8 13:17:28 2025 +0000 Simplify vpi_ref_panic() with VSB_QUOTE_ABBREVIATE diff --git a/bin/varnishd/cache/cache_vpi.c b/bin/varnishd/cache/cache_vpi.c index 5ed3fdbf0..d7fea778b 100644 --- a/bin/varnishd/cache/cache_vpi.c +++ b/bin/varnishd/cache/cache_vpi.c @@ -84,10 +84,7 @@ vpi_ref_panic(struct vsb *vsb, unsigned n, const struct vcl *vcl) { const struct VCL_conf *conf = NULL; const struct vpi_ref *ref; - const char *p, *src = NULL; - const int lim = 40; - const char *abbstr = "[...]"; - char buf[lim + sizeof(abbstr)]; + const char *src = NULL; int w = 0; AN(vsb); @@ -124,20 +121,10 @@ vpi_ref_panic(struct vsb *vsb, unsigned n, const struct vcl *vcl) if (src != NULL) { w = strlen(src); assert(w > 0); - if (ref->offset >= (unsigned)w) + if (ref->offset >= (unsigned)w) { src = NULL; - } - if (src != NULL) { - src += ref->offset; - p = strchr(src, '\n'); - if (p != NULL) - w = p - src; - else - w -= ref->offset; - if (w > lim) { - w = snprintf(buf, sizeof buf, "%.*s%s", - lim, src, abbstr); - src = buf; + } else { + src += ref->offset; } } @@ -145,8 +132,8 @@ vpi_ref_panic(struct vsb *vsb, unsigned n, const struct vcl *vcl) VSB_printf(vsb, "line = %u,\n", ref->line); VSB_printf(vsb, "pos = %u,\n", ref->pos); if (src != NULL) { - VSB_cat(vsb, "src = "); - VSB_quote(vsb, src, w, VSB_QUOTE_CSTR); + VSB_cat(vsb, "src = "); + VSB_quote(vsb, src, 40, VSB_QUOTE_CSTR | VSB_QUOTE_ABBREVIATE); VSB_putc(vsb, '\n'); } else { VSB_printf(vsb, "token = \"%s\"\n", ref->token); From phk at FreeBSD.org Mon Dec 8 13:19:04 2025 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 8 Dec 2025 13:19:04 +0000 (UTC) Subject: [master] eb0a7d33e Use bprintf() instead of handrolling it. Message-ID: <20251208131904.BC8431137B9@lists.vinyl-cache.org> commit eb0a7d33eed30a443ed7cf38ad357fe4c6bc7500 Author: Poul-Henning Kamp Date: Mon Dec 8 13:18:30 2025 +0000 Use bprintf() instead of handrolling it. diff --git a/vmod/vmod_directors_shard_cfg.c b/vmod/vmod_directors_shard_cfg.c index 5f0c2f559..c464746f5 100644 --- a/vmod/vmod_directors_shard_cfg.c +++ b/vmod/vmod_directors_shard_cfg.c @@ -261,8 +261,7 @@ shardcfg_hashcircle(struct sharddir *shardd) unsigned h; uint32_t i, j, n_points, r, rmax; const char *ident; - const int len = 12; // log10(UINT32_MAX) + 2; - char s[len]; + char s[12]; // log10(UINT32_MAX) + 2; CHECK_OBJ_NOTNULL(shardd, SHARDDIR_MAGIC); AZ(shardd->hashcircle); @@ -294,7 +293,7 @@ shardcfg_hashcircle(struct sharddir *shardd) r = vmin_t(uint32_t, b->replicas, rmax); for (j = 0; j < r; j++) { - assert(snprintf(s, len, "%d", j) < len); + bprintf(s, "%d", j); assert (i < n_points); shardd->hashcircle[i].point = VRT_HashStrands32(TOSTRANDS(2, ident, s)); From walid.boudebouda at gmail.com Mon Dec 8 14:34:04 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Mon, 8 Dec 2025 14:34:04 +0000 (UTC) Subject: [master] e0169b190 vcc: New "unused" toplev Message-ID: <20251208143404.EE60D1168BF@lists.vinyl-cache.org> commit e0169b190e09ee8078d69ccbe2f54d68a63b9fca Author: Walid Boudebouda Date: Mon Dec 1 18:40:27 2025 +0100 vcc: New "unused" toplev This allows a finer grained control over symbol references compared to the existing vcc_feature flag -err_unref. Refs #4410 diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c index e00b133e0..d3b045dce 100644 --- a/lib/libvcc/vcc_parse.c +++ b/lib/libvcc/vcc_parse.c @@ -212,6 +212,36 @@ vcc_Compound(struct vcc *tl) } } +/*-------------------------------------------------------------------- + */ + +static void +vcc_ParseUnused(struct vcc *tl) +{ + struct symbol *sym; + struct token *t; + struct inifin *ifp; + + vcc_NextToken(tl); + ExpectErr(tl, ID); + t = tl->t; + sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_NONE, SYMTAB_EXISTING, XREF_REF); + ERRCHK(tl); + AN(sym); + if (sym->kind != SYM_BACKEND && sym->kind != SYM_PROBE && + sym->kind != SYM_ACL && sym->kind != SYM_SUB) { + vcc_ErrWhere2(tl, t, tl->t); + VSB_printf(tl->sb, "Symbol '%s' cannot follow 'unused'.\n", + sym->name); + return; + } + AN(sym->rname); + ifp = New_IniFin(tl); + VSB_printf(ifp->ini, "\t(void)%s;\n", sym->rname); + ifp->ignore_errors = 1; + SkipToken(tl, ';'); +} + /*-------------------------------------------------------------------- * SYNTAX: * Function: @@ -348,6 +378,7 @@ vcc_ParseVcl(struct vcc *tl) * Backend definitions * VMOD import directives * VCL version declarations + * Unused symbols declarations * End of input */ @@ -365,6 +396,7 @@ static struct toplev { { "probe", vcc_ParseProbe, VCL_41, VCL_HIGH }, { "import", vcc_ParseImport, VCL_41, VCL_HIGH }, { "vcl", vcc_ParseVcl, VCL_41, VCL_HIGH }, + { "unused", vcc_ParseUnused, VCL_41, VCL_HIGH}, { NULL, NULL } }; From walid.boudebouda at gmail.com Mon Dec 8 14:34:05 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Mon, 8 Dec 2025 14:34:05 +0000 (UTC) Subject: [master] 73c3a1c95 tests: Add coverage for the new vcc 'unused' directive Message-ID: <20251208143405.12B8E1168C2@lists.vinyl-cache.org> commit 73c3a1c957c78ec7b031bc76bb2855f1f1de35e9 Author: Walid Boudebouda Date: Tue Dec 2 10:02:50 2025 +0100 tests: Add coverage for the new vcc 'unused' directive diff --git a/bin/varnishtest/tests/v00075.vtc b/bin/varnishtest/tests/v00075.vtc new file mode 100644 index 000000000..1aedba1e3 --- /dev/null +++ b/bin/varnishtest/tests/v00075.vtc @@ -0,0 +1,33 @@ +varnishtest "Test vcc 'unused' directive" + + +varnish v1 -vcl { + backend b1 { .host = "localhost"; } + + probe p1 { } + + acl acl1 { "localhost"; } + + sub sb {} + + unused p1; + unused b1; + unused acl1; + unused sb; +} -start + +varnish v1 -errvcl "Symbol not found: 'nonexistentsymbol'" { + unused nonexistentsymbol; +} + +varnish v1 -errvcl "Expected ID got ';'" { + unused; +} + +varnish v1 -errvcl "Symbol 'req' cannot follow 'unused'" { + unused req; +} + +varnish v1 -errvcl "Symbol 'backend' cannot follow 'unused'" { + unused bereq.backend; +} \ No newline at end of file From walid.boudebouda at gmail.com Mon Dec 8 14:34:05 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Mon, 8 Dec 2025 14:34:05 +0000 (UTC) Subject: [master] 6b53be1a0 vcl.rst: Document the new vcl 'unused' directive Message-ID: <20251208143405.5491C1168C6@lists.vinyl-cache.org> commit 6b53be1a05140de149a00747ca4b7cdc344c177d Author: Walid Boudebouda Date: Tue Dec 2 10:19:57 2025 +0100 vcl.rst: Document the new vcl 'unused' directive diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 4814bc92d..f3f779a0d 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -436,6 +436,28 @@ subroutine's name:: call pipe_if_local; } +Symbol references +----------------- + +Some VCL symbols are subject to reference counting, and would trigger a vcl +compiler error if they were declared but not used. One way to turn these errors +into warnings is to add ``-p vcc_feature=-err_unref`` to your ``varnishd`` +command line. This will disable the error globally for all symbols in every VCL +that is compiled. + +If you only want to disable the error for some specific symbols, the ``unused`` +keyword can be used to mark such symbols as intentionally unused:: + + backend b1 { .host = "localhost"; } + probe p1 { } + acl acl1 { "localhost"; } + sub sb {} + + unused b1; + unused p1; + unused acl1; + unused sb; + Return statements ~~~~~~~~~~~~~~~~~ From nils.goroll at uplex.de Mon Dec 8 15:02:05 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 8 Dec 2025 15:02:05 +0000 (UTC) Subject: [master] d2acc546a Move VEXT code to mgt Message-ID: <20251208150205.3DA92117DBB@lists.vinyl-cache.org> commit d2acc546ab3651150519fad8af0e741f5431018b Author: Nils Goroll Date: Fri Nov 28 16:22:40 2025 +0100 Move VEXT code to mgt VEXTs get loaded early after the worker process fork, but that code is owned by mgt and, after that, the cache worker has no business in VEXTs. The variable rename is to avoid shadowing diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am index 0d60f1b18..bbda7dea9 100644 --- a/bin/varnishd/Makefile.am +++ b/bin/varnishd/Makefile.am @@ -63,7 +63,6 @@ varnishd_SOURCES = \ cache/cache_ws_common.c \ common/common_vsc.c \ common/common_vsmw.c \ - common/common_vext.c \ hash/hash_classic.c \ hash/hash_critbit.c \ hash/hash_simple_list.c \ @@ -99,6 +98,7 @@ varnishd_SOURCES = \ mgt/mgt_util.c \ mgt/mgt_vcc.c \ mgt/mgt_vcl.c \ + mgt/mgt_vext.c \ proxy/cache_proxy_proto.c \ proxy/cache_proxy.h \ storage/mgt_stevedore.c \ diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index aedc7c295..9868ab5cb 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -134,12 +134,3 @@ extern vsm_lock_f *vsc_lock; extern vsm_lock_f *vsc_unlock; extern vsm_lock_f *vsmw_lock; extern vsm_lock_f *vsmw_unlock; - -/* common/common_vext.c */ - -void vext_argument(const char *); -void vext_copyin(struct vsb *); -void vext_load(void); -void vext_cleanup(int); -typedef void vext_iter_f(const char *, void *); -void vext_iter(vext_iter_f *func, void *); diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 3f20777c7..826678000 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -263,3 +263,11 @@ pthread_create(void) #define MGT_EXPERIMENT(x) COM_EXPERIMENT(mgt_param.experimental_bits, x) #define MGT_DO_DEBUG(x) COM_DO_DEBUG(mgt_param.debug_bits, x) #define MGT_VCC_FEATURE(x) COM_VCC_FEATURE(mgt_param.vcc_feature_bits, x) + +/* mgt_vext.c */ +void vext_argument(const char *); +void vext_copyin(struct vsb *); +void vext_load(void); +void vext_cleanup(int); +typedef void vext_iter_f(const char *, void *); +void vext_iter(vext_iter_f *func, void *); diff --git a/bin/varnishd/common/common_vext.c b/bin/varnishd/mgt/mgt_vext.c similarity index 97% rename from bin/varnishd/common/common_vext.c rename to bin/varnishd/mgt/mgt_vext.c index 169cb13ee..30c0b2661 100644 --- a/bin/varnishd/common/common_vext.c +++ b/bin/varnishd/mgt/mgt_vext.c @@ -40,7 +40,8 @@ #include #include -#include "vdef.h" +#include "mgt.h" + #include "vas.h" #include "miniobj.h" #include "vav.h" @@ -48,7 +49,7 @@ #include "vrnd.h" #include "vsb.h" -#include "heritage.h" +#include "common/heritage.h" struct vext { unsigned magic; @@ -95,7 +96,7 @@ vext_iter(vext_iter_f *func, void *priv) } void -vext_copyin(struct vsb *vident) +vext_copyin(struct vsb *vi) { struct vext *vp; const char *p; @@ -115,7 +116,7 @@ vext_copyin(struct vsb *vident) p++; else p = vp->argv[0]; - VSB_printf(vident, ",-E%s", p); + VSB_printf(vi, ",-E%s", p); VSB_printf(vp->vsb, "vext_cache/%s,", p); for (i = 0; i < 8; i++) { AZ(VRND_RandomCrypto(&u, sizeof u)); From nils.goroll at uplex.de Mon Dec 8 15:02:05 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 8 Dec 2025 15:02:05 +0000 (UTC) Subject: [master] 84708f9fb Add simplified VEXT loading as -E Message-ID: <20251208150205.56254117DBE@lists.vinyl-cache.org> commit 84708f9fb2cc8b4feaa9fd0a0a5dca79af130d2d Author: Nils Goroll Date: Fri Nov 28 17:14:20 2025 +0100 Add simplified VEXT loading as -E Similar to how vmods can be loaded by their base name, we now support loading extensions using, for example, -Estd: If a path is specified (-E argument contains "/"), it is taken literally as before. Otherwise, the -E argument is expanded to libvmod_%s.so and a search in vmod_path is conducted. diff --git a/bin/varnishd/mgt/mgt_vext.c b/bin/varnishd/mgt/mgt_vext.c index 30c0b2661..c2f61f576 100644 --- a/bin/varnishd/mgt/mgt_vext.c +++ b/bin/varnishd/mgt/mgt_vext.c @@ -45,6 +45,7 @@ #include "vas.h" #include "miniobj.h" #include "vav.h" +#include "vfil.h" #include "vqueue.h" #include "vrnd.h" #include "vsb.h" @@ -65,10 +66,25 @@ struct vext { static VTAILQ_HEAD(,vext) vext_list = VTAILQ_HEAD_INITIALIZER(vext_list); +static int +vext_tryopen(void *priv, const char *fn) +{ + struct vext *vp; + + CAST_OBJ_NOTNULL(vp, priv, VEXT_MAGIC); + vp->fd = open(fn, O_RDONLY); + if (vp->fd < 0) + return (1); + return (0); +} + void vext_argument(const char *arg) { struct vext *vp; + char fn[1024]; + char *fno = NULL; + struct vfil_path *vmod_path = NULL; fprintf(stderr, "EEE <%s>\n", arg); ALLOC_OBJ(vp, VEXT_MAGIC); @@ -79,11 +95,20 @@ vext_argument(const char *arg) ARGV_ERR("\tParse failure in argument: %s\n\t%s\n", arg, vp->argv[0]); VTAILQ_INSERT_TAIL(&vext_list, vp, list); - fprintf(stderr, "eee <%s>\n", vp->argv[1]); - vp->fd = open(vp->argv[1], O_RDONLY); - if (vp->fd < 0) + + if (strchr(vp->argv[1], '/')) + bstrcpy(fn, vp->argv[1]); + else + bprintf(fn, "libvmod_%s.so", vp->argv[1]); + + VFIL_setpath(&vmod_path, mgt_vmod_path); + if (VFIL_searchpath(vmod_path, vext_tryopen, vp, fn, &fno)) { ARGV_ERR("\tCannot open %s\n\t%s\n", - vp->argv[1], strerror(errno)); + fn, strerror(errno)); + } + + fprintf(stderr, "eee <%s>\n", fno); + free(fno); } void @@ -115,7 +140,7 @@ vext_copyin(struct vsb *vi) if (p != NULL) p++; else - p = vp->argv[0]; + p = vp->argv[1]; VSB_printf(vi, ",-E%s", p); VSB_printf(vp->vsb, "vext_cache/%s,", p); for (i = 0; i < 8; i++) { diff --git a/bin/varnishtest/tests/x00000.vtc b/bin/varnishtest/tests/x00000.vtc index 7069f4c2c..5baea5986 100644 --- a/bin/varnishtest/tests/x00000.vtc +++ b/bin/varnishtest/tests/x00000.vtc @@ -2,7 +2,7 @@ varnishtest "Test VMOD import from VEXT" feature topbuild -server s1 { +server s1 -repeat 2 { rxreq txresp } -start @@ -23,3 +23,26 @@ client c1 { rxresp expect resp.http.foobar ~ [0-9] } -run + +varnish v1 -stop + +varnish v2 \ + -arg "-Estd" \ + -vcl+backend { + import std; + + sub vcl_deliver { + set resp.http.foobar = std.random(10,99); + } + } -start + +client c2 -connect ${v2_sock} { + txreq + rxresp + expect resp.http.foobar ~ [0-9] +} -run + +varnish v2 -stop + +shell -err -match {Error:.*Cannot open libvmod_std.so} \ + "varnishd -pvmod_path=/nonexistent -Estd -b none -a ${tmpdir}/vtc.sock" From nils.goroll at uplex.de Mon Dec 8 15:02:05 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 8 Dec 2025 15:02:05 +0000 (UTC) Subject: [master] 107f60674 suppress complains about insignificant leak Message-ID: <20251208150205.6B42D117DC2@lists.vinyl-cache.org> commit 107f60674d3b0d57ea265eac5bb84d40eed125d6 Author: Nils Goroll Date: Wed Dec 3 15:37:51 2025 +0100 suppress complains about insignificant leak diff --git a/tools/lsan.suppr b/tools/lsan.suppr index cce56c4f7..bcf95a2a3 100644 --- a/tools/lsan.suppr +++ b/tools/lsan.suppr @@ -8,6 +8,7 @@ leak:HSH_config leak:vcc_ leak:VSL_Setup leak:WRK_BgThread +leak:vext_argument # leak:VBH_new # ev From nils.goroll at uplex.de Mon Dec 8 15:02:05 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 8 Dec 2025 15:02:05 +0000 (UTC) Subject: [master] 7fb27fbbb document varnishd -E parameter Message-ID: <20251208150205.8173C117DC8@lists.vinyl-cache.org> commit 7fb27fbbbba7b884e3c9afe8a972833910ffa04c Author: Nils Goroll Date: Mon Dec 8 16:00:30 2025 +0100 document varnishd -E parameter It was mentioned in usage, but not in the actual reference documentation. diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 8afe6dde0..bc4ec89c6 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -25,6 +25,7 @@ varnishd [-b [host[:port]|path]] [-C] [-d] + [-E extension] [-F] [-f config] [-h type[,options]] @@ -229,6 +230,22 @@ Operations options Execute the management commands in the file given as ``clifile`` before the worker process starts, see `CLI Command File`_. +-E extension + + Load the named extension. Extensions are modules (VMODs) which can modify + varnishd behavior outside VCL, for example by adding storage- or protocol + implementations. Extensions are always also VMODs, even if they do not provide + any functionality to VCL, but in most cases they will. + + Any VMOD can be loaded as an extension, in which case it is simply pre-loaded + at startup and prevented from ever getting unloaded. + + If `extension` contains any slashes ``/``, it is taken as an abslute path. + Otherwise, for `extention` ``ext``, a ``vmod_ext.so`` is searched for in + ``vmod_path``. + + ``varnishd`` startup fails if loading the extension fails for any reason. + Tuning options -------------- From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] 27c493f5f Cherry-pick the trivial parts of zlib 1.2.13 Message-ID: <20251210154306.2097910292F@lists.vinyl-cache.org> commit 27c493f5f79151eefa88fefe4125683423c5bbf5 Author: Poul-Henning Kamp Date: Mon Dec 19 10:36:53 2022 +0000 Cherry-pick the trivial parts of zlib 1.2.13 diff --git a/lib/libvgz/crc32.c b/lib/libvgz/crc32.c index 0f59da66a..aee728a25 100644 --- a/lib/libvgz/crc32.c +++ b/lib/libvgz/crc32.c @@ -647,8 +647,8 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) len &= 7; /* Do three interleaved CRCs to realize the throughput of one crc32x - instruction per cycle. Each CRC is calcuated on Z_BATCH words. The three - CRCs are combined into a single CRC after each set of batches. */ + instruction per cycle. Each CRC is calculated on Z_BATCH words. The + three CRCs are combined into a single CRC after each set of batches. */ while (num >= 3 * Z_BATCH) { crc1 = 0; crc2 = 0; diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index fb0a53684..077a700f1 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -292,6 +292,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, if (windowBits < 0) { /* suppress zlib wrapper */ wrap = 0; + if (windowBits < -15) + return Z_STREAM_ERROR; windowBits = -windowBits; } #ifdef GZIP @@ -690,36 +692,50 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) } /* ========================================================================= - * For the default windowBits of 15 and memLevel of 8, this function returns - * a close to exact, as well as small, upper bound on the compressed size. - * They are coded as constants here for a reason--if the #define's are - * changed, then this function needs to be changed as well. The return - * value for 15 and 8 only works for those exact settings. + * For the default windowBits of 15 and memLevel of 8, this function returns a + * close to exact, as well as small, upper bound on the compressed size. This + * is an expansion of ~0.03%, plus a small constant. * - * For any setting other than those defaults for windowBits and memLevel, - * the value returned is a conservative worst case for the maximum expansion - * resulting from using fixed blocks instead of stored blocks, which deflate - * can emit on compressed data for some combinations of the parameters. + * For any setting other than those defaults for windowBits and memLevel, one + * of two worst case bounds is returned. This is at most an expansion of ~4% or + * ~13%, plus a small constant. * - * This function could be more sophisticated to provide closer upper bounds for - * every combination of windowBits and memLevel. But even the conservative - * upper bound of about 14% expansion does not seem onerous for output buffer - * allocation. + * Both the 0.03% and 4% derive from the overhead of stored blocks. The first + * one is for stored blocks of 16383 bytes (memLevel == 8), whereas the second + * is for stored blocks of 127 bytes (the worst case memLevel == 1). The + * expansion results from five bytes of header for each stored block. + * + * The larger expansion of 13% results from a window size less than or equal to + * the symbols buffer size (windowBits <= memLevel + 7). In that case some of + * the data being compressed may have slid out of the sliding window, impeding + * a stored block from being emitted. Then the only choice is a fixed or + * dynamic block, where a fixed block limits the maximum expansion to 9 bits + * per 8-bit byte, plus 10 bits for every block. The smallest block size for + * which this can occur is 255 (memLevel == 2). + * + * Shifts are used to approximate divisions, for speed. */ uLong ZEXPORT deflateBound(strm, sourceLen) z_streamp strm; uLong sourceLen; { deflate_state *s; - uLong complen, wraplen; + uLong fixedlen, storelen, wraplen; + + /* upper bound for fixed blocks with 9-bit literals and length 255 + (memLevel == 2, which is the lowest that may not use stored blocks) -- + ~13% overhead plus a small constant */ + fixedlen = sourceLen + (sourceLen >> 3) + (sourceLen >> 8) + + (sourceLen >> 9) + 4; - /* conservative upper bound for compressed data */ - complen = sourceLen + - ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; + /* upper bound for stored blocks with length 127 (memLevel == 1) -- + ~4% overhead plus a small constant */ + storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) + + (sourceLen >> 11) + 7; - /* if can't get parameters, return conservative bound plus zlib wrapper */ + /* if can't get parameters, return larger bound plus a zlib wrapper */ if (deflateStateCheck(strm)) - return complen + 6; + return (fixedlen > storelen ? fixedlen : storelen) + 6; /* compute wrapper length */ s = strm->state; @@ -756,11 +772,12 @@ uLong ZEXPORT deflateBound(strm, sourceLen) wraplen = 6; } - /* if not default parameters, return conservative bound */ + /* if not default parameters, return one of the conservative bounds */ if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return complen + wraplen; + return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen; - /* default settings: return tight bound for that case */ + /* default settings: return tight bound for that case -- ~0.03% overhead + plus a small constant */ return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13 - 6 + wraplen; } @@ -1353,7 +1370,8 @@ local uInt longest_match(s, cur_match) */ if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead; - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "need lookahead"); do { Assert(cur_match < s->strstart, "no future"); @@ -1377,7 +1395,7 @@ local uInt longest_match(s, cur_match) /* It is not necessary to compare scan[2] and match[2] since they are * always equal when the other bytes match, given that the hash keys * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart+3, +5, ... up to strstart+257. We check for insufficient + * strstart + 3, + 5, up to strstart + 257. We check for insufficient * lookahead only every 4th comparison; the 128th check will be made * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is * necessary to put more guard bytes at the end of the window, or @@ -1394,7 +1412,8 @@ local uInt longest_match(s, cur_match) /* The funny "do {}" generates better code on most compilers */ /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + Assert(scan <= s->window + (unsigned)(s->window_size - 1), + "wild scan"); if (*scan == *match) scan++; len = (MAX_MATCH - 1) - (int)(strend-scan); @@ -1426,7 +1445,8 @@ local uInt longest_match(s, cur_match) *++scan == *++match && *++scan == *++match && scan < strend); - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + Assert(scan <= s->window + (unsigned)(s->window_size - 1), + "wild scan"); len = MAX_MATCH - (int)(strend - scan); scan = strend - MAX_MATCH; @@ -1471,7 +1491,8 @@ local uInt longest_match(s, cur_match) */ Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "need lookahead"); Assert(cur_match < s->strstart, "no future"); @@ -1717,7 +1738,7 @@ local void fill_window(s) * * deflate_stored() is written to minimize the number of times an input byte is * copied. It is most efficient with large input and output buffers, which - * maximizes the opportunites to have a single copy from next_in to next_out. + * maximizes the opportunities to have a single copy from next_in to next_out. */ local block_state deflate_stored(s, flush) deflate_state *s; @@ -2182,7 +2203,8 @@ local block_state deflate_rle(s, flush) if (s->match_length > s->lookahead) s->match_length = s->lookahead; } - Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); + Assert(scan <= s->window + (uInt)(s->window_size - 1), + "wild scan"); } /* Emit match if have run of MIN_MATCH or longer, else emit literal */ diff --git a/lib/libvgz/deflate.h b/lib/libvgz/deflate.h index 17c226113..1a06cd5f2 100644 --- a/lib/libvgz/deflate.h +++ b/lib/libvgz/deflate.h @@ -329,8 +329,8 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, # define _tr_tally_dist(s, distance, length, flush) \ { uch len = (uch)(length); \ ush dist = (ush)(distance); \ - s->sym_buf[s->sym_next++] = dist; \ - s->sym_buf[s->sym_next++] = dist >> 8; \ + s->sym_buf[s->sym_next++] = (uch)dist; \ + s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \ s->sym_buf[s->sym_next++] = len; \ dist--; \ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index 9577e8312..5cdbe8b95 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -171,6 +171,8 @@ int windowBits; /* extract wrap request from windowBits parameter */ if (windowBits < 0) { + if (windowBits < -15) + return Z_STREAM_ERROR; wrap = 0; windowBits = -windowBits; } diff --git a/lib/libvgz/inftrees.c b/lib/libvgz/inftrees.c index 761253942..2cac3d8be 100644 --- a/lib/libvgz/inftrees.c +++ b/lib/libvgz/inftrees.c @@ -63,7 +63,7 @@ unsigned short FAR *work; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 202}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff --git a/lib/libvgz/inftrees.h b/lib/libvgz/inftrees.h index baa53a0b1..f53665311 100644 --- a/lib/libvgz/inftrees.h +++ b/lib/libvgz/inftrees.h @@ -38,7 +38,7 @@ typedef struct { /* Maximum size of the dynamic table. The maximum number of code structures is 1444, which is the sum of 852 for literal/length codes and 592 for distance codes. These values were found by exhaustive searches using the program - examples/enough.c found in the zlib distribtution. The arguments to that + examples/enough.c found in the zlib distribution. The arguments to that program are the number of symbols, the initial root table size, and the maximum bit length of a code. "enough 286 9 15" for literal/length codes returns returns 852, and "enough 30 6 15" for distance codes returns 592. diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c index 6ae8dcf47..1ccce63e6 100644 --- a/lib/libvgz/trees.c +++ b/lib/libvgz/trees.c @@ -312,7 +312,7 @@ local void tr_static_init() } /* =========================================================================== - * Genererate the file trees.h describing the static trees. + * Generate the file trees.h describing the static trees. */ #ifdef GEN_TREES_H # ifndef ZLIB_DEBUG @@ -807,8 +807,8 @@ local int build_bl_tree(s) /* Build the bit length tree: */ build_tree(s, (tree_desc *)(&(s->bl_desc))); - /* opt_len now includes the length of the tree representations, except - * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + /* opt_len now includes the length of the tree representations, except the + * lengths of the bit lengths codes and the 5 + 5 + 4 bits for the counts. */ /* Determine the number of bit length codes to send. The pkzip format @@ -961,7 +961,10 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, s->sym_next / 3)); - if (static_lenb <= opt_lenb) opt_lenb = static_lenb; +#ifndef FORCE_STATIC + if (static_lenb <= opt_lenb || s->strategy == Z_FIXED) +#endif + opt_lenb = static_lenb; } else { Assert(buf != (char*)0, "lost buf"); @@ -982,11 +985,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) */ _tr_stored_block(s, buf, stored_len, last); -#ifdef FORCE_STATIC - } else if (static_lenb >= 0) { /* force static trees */ -#else - } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { -#endif + } else if (static_lenb == opt_lenb) { send_bits(s, (STATIC_TREES<<1)+last, 3); compress_block(s, (const ct_data *)static_ltree, (const ct_data *)static_dtree); @@ -1028,11 +1027,11 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) int ZLIB_INTERNAL _tr_tally (s, dist, lc) deflate_state *s; unsigned dist; /* distance of matched string */ - unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ + unsigned lc; /* match length - MIN_MATCH or unmatched char (dist==0) */ { - s->sym_buf[s->sym_next++] = dist; - s->sym_buf[s->sym_next++] = dist >> 8; - s->sym_buf[s->sym_next++] = lc; + s->sym_buf[s->sym_next++] = (uch)dist; + s->sym_buf[s->sym_next++] = (uch)(dist >> 8); + s->sym_buf[s->sym_next++] = (uch)lc; if (dist == 0) { /* lc is the unmatched char */ s->dyn_ltree[lc].Freq++; @@ -1074,7 +1073,7 @@ local void compress_block(s, ltree, dtree) } else { /* Here, lc is the match length - MIN_MATCH */ code = _length_code[lc]; - send_code(s, code+LITERALS+1, ltree); /* send the length code */ + send_code(s, code + LITERALS + 1, ltree); /* send length code */ extra = extra_lbits[code]; if (extra != 0) { lc -= base_length[code]; diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h index b259aac34..eff35f22a 100644 --- a/lib/libvgz/vgz.h +++ b/lib/libvgz/vgz.h @@ -281,7 +281,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); == 0), or after each call of deflate(). If deflate returns Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending. See deflatePending(), - which can be used if desired to determine whether or not there is more ouput + which can be used if desired to determine whether or not there is more output in that case. Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to @@ -665,7 +665,7 @@ ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, to dictionary. dictionary must have enough space, where 32768 bytes is always enough. If deflateGetDictionary() is called with dictionary equal to Z_NULL, then only the dictionary length is returned, and nothing is copied. - Similary, if dictLength is Z_NULL, then it is not set. + Similarly, if dictLength is Z_NULL, then it is not set. deflateGetDictionary() may return a length less than the window size, even when more than the window size in input has been provided. It may return up @@ -920,7 +920,7 @@ ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, to dictionary. dictionary must have enough space, where 32768 bytes is always enough. If inflateGetDictionary() is called with dictionary equal to Z_NULL, then only the dictionary length is returned, and nothing is copied. - Similary, if dictLength is Z_NULL, then it is not set. + Similarly, if dictLength is Z_NULL, then it is not set. inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the stream state is inconsistent. @@ -1442,12 +1442,12 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, In the event that the end of file is reached and only a partial item is available at the end, i.e. the remaining uncompressed data length is not a - multiple of size, then the final partial item is nevetheless read into buf + multiple of size, then the final partial item is nevertheless read into buf and the end-of-file flag is set. The length of the partial item read is not provided, but could be inferred from the result of gztell(). This behavior is the same as the behavior of fread() implementations in common libraries, but it prevents the direct use of gzfread() to read a concurrently written - file, reseting and retrying on end-of-file, when size is not 1. + file, resetting and retrying on end-of-file, when size is not 1. */ ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] 0784fb4f0 The (potentially) substantial parts of zlib 1.2.13 Message-ID: <20251210154306.3939A102933@lists.vinyl-cache.org> commit 0784fb4f0200696221e96b1ec2b101ce22757602 Author: Poul-Henning Kamp Date: Mon Dec 19 12:23:18 2022 +0000 The (potentially) substantial parts of zlib 1.2.13 diff --git a/lib/libvgz/crc32.c b/lib/libvgz/crc32.c index aee728a25..6eab5e951 100644 --- a/lib/libvgz/crc32.c +++ b/lib/libvgz/crc32.c @@ -98,13 +98,22 @@ # endif #endif +/* If available, use the ARM processor CRC32 instruction. */ +#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8 +# define ARMCRC32 +#endif + /* Local functions. */ local z_crc_t multmodp OF((z_crc_t a, z_crc_t b)); local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); -/* If available, use the ARM processor CRC32 instruction. */ -#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8 -# define ARMCRC32 +#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) + local z_word_t byte_swap OF((z_word_t word)); +#endif + +#if defined(W) && !defined(ARMCRC32) + local z_crc_t crc_word OF((z_word_t data)); + local z_word_t crc_word_big OF((z_word_t data)); #endif #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) @@ -1092,7 +1101,7 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2) uLong crc2; z_off_t len2; { - return crc32_combine64(crc1, crc2, len2); + return crc32_combine64(crc1, crc2, (z_off64_t)len2); } /* ========================================================================= */ @@ -1109,11 +1118,11 @@ uLong ZEXPORT crc32_combine_gen64(len2) uLong ZEXPORT crc32_combine_gen(len2) z_off_t len2; { - return crc32_combine_gen64(len2); + return crc32_combine_gen64((z_off64_t)len2); } /* ========================================================================= */ -uLong crc32_combine_op(crc1, crc2, op) +uLong ZEXPORT crc32_combine_op(crc1, crc2, op) uLong crc1; uLong crc2; uLong op; diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index 077a700f1..75277afd4 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -53,7 +53,7 @@ extern const char deflate_copyright[]; const char deflate_copyright[] = - " deflate 1.2.12 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; + " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -90,13 +90,7 @@ local void lm_init OF((deflate_state *s)); local void putShortMSB OF((deflate_state *s, uInt b)); local void flush_pending OF((z_streamp strm)); local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -#ifdef ASMV -# pragma message("Assembler code may have bugs -- use at your own risk") - void match_init OF((void)); /* asm code initialization */ - uInt longest_match OF((deflate_state *s, IPos cur_match)); -#else local uInt longest_match OF((deflate_state *s, IPos cur_match)); -#endif #ifdef ZLIB_DEBUG local void check_match OF((deflate_state *s, IPos start, IPos match, @@ -1304,11 +1298,6 @@ local void lm_init (s) s->match_length = s->prev_length = MIN_MATCH-1; s->match_available = 0; s->ins_h = 0; -#ifndef FASTEST -#ifdef ASMV - match_init(); /* initialize the asm code */ -#endif -#endif } #ifndef FASTEST @@ -1321,10 +1310,6 @@ local void lm_init (s) * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * OUT assertion: the match length is not greater than s->lookahead. */ -#ifndef ASMV -/* For 80x86 and 680x0, an optimized version will be provided in match.asm or - * match.S. The code will be functionally equivalent. - */ local uInt longest_match(s, cur_match) deflate_state *s; IPos cur_match; /* current match */ @@ -1470,7 +1455,6 @@ local uInt longest_match(s, cur_match) if ((uInt)best_len <= s->lookahead) return (uInt)best_len; return s->lookahead; } -#endif /* ASMV */ #else /* FASTEST */ diff --git a/lib/libvgz/inftrees.c b/lib/libvgz/inftrees.c index 2cac3d8be..18faf783c 100644 --- a/lib/libvgz/inftrees.c +++ b/lib/libvgz/inftrees.c @@ -10,7 +10,7 @@ extern const char inflate_copyright[]; const char inflate_copyright[] = - " inflate 1.2.12 Copyright 1995-2022 Mark Adler "; + " inflate 1.2.13 Copyright 1995-2022 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h index eff35f22a..c545df07a 100644 --- a/lib/libvgz/vgz.h +++ b/lib/libvgz/vgz.h @@ -1,5 +1,5 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.12, March 11th, 2022 + version 1.2.13, October 13th, 2022 Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.12" -#define ZLIB_VERNUM 0x12c0 +#define ZLIB_VERSION "1.2.13" +#define ZLIB_VERNUM 0x12d0 #define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 12 +#define ZLIB_VER_REVISION 13 #define ZLIB_VER_SUBREVISION 0 /* @@ -1864,10 +1864,9 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); #endif -ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); - #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) # ifdef Z_PREFIX_SET # define z_gzopen z_gzopen64 diff --git a/lib/libvgz/zconf.h b/lib/libvgz/zconf.h index 5113d217e..bf977d3e7 100644 --- a/lib/libvgz/zconf.h +++ b/lib/libvgz/zconf.h @@ -8,12 +8,6 @@ #ifndef ZCONF_H #define ZCONF_H -#if defined(Z_SOLO) -#include -#define Z_U8 __uint64_t -#define Z_U4 __uint32_t -#endif - /* * If you *really* need a unique prefix for all types and library functions, * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. @@ -44,6 +38,9 @@ # define crc32 z_crc32 # define crc32_combine z_crc32_combine # define crc32_combine64 z_crc32_combine64 +# define crc32_combine_gen z_crc32_combine_gen +# define crc32_combine_gen64 z_crc32_combine_gen64 +# define crc32_combine_op z_crc32_combine_op # define crc32_z z_crc32_z # define deflate z_deflate # define deflateBound z_deflateBound @@ -355,6 +352,9 @@ # ifdef FAR # undef FAR # endif +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include /* No need for _export, use ZLIB.DEF instead. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */ @@ -473,11 +473,18 @@ typedef uLong FAR uLongf; # undef _LARGEFILE64_SOURCE #endif -#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H +#ifndef Z_HAVE_UNISTD_H +# ifdef __WATCOMC__ +# define Z_HAVE_UNISTD_H +# endif +#endif +#ifndef Z_HAVE_UNISTD_H +# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32) +# define Z_HAVE_UNISTD_H +# endif #endif #ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# if defined(Z_HAVE_UNISTD_H) # include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ # ifdef VMS # include /* for off_t */ diff --git a/lib/libvgz/zutil.c b/lib/libvgz/zutil.c index 7c300fdaf..fd0cda93b 100644 --- a/lib/libvgz/zutil.c +++ b/lib/libvgz/zutil.c @@ -62,9 +62,11 @@ uLong ZEXPORT zlibCompileFlags() #ifdef ZLIB_DEBUG flags += 1 << 8; #endif + /* #if defined(ASMV) || defined(ASMINF) flags += 1 << 9; #endif + */ #ifdef ZLIB_WINAPI flags += 1 << 10; #endif diff --git a/lib/libvgz/zutil.h b/lib/libvgz/zutil.h index 1c80e3842..03cdb4d38 100644 --- a/lib/libvgz/zutil.h +++ b/lib/libvgz/zutil.h @@ -193,6 +193,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); #endif /* common defaults */ From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] 7c0a52615 Bite the bullet, and eliminate K&R functions in libvgz, in the most diff-friendly way. Message-ID: <20251210154306.5385C102937@lists.vinyl-cache.org> commit 7c0a526152f81f910c81e03e46378aea524fbcb9 Author: Poul-Henning Kamp Date: Tue Jun 20 08:36:55 2023 +0000 Bite the bullet, and eliminate K&R functions in libvgz, in the most diff-friendly way. If Mark Adler ever decides that the 21st century is real thing, we will adopt his diff. This should allow us to revert 79c7d17543d86 diff --git a/lib/libvgz/adler32.c b/lib/libvgz/adler32.c index ef1ae7e79..7a3d10ccc 100644 --- a/lib/libvgz/adler32.c +++ b/lib/libvgz/adler32.c @@ -186,10 +186,11 @@ uLong ZEXPORT adler32_combine64(adler1, adler2, len2) return adler32_combine_(adler1, adler2, len2); } #else /* NOVGZ */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; +uLong ZEXPORT adler32( + uLong adler, + const Bytef *buf, + uInt len +) { (void)adler; (void)buf; diff --git a/lib/libvgz/crc32.c b/lib/libvgz/crc32.c index 6eab5e951..32c6d5b77 100644 --- a/lib/libvgz/crc32.c +++ b/lib/libvgz/crc32.c @@ -125,8 +125,9 @@ local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); */ local z_word_t byte_swap OF((z_word_t word)); -local z_word_t byte_swap(word) - z_word_t word; +local z_word_t byte_swap( + z_word_t word +) { # if W == 8 return @@ -550,9 +551,10 @@ local void braid(ltl, big, n, w) Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, reflected. For speed, this requires that a not be zero. */ -local z_crc_t multmodp(a, b) - z_crc_t a; - z_crc_t b; +local z_crc_t multmodp( + z_crc_t a, + z_crc_t b +) { z_crc_t m, p; @@ -574,9 +576,10 @@ local z_crc_t multmodp(a, b) Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been initialized. */ -local z_crc_t x2nmodp(n, k) - z_off64_t n; - unsigned k; +local z_crc_t x2nmodp( + z_off64_t n, + unsigned k +) { z_crc_t p; @@ -594,7 +597,7 @@ local z_crc_t x2nmodp(n, k) * This function can be used by asm versions of crc32(), and to force the * generation of the CRC tables in a threaded application. */ -const z_crc_t FAR * ZEXPORT get_crc_table() +const z_crc_t FAR * ZEXPORT get_crc_table(void) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); @@ -727,8 +730,9 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) */ local z_crc_t crc_word OF((z_word_t data)); -local z_crc_t crc_word(data) - z_word_t data; +local z_crc_t crc_word( + z_word_t data +) { int k; for (k = 0; k < W; k++) @@ -738,8 +742,9 @@ local z_crc_t crc_word(data) local z_word_t crc_word_big OF((z_word_t data)); -local z_word_t crc_word_big(data) - z_word_t data; +local z_word_t crc_word_big( + z_word_t data +) { int k; for (k = 0; k < W; k++) @@ -751,10 +756,11 @@ local z_word_t crc_word_big(data) #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - z_size_t len; +unsigned long ZEXPORT crc32_z( + unsigned long crc, + const unsigned char FAR *buf, + z_size_t len +) { /* Return initial CRC, if requested. */ if (buf == Z_NULL) return 0; @@ -1075,19 +1081,21 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - uInt len; +unsigned long ZEXPORT crc32( + unsigned long crc, + const unsigned char FAR *buf, + uInt len +) { return crc32_z(crc, buf, len); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine64(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; +uLong ZEXPORT crc32_combine64( + uLong crc1, + uLong crc2, + z_off64_t len2 +) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); @@ -1096,17 +1104,19 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2) } /* ========================================================================= */ -uLong ZEXPORT crc32_combine(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off_t len2; +uLong ZEXPORT crc32_combine( + uLong crc1, + uLong crc2, + z_off_t len2 +) { return crc32_combine64(crc1, crc2, (z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen64(len2) - z_off64_t len2; +uLong ZEXPORT crc32_combine_gen64( + z_off64_t len2 +) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); @@ -1115,17 +1125,19 @@ uLong ZEXPORT crc32_combine_gen64(len2) } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen(len2) - z_off_t len2; +uLong ZEXPORT crc32_combine_gen( + z_off_t len2 +) { return crc32_combine_gen64((z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_op(crc1, crc2, op) - uLong crc1; - uLong crc2; - uLong op; +uLong ZEXPORT crc32_combine_op( + uLong crc1, + uLong crc2, + uLong op +) { return multmodp(op, crc1) ^ (crc2 & 0xffffffff); } diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index 75277afd4..32b395342 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -198,8 +198,9 @@ local const config configuration_table[10] = { * bit values at the expense of memory usage). We slide even when level == 0 to * keep the hash table consistent if we switch back to level > 0 later. */ -local void slide_hash(s) - deflate_state *s; +local void slide_hash( + deflate_state *s +) { unsigned n, m; Posf *p; @@ -241,16 +242,16 @@ int ZEXPORT deflateInit_(strm, level, version, stream_size) #endif /* NOVGZ */ /* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - version, stream_size) - z_streamp strm; - int level; - int method; - int windowBits; - int memLevel; - int strategy; - const char *version; - int stream_size; +int ZEXPORT deflateInit2_( + z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy, + const char *version, + int stream_size +) { deflate_state *s; int wrap = 1; @@ -393,8 +394,9 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, /* ========================================================================= * Check for a valid deflate stream state. Return 0 if ok, 1 if not. */ -local int deflateStateCheck (strm) - z_streamp strm; +local int deflateStateCheck ( + z_streamp strm +) { deflate_state *s; if (strm == Z_NULL || @@ -513,8 +515,9 @@ int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) #endif /* NOVGZ */ /* ========================================================================= */ -int ZEXPORT deflateResetKeep (strm) - z_streamp strm; +int ZEXPORT deflateResetKeep ( + z_streamp strm +) { deflate_state *s; @@ -552,8 +555,9 @@ int ZEXPORT deflateResetKeep (strm) } /* ========================================================================= */ -int ZEXPORT deflateReset (strm) - z_streamp strm; +int ZEXPORT deflateReset ( + z_streamp strm +) { int ret; @@ -566,9 +570,10 @@ int ZEXPORT deflateReset (strm) #ifdef NOVGZ /* ========================================================================= */ -int ZEXPORT deflateSetHeader (strm, head) - z_streamp strm; - gz_headerp head; +int ZEXPORT deflateSetHeader ( + z_streamp strm, + gz_headerp head +) { if (deflateStateCheck(strm) || strm->state->wrap != 2) return Z_STREAM_ERROR; @@ -577,10 +582,11 @@ int ZEXPORT deflateSetHeader (strm, head) } /* ========================================================================= */ -int ZEXPORT deflatePending (strm, pending, bits) - unsigned *pending; - int *bits; - z_streamp strm; +int ZEXPORT deflatePending ( + z_streamp strm, + unsigned *pending, + int *bits +) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (pending != Z_NULL) @@ -783,9 +789,10 @@ uLong ZEXPORT deflateBound(strm, sourceLen) * IN assertion: the stream state is correct and there is enough room in * pending_buf. */ -local void putShortMSB (s, b) - deflate_state *s; - uInt b; +local void putShortMSB ( + deflate_state *s, + uInt b +) { put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b & 0xff)); @@ -797,8 +804,9 @@ local void putShortMSB (s, b) * applications may wish to modify it to avoid allocating a large * strm->next_out buffer and copying into it. (See also read_buf()). */ -local void flush_pending(strm) - z_streamp strm; +local void flush_pending( + z_streamp strm +) { unsigned len; deflate_state *s = strm->state; @@ -830,9 +838,10 @@ local void flush_pending(strm) } while (0) /* ========================================================================= */ -int ZEXPORT deflate (strm, flush) - z_streamp strm; - int flush; +int ZEXPORT deflate ( + z_streamp strm, + int flush +) { int old_flush; /* value of flush param for previous deflate call */ deflate_state *s; @@ -1158,8 +1167,9 @@ int ZEXPORT deflate (strm, flush) } /* ========================================================================= */ -int ZEXPORT deflateEnd (strm) - z_streamp strm; +int ZEXPORT deflateEnd ( + z_streamp strm +) { int status; @@ -1247,10 +1257,11 @@ int ZEXPORT deflateCopy (dest, source) * allocating a large strm->next_in buffer and copying from it. * (See also flush_pending()). */ -local unsigned read_buf(strm, buf, size) - z_streamp strm; - Bytef *buf; - unsigned size; +local unsigned read_buf( + z_streamp strm, + Bytef *buf, + unsigned size +) { unsigned len = strm->avail_in; @@ -1277,8 +1288,9 @@ local unsigned read_buf(strm, buf, size) /* =========================================================================== * Initialize the "longest match" routines for a new zlib stream */ -local void lm_init (s) - deflate_state *s; +local void lm_init ( + deflate_state *s +) { s->window_size = (ulg)2L*s->w_size; @@ -1310,9 +1322,10 @@ local void lm_init (s) * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * OUT assertion: the match length is not greater than s->lookahead. */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ +local uInt longest_match( + deflate_state *s, + IPos cur_match /* current match */ +) { unsigned chain_length = s->max_chain_length;/* max hash chain length */ register Bytef *scan = s->window + s->strstart; /* current string */ @@ -1559,8 +1572,9 @@ local void check_match(s, start, match, length) * performed for at least two bytes (required for the zip translate_eol * option -- not supported here). */ -local void fill_window(s) - deflate_state *s; +local void fill_window( + deflate_state *s +) { unsigned n; unsigned more; /* Amount of free space at the end of the window. */ @@ -1724,9 +1738,10 @@ local void fill_window(s) * copied. It is most efficient with large input and output buffers, which * maximizes the opportunities to have a single copy from next_in to next_out. */ -local block_state deflate_stored(s, flush) - deflate_state *s; - int flush; +local block_state deflate_stored( + deflate_state *s, + int flush +) { /* Smallest worthy block size when not flushing or finishing. By default * this is 32K. This can be as small as 507 bytes for memLevel == 1. For @@ -1914,9 +1929,10 @@ local block_state deflate_stored(s, flush) * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */ -local block_state deflate_fast(s, flush) - deflate_state *s; - int flush; +local block_state deflate_fast( + deflate_state *s, + int flush +) { IPos hash_head; /* head of the hash chain */ int bflush; /* set if current block must be flushed */ @@ -2016,9 +2032,10 @@ local block_state deflate_fast(s, flush) * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */ -local block_state deflate_slow(s, flush) - deflate_state *s; - int flush; +local block_state deflate_slow( + deflate_state *s, + int flush +) { IPos hash_head; /* head of hash chain */ int bflush; /* set if current block must be flushed */ diff --git a/lib/libvgz/inffast.c b/lib/libvgz/inffast.c index 903ebfae1..01b00436b 100644 --- a/lib/libvgz/inffast.c +++ b/lib/libvgz/inffast.c @@ -47,9 +47,10 @@ requires strm->avail_out >= 258 for each loop to avoid checking for output space. */ -void ZLIB_INTERNAL inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ +void ZLIB_INTERNAL inflate_fast( + z_streamp strm, + unsigned start /* inflate()'s starting value for strm->avail_out */ +) { struct inflate_state FAR *state; z_const unsigned char FAR *in; /* local strm->next_in */ diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index 5cdbe8b95..cfd708391 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -104,8 +104,9 @@ local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, unsigned len)); #endif /* NOVGZ */ -local int inflateStateCheck(strm) -z_streamp strm; +local int inflateStateCheck( + z_streamp strm +) { struct inflate_state FAR *state; if (strm == Z_NULL || @@ -118,8 +119,9 @@ z_streamp strm; return 0; } -int ZEXPORT inflateResetKeep(strm) -z_streamp strm; +int ZEXPORT inflateResetKeep( + z_streamp strm +) { struct inflate_state FAR *state; @@ -145,8 +147,9 @@ z_streamp strm; return Z_OK; } -int ZEXPORT inflateReset(strm) -z_streamp strm; +int ZEXPORT inflateReset( + z_streamp strm +) { struct inflate_state FAR *state; @@ -158,9 +161,10 @@ z_streamp strm; return inflateResetKeep(strm); } -int ZEXPORT inflateReset2(strm, windowBits) -z_streamp strm; -int windowBits; +int ZEXPORT inflateReset2( + z_streamp strm, + int windowBits +) { int wrap; struct inflate_state FAR *state; @@ -198,11 +202,12 @@ int windowBits; return inflateReset(strm); } -int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) -z_streamp strm; -int windowBits; -const char *version; -int stream_size; +int ZEXPORT inflateInit2_( + z_streamp strm, + int windowBits, + const char *version, + int stream_size +) { int ret; struct inflate_state FAR *state; @@ -244,18 +249,20 @@ int stream_size; #ifdef NOVGZ -int ZEXPORT inflateInit_(strm, version, stream_size) -z_streamp strm; -const char *version; -int stream_size; +int ZEXPORT inflateInit_( + z_streamp strm, + const char *version, + int stream_size +) { return inflateInit2_(strm, DEF_WBITS, version, stream_size); } -int ZEXPORT inflatePrime(strm, bits, value) -z_streamp strm; -int bits; -int value; +int ZEXPORT inflatePrime( + z_streamp strm, + int bits, + int value +) { struct inflate_state FAR *state; @@ -285,8 +292,9 @@ int value; used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables(state) -struct inflate_state FAR *state; +local void fixedtables( + struct inflate_state FAR *state +) { #ifdef BUILDFIXED static int virgin = 1; @@ -403,10 +411,11 @@ void makefixed() output will fall in the output data, making match copies simpler and faster. The advantage may be dependent on the size of the processor's data caches. */ -local int updatewindow(strm, end, copy) -z_streamp strm; -const Bytef *end; -unsigned copy; +local int updatewindow( + z_streamp strm, + const Bytef *end, + unsigned copy +) { struct inflate_state FAR *state; unsigned dist; @@ -629,9 +638,10 @@ unsigned copy; will return Z_BUF_ERROR if it has not reached the end of the stream. */ -int ZEXPORT inflate(strm, flush) -z_streamp strm; -int flush; +int ZEXPORT inflate( + z_streamp strm, + int flush +) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ @@ -1313,8 +1323,9 @@ int flush; return ret; } -int ZEXPORT inflateEnd(strm) -z_streamp strm; +int ZEXPORT inflateEnd( + z_streamp strm +) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) diff --git a/lib/libvgz/inftrees.c b/lib/libvgz/inftrees.c index 18faf783c..a794b0e27 100644 --- a/lib/libvgz/inftrees.c +++ b/lib/libvgz/inftrees.c @@ -30,13 +30,14 @@ const char inflate_copyright[] = table index bits. It will differ if the request is greater than the longest code or if it is less than the shortest code. */ -int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) -codetype type; -unsigned short FAR *lens; -unsigned codes; -code FAR * FAR *table; -unsigned FAR *bits; -unsigned short FAR *work; +int ZLIB_INTERNAL inflate_table( + codetype type, + unsigned short FAR *lens, + unsigned codes, + code FAR * FAR *table, + unsigned FAR *bits, + unsigned short FAR *work +) { unsigned len; /* a code's length in bits */ unsigned sym; /* index of code symbols */ diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c index 1ccce63e6..87b5c5f32 100644 --- a/lib/libvgz/trees.c +++ b/lib/libvgz/trees.c @@ -229,7 +229,7 @@ local void send_bits(s, value, length) /* =========================================================================== * Initialize the various 'constant' tables. */ -local void tr_static_init() +local void tr_static_init(void) { #if defined(GEN_TREES_H) || !defined(STDC) static int static_init_done = 0; @@ -376,8 +376,9 @@ void gen_trees_header() /* =========================================================================== * Initialize the tree data structures for a new zlib stream. */ -void ZLIB_INTERNAL _tr_init(s) - deflate_state *s; +void ZLIB_INTERNAL _tr_init( + deflate_state *s +) { tr_static_init(); @@ -404,8 +405,9 @@ void ZLIB_INTERNAL _tr_init(s) /* =========================================================================== * Initialize a new block. */ -local void init_block(s) - deflate_state *s; +local void init_block( + deflate_state *s +) { int n; /* iterates over tree elements */ @@ -448,10 +450,11 @@ local void init_block(s) * when the heap property is re-established (each father smaller than its * two sons). */ -local void pqdownheap(s, tree, k) - deflate_state *s; - ct_data *tree; /* the tree to restore */ - int k; /* node to move down */ +local void pqdownheap( + deflate_state *s, + ct_data *tree, /* the tree to restore */ + int k /* node to move down */ +) { int v = s->heap[k]; int j = k << 1; /* left son of k */ @@ -483,9 +486,10 @@ local void pqdownheap(s, tree, k) * The length opt_len is updated; static_len is also updated if stree is * not null. */ -local void gen_bitlen(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ +local void gen_bitlen( + deflate_state *s, + tree_desc *desc /* the tree descriptor */ +) { ct_data *tree = desc->dyn_tree; int max_code = desc->max_code; @@ -569,10 +573,11 @@ local void gen_bitlen(s, desc) * OUT assertion: the field code is set for all tree elements of non * zero code length. */ -local void gen_codes (tree, max_code, bl_count) - ct_data *tree; /* the tree to decorate */ - int max_code; /* largest code with non zero frequency */ - ushf *bl_count; /* number of codes at each bit length */ +local void gen_codes ( + ct_data *tree, /* the tree to decorate */ + int max_code, /* largest code with non zero frequency */ + ushf *bl_count /* number of codes at each bit length */ +) { ush next_code[MAX_BITS+1]; /* next code value for each bit length */ unsigned code = 0; /* running code value */ @@ -612,9 +617,10 @@ local void gen_codes (tree, max_code, bl_count) * and corresponding code. The length opt_len is updated; static_len is * also updated if stree is not null. The field max_code is set. */ -local void build_tree(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ +local void build_tree( + deflate_state *s, + tree_desc *desc /* the tree descriptor */ +) { ct_data *tree = desc->dyn_tree; const ct_data *stree = desc->stat_desc->static_tree; @@ -700,10 +706,11 @@ local void build_tree(s, desc) * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */ -local void scan_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ +local void scan_tree ( + deflate_state *s, + ct_data *tree, /* the tree to be scanned */ + int max_code /* and its largest code of non zero frequency */ +) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ @@ -745,10 +752,11 @@ local void scan_tree (s, tree, max_code) * Send a literal or distance tree in compressed form, using the codes in * bl_tree. */ -local void send_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ +local void send_tree ( + deflate_state *s, + ct_data *tree, /* the tree to be scanned */ + int max_code /* and its largest code of non zero frequency */ +) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ @@ -796,8 +804,9 @@ local void send_tree (s, tree, max_code) * Construct the Huffman tree for the bit lengths and return the index in * bl_order of the last bit length code to send. */ -local int build_bl_tree(s) - deflate_state *s; +local int build_bl_tree( + deflate_state *s +) { int max_blindex; /* index of last bit length code of non zero freq */ @@ -831,9 +840,12 @@ local int build_bl_tree(s) * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ -local void send_all_trees(s, lcodes, dcodes, blcodes) - deflate_state *s; - int lcodes, dcodes, blcodes; /* number of codes for each tree */ +local void send_all_trees( + deflate_state *s, + int lcodes, + int dcodes, + int blcodes /* number of codes for each tree */ +) { int rank; /* index in bl_order */ @@ -860,11 +872,12 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) /* =========================================================================== * Send a stored block */ -void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ +void ZLIB_INTERNAL _tr_stored_block( + deflate_state *s, + charf *buf, /* input block */ + ulg stored_len, /* length of input block */ + int last /* one if this is the last block for a file */ +) { if (last) s->strm->last_bit = @@ -891,8 +904,9 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) /* =========================================================================== * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) */ -void ZLIB_INTERNAL _tr_flush_bits(s) - deflate_state *s; +void ZLIB_INTERNAL _tr_flush_bits( + deflate_state *s +) { bi_flush(s); } @@ -901,8 +915,9 @@ void ZLIB_INTERNAL _tr_flush_bits(s) * Send one empty static block to give enough lookahead for inflate. * This takes 10 bits, of which 7 may remain in the bit buffer. */ -void ZLIB_INTERNAL _tr_align(s) - deflate_state *s; +void ZLIB_INTERNAL _tr_align( + deflate_state *s +) { send_bits(s, STATIC_TREES<<1, 3); send_code(s, END_BLOCK, static_ltree); @@ -916,11 +931,12 @@ void ZLIB_INTERNAL _tr_align(s) * Determine the best encoding for the current block: dynamic trees, static * trees or store, and write out the encoded block. */ -void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block, or NULL if too old */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ +void ZLIB_INTERNAL _tr_flush_block( + deflate_state *s, + charf *buf, /* input block, or NULL if too old */ + ulg stored_len, /* length of input block */ + int last /* one if this is the last block for a file */ +) { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex = 0; /* index of last bit length code of non zero freq */ @@ -1024,10 +1040,11 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) * Save the match info and tally the frequency counts. Return true if * the current block must be flushed. */ -int ZLIB_INTERNAL _tr_tally (s, dist, lc) - deflate_state *s; - unsigned dist; /* distance of matched string */ - unsigned lc; /* match length - MIN_MATCH or unmatched char (dist==0) */ +int ZLIB_INTERNAL _tr_tally ( + deflate_state *s, + unsigned dist, /* distance of matched string */ + unsigned lc /* match length - MIN_MATCH or unmatched char (dist==0) */ +) { s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)(dist >> 8); @@ -1052,10 +1069,11 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc) /* =========================================================================== * Send the block data compressed using the given Huffman trees */ -local void compress_block(s, ltree, dtree) - deflate_state *s; - const ct_data *ltree; /* literal tree */ - const ct_data *dtree; /* distance tree */ +local void compress_block( + deflate_state *s, + const ct_data *ltree, /* literal tree */ + const ct_data *dtree /* distance tree */ +) { unsigned dist; /* distance of matched string */ int lc; /* match length or unmatched char (if dist == 0) */ @@ -1112,8 +1130,9 @@ local void compress_block(s, ltree, dtree) * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). * IN assertion: the fields Freq of dyn_ltree are set. */ -local int detect_data_type(s) - deflate_state *s; +local int detect_data_type( + deflate_state *s +) { /* block_mask is the bit mask of block-listed bytes * set bits 0..6, 14..25, and 28..31 @@ -1146,9 +1165,10 @@ local int detect_data_type(s) * method would use a table) * IN assertion: 1 <= len <= 15 */ -local unsigned bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ +local unsigned bi_reverse( + unsigned code, /* the value to invert */ + int len /* its bit length */ +) { register unsigned res = 0; do { @@ -1161,8 +1181,9 @@ local unsigned bi_reverse(code, len) /* =========================================================================== * Flush the bit buffer, keeping at most 7 bits in it. */ -local void bi_flush(s) - deflate_state *s; +local void bi_flush( + deflate_state *s +) { if (s->bi_valid == 16) { put_short(s, s->bi_buf); @@ -1178,8 +1199,9 @@ local void bi_flush(s) /* =========================================================================== * Flush the bit buffer and align the output on a byte boundary */ -local void bi_windup(s) - deflate_state *s; +local void bi_windup( + deflate_state *s +) { if (s->bi_valid > 8) { put_short(s, s->bi_buf); diff --git a/lib/libvgz/zutil.c b/lib/libvgz/zutil.c index fd0cda93b..6a5b32c3e 100644 --- a/lib/libvgz/zutil.c +++ b/lib/libvgz/zutil.c @@ -307,19 +307,21 @@ extern voidp calloc OF((uInt items, uInt size)); extern void free OF((voidpf ptr)); #endif -voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; +voidpf ZLIB_INTERNAL zcalloc ( + voidpf opaque, + unsigned items, + unsigned size +) { (void)opaque; return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : (voidpf)calloc(items, size); } -void ZLIB_INTERNAL zcfree (opaque, ptr) - voidpf opaque; - voidpf ptr; +void ZLIB_INTERNAL zcfree ( + voidpf opaque, + voidpf ptr +) { (void)opaque; free(ptr); From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] 38f1febb5 zlib 1.3 convergence: Get rid of OF(...) Message-ID: <20251210154306.6F29C102940@lists.vinyl-cache.org> commit 38f1febb537e40c017631384aae191ff3a5ee821 Author: Poul-Henning Kamp Date: Wed Aug 30 09:42:50 2023 +0000 zlib 1.3 convergence: Get rid of OF(...) diff --git a/lib/libvgz/adler32.c b/lib/libvgz/adler32.c index 7a3d10ccc..25f11472c 100644 --- a/lib/libvgz/adler32.c +++ b/lib/libvgz/adler32.c @@ -8,7 +8,7 @@ #include "zutil.h" #ifdef NOVGZ -local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); +local uLong adler32_combine_ (uLong adler1, uLong adler2, z_off64_t len2); #define BASE 65521U /* largest prime smaller than 65536 */ #define NMAX 5552 diff --git a/lib/libvgz/crc32.c b/lib/libvgz/crc32.c index 32c6d5b77..fd68dcbdf 100644 --- a/lib/libvgz/crc32.c +++ b/lib/libvgz/crc32.c @@ -104,16 +104,16 @@ #endif /* Local functions. */ -local z_crc_t multmodp OF((z_crc_t a, z_crc_t b)); -local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); +local z_crc_t multmodp (z_crc_t a, z_crc_t b); +local z_crc_t x2nmodp (z_off64_t n, unsigned k); #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) - local z_word_t byte_swap OF((z_word_t word)); + local z_word_t byte_swap (z_word_t word); #endif #if defined(W) && !defined(ARMCRC32) - local z_crc_t crc_word OF((z_word_t data)); - local z_word_t crc_word_big OF((z_word_t data)); + local z_crc_t crc_word (z_word_t data); + local z_word_t crc_word_big (z_word_t data); #endif #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) @@ -123,7 +123,7 @@ local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); instruction, if one is available. This assumes that word_t is either 32 bits or 64 bits. */ -local z_word_t byte_swap OF((z_word_t word)); +local z_word_t byte_swap (z_word_t word); local z_word_t byte_swap( z_word_t word @@ -156,17 +156,17 @@ local z_word_t byte_swap( local z_crc_t FAR crc_table[256]; local z_crc_t FAR x2n_table[32]; -local void make_crc_table OF((void)); +local void make_crc_table (void); #ifdef W local z_word_t FAR crc_big_table[256]; local z_crc_t FAR crc_braid_table[W][256]; local z_word_t FAR crc_braid_big_table[W][256]; - local void braid OF((z_crc_t [][256], z_word_t [][256], int, int)); + local void braid (z_crc_t [][256], z_word_t [][256], int, int); #endif #ifdef MAKECRCH - local void write_table OF((FILE *, const z_crc_t FAR *, int)); - local void write_table32hi OF((FILE *, const z_word_t FAR *, int)); - local void write_table64 OF((FILE *, const z_word_t FAR *, int)); + local void write_table (FILE *, const z_crc_t FAR *, int); + local void write_table32hi (FILE *, const z_word_t FAR *, int); + local void write_table64 (FILE *, const z_word_t FAR *, int); #endif /* MAKECRCH */ /* @@ -179,7 +179,7 @@ local void make_crc_table OF((void)); /* Definition of once functionality. */ typedef struct once_s once_t; -local void once OF((once_t *, void (*)(void))); +local void once (once_t *, void (*)(void)); /* Check for the availability of atomics. */ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ @@ -225,7 +225,7 @@ struct once_s { /* Test and set. Alas, not atomic, but tries to minimize the period of vulnerability. */ -local int test_and_set OF((int volatile *)); +local int test_and_set (int volatile *); local int test_and_set(flag) int volatile *flag; { @@ -728,7 +728,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) least-significant byte of the word as the first byte of data, without any pre or post conditioning. This is used to combine the CRCs of each braid. */ -local z_crc_t crc_word OF((z_word_t data)); +local z_crc_t crc_word (z_word_t data); local z_crc_t crc_word( z_word_t data @@ -740,7 +740,7 @@ local z_crc_t crc_word( return (z_crc_t)data; } -local z_word_t crc_word_big OF((z_word_t data)); +local z_word_t crc_word_big (z_word_t data); local z_word_t crc_word_big( z_word_t data diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index 32b395342..4dd3447aa 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -71,30 +71,30 @@ typedef enum { finish_done /* finish done, accept no more input or output */ } block_state; -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +typedef block_state (*compress_func) (deflate_state *s, int flush); /* Compression function. Returns the block state after the call. */ -local int deflateStateCheck OF((z_streamp strm)); -local void slide_hash OF((deflate_state *s)); -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); +local int deflateStateCheck (z_streamp strm); +local void slide_hash (deflate_state *s); +local void fill_window (deflate_state *s); +local block_state deflate_stored (deflate_state *s, int flush); +local block_state deflate_fast (deflate_state *s, int flush); #ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); +local block_state deflate_slow (deflate_state *s, int flush); #endif #ifdef NOVGZ -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); +local block_state deflate_rle (deflate_state *s, int flush); +local block_state deflate_huff (deflate_state *s, int flush); #endif /* NOVGZ */ -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -local uInt longest_match OF((deflate_state *s, IPos cur_match)); +local void lm_init (deflate_state *s); +local void putShortMSB (deflate_state *s, uInt b); +local void flush_pending (z_streamp strm); +local unsigned read_buf (z_streamp strm, Bytef *buf, unsigned size); +local uInt longest_match (deflate_state *s, IPos cur_match); #ifdef ZLIB_DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); +local void check_match (deflate_state *s, IPos start, IPos match, + int length); #endif /* =========================================================================== diff --git a/lib/libvgz/deflate.h b/lib/libvgz/deflate.h index 1a06cd5f2..6d9f6945e 100644 --- a/lib/libvgz/deflate.h +++ b/lib/libvgz/deflate.h @@ -291,14 +291,14 @@ typedef struct internal_state { memory checker errors from longest match routines */ /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); +void ZLIB_INTERNAL _tr_init (deflate_state *s); +int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, unsigned lc); +void ZLIB_INTERNAL _tr_flush_block (deflate_state *s, charf *buf, + ulg stored_len, int last); +void ZLIB_INTERNAL _tr_flush_bits (deflate_state *s); +void ZLIB_INTERNAL _tr_align (deflate_state *s); +void ZLIB_INTERNAL _tr_stored_block (deflate_state *s, charf *buf, + ulg stored_len, int last); #define d_code(dist) \ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) diff --git a/lib/libvgz/gzguts.h b/lib/libvgz/gzguts.h index 3991076e6..433c8d8af 100644 --- a/lib/libvgz/gzguts.h +++ b/lib/libvgz/gzguts.h @@ -119,8 +119,8 @@ /* gz* functions always use library allocation functions */ #ifndef STDC - extern voidp malloc OF((uInt size)); - extern void free OF((voidpf ptr)); + extern voidp malloc (uInt size); + extern void free (voidpf ptr); #endif /* get errno and strerror definition */ @@ -138,10 +138,10 @@ /* provide prototypes for these when building zlib without LFS */ #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN gzFile ZEXPORT gzopen64 (const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64 (gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64 (gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64 (gzFile); #endif /* default memLevel */ @@ -203,9 +203,9 @@ typedef struct { typedef gz_state FAR *gz_statep; /* shared functions */ -void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); +void ZLIB_INTERNAL gz_error (gz_statep, int, const char *); #if defined UNDER_CE -char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); +char ZLIB_INTERNAL *gz_strwinerror (DWORD error); #endif /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t @@ -214,6 +214,6 @@ char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); #ifdef INT_MAX # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) #else -unsigned ZLIB_INTERNAL gz_intmax OF((void)); +unsigned ZLIB_INTERNAL gz_intmax (void); # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) #endif diff --git a/lib/libvgz/inffast.h b/lib/libvgz/inffast.h index e5c1aa4ca..96bd8abb8 100644 --- a/lib/libvgz/inffast.h +++ b/lib/libvgz/inffast.h @@ -8,4 +8,4 @@ subject to change. Applications should only use zlib.h. */ -void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); +void ZLIB_INTERNAL inflate_fast (z_streamp strm, unsigned start); diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index cfd708391..7cdee41b0 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -92,16 +92,16 @@ #endif /* function prototypes */ -local int inflateStateCheck OF((z_streamp strm)); -local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, - unsigned copy)); +local int inflateStateCheck (z_streamp strm); +local void fixedtables (struct inflate_state FAR *state); +local int updatewindow (z_streamp strm, const unsigned char FAR *end, + unsigned copy); #ifdef BUILDFIXED - void makefixed OF((void)); + void makefixed (void); #endif #ifdef NOVGZ -local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, - unsigned len)); +local unsigned syncsearch (unsigned FAR *have, const unsigned char FAR *buf, + unsigned len); #endif /* NOVGZ */ local int inflateStateCheck( diff --git a/lib/libvgz/inftrees.h b/lib/libvgz/inftrees.h index f53665311..c96d3b62a 100644 --- a/lib/libvgz/inftrees.h +++ b/lib/libvgz/inftrees.h @@ -57,6 +57,6 @@ typedef enum { DISTS } codetype; -int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, +int ZLIB_INTERNAL inflate_table (codetype type, unsigned short FAR *lens, unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); + unsigned FAR *bits, unsigned short FAR *work); diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c index 87b5c5f32..7f1f949fe 100644 --- a/lib/libvgz/trees.c +++ b/lib/libvgz/trees.c @@ -135,26 +135,26 @@ local const static_tree_desc static_bl_desc = * Local (static) routines in this file. */ -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, const ct_data *ltree, - const ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned code, int len)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); +local void tr_static_init (void); +local void init_block (deflate_state *s); +local void pqdownheap (deflate_state *s, ct_data *tree, int k); +local void gen_bitlen (deflate_state *s, tree_desc *desc); +local void gen_codes (ct_data *tree, int max_code, ushf *bl_count); +local void build_tree (deflate_state *s, tree_desc *desc); +local void scan_tree (deflate_state *s, ct_data *tree, int max_code); +local void send_tree (deflate_state *s, ct_data *tree, int max_code); +local int build_bl_tree (deflate_state *s); +local void send_all_trees (deflate_state *s, int lcodes, int dcodes, + int blcodes); +local void compress_block (deflate_state *s, const ct_data *ltree, + const ct_data *dtree); +local int detect_data_type (deflate_state *s); +local unsigned bi_reverse (unsigned code, int len); +local void bi_windup (deflate_state *s); +local void bi_flush (deflate_state *s); #ifdef GEN_TREES_H -local void gen_trees_header OF((void)); +local void gen_trees_header (void); #endif #ifndef ZLIB_DEBUG @@ -181,7 +181,7 @@ local void gen_trees_header OF((void)); * IN assertion: length <= 16 and value fits in length bits. */ #ifdef ZLIB_DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); +local void send_bits (deflate_state *s, int value, int length); local void send_bits(s, value, length) deflate_state *s; diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h index c545df07a..a91fd3d66 100644 --- a/lib/libvgz/vgz.h +++ b/lib/libvgz/vgz.h @@ -78,8 +78,8 @@ extern "C" { even in the case of corrupted input. */ -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); +typedef voidpf (*alloc_func) (voidpf opaque, uInt items, uInt size); +typedef void (*free_func) (voidpf opaque, voidpf address); struct internal_state; @@ -222,7 +222,7 @@ typedef gz_header FAR *gz_headerp; /* basic functions */ -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +ZEXTERN const char * ZEXPORT zlibVersion (void); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check @@ -230,7 +230,7 @@ ZEXTERN const char * ZEXPORT zlibVersion OF((void)); */ /* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); +ZEXTERN int ZEXPORT deflateInit (z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If @@ -252,7 +252,7 @@ ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); */ -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT deflate (z_streamp strm, int flush); /* deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -365,7 +365,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); */ -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateEnd (z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -380,7 +380,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); /* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateInit (z_streamp strm); Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by @@ -402,7 +402,7 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); */ -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT inflate (z_streamp strm, int flush); /* inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -522,7 +522,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); */ -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateEnd (z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -540,12 +540,12 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); */ /* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateInit2 (z_streamp strm, int level, int method, int windowBits, int memLevel, - int strategy)); + int strategy); This is another version of deflateInit with more compression options. The fields zalloc, zfree and opaque must be initialized before by the caller. @@ -612,9 +612,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, - uInt dictLength)); + uInt dictLength); /* Initializes the compression dictionary from the given byte sequence without producing any compressed output. When using the zlib format, this @@ -656,9 +656,9 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, not perform any compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateGetDictionary (z_streamp strm, Bytef *dictionary, - uInt *dictLength)); + uInt *dictLength); /* Returns the sliding dictionary being maintained by deflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -678,8 +678,8 @@ ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT deflateCopy (z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -696,7 +696,7 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, destination. */ -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateReset (z_streamp strm); /* This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream @@ -707,9 +707,9 @@ ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateParams (z_streamp strm, int level, - int strategy)); + int strategy); /* Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2(). This can be @@ -745,11 +745,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, retried with more output space. */ -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, +ZEXTERN int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, - int max_chain)); + int max_chain); /* Fine tune deflate's internal compression parameters. This should only be used by someone who understands the algorithm used by zlib's deflate for @@ -762,8 +762,8 @@ ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. */ -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); +ZEXTERN uLong ZEXPORT deflateBound (z_streamp strm, + uLong sourceLen); /* deflateBound() returns an upper bound on the compressed size after deflation of sourceLen bytes. It must be called after deflateInit() or @@ -777,9 +777,9 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, than Z_FINISH or Z_NO_FLUSH are used. */ -ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, +ZEXTERN int ZEXPORT deflatePending (z_streamp strm, unsigned *pending, - int *bits)); + int *bits); /* deflatePending() returns the number of bytes and bits of output that have been generated, but not yet provided in the available output. The bytes not @@ -792,9 +792,9 @@ ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, +ZEXTERN int ZEXPORT deflatePrime (z_streamp strm, int bits, - int value)); + int value); /* deflatePrime() inserts bits in the deflate output stream. The intent is that this function is used to start off the deflate output with the bits @@ -809,8 +809,8 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, source stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT deflateSetHeader (z_streamp strm, + gz_headerp head); /* deflateSetHeader() provides gzip header information for when a gzip stream is requested by deflateInit2(). deflateSetHeader() may be called @@ -834,8 +834,8 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, */ /* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateInit2 (z_streamp strm, + int windowBits); This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized @@ -888,9 +888,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, deferred until inflate() is called. */ -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, +ZEXTERN int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, - uInt dictLength)); + uInt dictLength); /* Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate, @@ -911,9 +911,9 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, inflate(). */ -ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, +ZEXTERN int ZEXPORT inflateGetDictionary (z_streamp strm, Bytef *dictionary, - uInt *dictLength)); + uInt *dictLength); /* Returns the sliding dictionary being maintained by inflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -926,7 +926,7 @@ ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateSync (z_streamp strm); /* Skips invalid compressed data until a possible full flush point (see above for the description of deflate with Z_FULL_FLUSH) can be found, or until all @@ -945,8 +945,8 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); input each time, until success or end of the input data. */ -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT inflateCopy (z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -961,7 +961,7 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, destination. */ -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateReset (z_streamp strm); /* This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The @@ -971,8 +971,8 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateReset2 (z_streamp strm, + int windowBits); /* This function is the same as inflateReset, but it also permits changing the wrap and window size requests. The windowBits parameter is interpreted @@ -985,9 +985,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, the windowBits parameter is invalid. */ -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, +ZEXTERN int ZEXPORT inflatePrime (z_streamp strm, int bits, - int value)); + int value); /* This function inserts bits in the inflate input stream. The intent is that this function is used to start inflating at a bit position in the @@ -1006,7 +1006,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, stream state was inconsistent. */ -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +ZEXTERN long ZEXPORT inflateMark (z_streamp strm); /* This function returns two values, one in the lower 16 bits of the return value, and the other in the remaining upper bits, obtained by shifting the @@ -1034,8 +1034,8 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); source stream state was inconsistent. */ -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT inflateGetHeader (z_streamp strm, + gz_headerp head); /* inflateGetHeader() requests that gzip header information be stored in the provided gz_header structure. inflateGetHeader() may be called after @@ -1075,8 +1075,8 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, */ /* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); +ZEXTERN int ZEXPORT inflateBackInit (z_streamp strm, int windowBits, + unsigned char FAR *window); Initialize the internal stream state for decompression using inflateBack() calls. The fields zalloc, zfree and opaque in strm must be initialized @@ -1096,13 +1096,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, the version of the header file. */ -typedef unsigned (*in_func) OF((void FAR *, - z_const unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); +typedef unsigned (*in_func) (void FAR *, + z_const unsigned char FAR * FAR *); +typedef int (*out_func) (void FAR *, unsigned char FAR *, unsigned); -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, +ZEXTERN int ZEXPORT inflateBack (z_streamp strm, in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); + out_func out, void FAR *out_desc); /* inflateBack() does a raw inflate with a single call using a call-back interface for input and output. This is potentially more efficient than @@ -1170,7 +1170,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, cannot return Z_OK. */ -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateBackEnd (z_streamp strm); /* All memory allocated by inflateBackInit() is freed. @@ -1178,7 +1178,7 @@ ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); state was inconsistent. */ -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +ZEXTERN uLong ZEXPORT zlibCompileFlags (void); /* Return flags indicating compile-time options. Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: @@ -1231,8 +1231,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); you need special options. */ -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT compress (Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1246,9 +1246,9 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, buffer. */ -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, +ZEXTERN int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, - int level)); + int level); /* Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte @@ -1262,15 +1262,15 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, Z_STREAM_ERROR if the level parameter is invalid. */ -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +ZEXTERN uLong ZEXPORT compressBound (uLong sourceLen); /* compressBound() returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() call to allocate the destination buffer. */ -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1287,8 +1287,8 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, buffer with the uncompressed data up to that point. */ -ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong *sourceLen)); +ZEXTERN int ZEXPORT uncompress2 (Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen); /* Same as uncompress, except that sourceLen is a pointer, where the length of the source is *sourceLen. On return, *sourceLen is the number of @@ -1307,7 +1307,7 @@ ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ /* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen (const char *path, const char *mode); Open the gzip (.gz) file at path for reading and decompressing, or compressing and writing. The mode parameter is as in fopen ("rb" or "wb") @@ -1344,7 +1344,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); file could not be opened. */ -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +ZEXTERN gzFile ZEXPORT gzdopen (int fd, const char *mode); /* Associate a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (if the file has @@ -1367,7 +1367,7 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); will not detect if fd is invalid (unless fd is -1). */ -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +ZEXTERN int ZEXPORT gzbuffer (gzFile file, unsigned size); /* Set the internal buffer size used by this library's functions for file to size. The default buffer size is 8192 bytes. This function must be called @@ -1383,7 +1383,7 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); too late. */ -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +ZEXTERN int ZEXPORT gzsetparams (gzFile file, int level, int strategy); /* Dynamically update the compression level and strategy for file. See the description of deflateInit2 for the meaning of these parameters. Previously @@ -1394,7 +1394,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); or Z_MEM_ERROR if there is a memory allocation error. */ -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +ZEXTERN int ZEXPORT gzread (gzFile file, voidp buf, unsigned len); /* Read and decompress up to len uncompressed bytes from file into buf. If the input file is not in gzip format, gzread copies the given number of @@ -1424,8 +1424,8 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); Z_STREAM_ERROR. */ -ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, - gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfread (voidp buf, z_size_t size, z_size_t nitems, + gzFile file); /* Read and decompress up to nitems items of size size from file into buf, otherwise operating as gzread() does. This duplicates the interface of @@ -1450,14 +1450,14 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, file, resetting and retrying on end-of-file, when size is not 1. */ -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); +ZEXTERN int ZEXPORT gzwrite (gzFile file, voidpc buf, unsigned len); /* Compress and write the len uncompressed bytes at buf to file. gzwrite returns the number of uncompressed bytes written or 0 in case of error. */ -ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, - z_size_t nitems, gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfwrite (voidpc buf, z_size_t size, + z_size_t nitems, gzFile file); /* Compress and write nitems items of size size from buf to file, duplicating the interface of stdio's fwrite(), with size_t request and return types. If @@ -1485,7 +1485,7 @@ ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); This can be determined using zlibCompileFlags(). */ -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +ZEXTERN int ZEXPORT gzputs (gzFile file, const char *s); /* Compress and write the given null-terminated string s to file, excluding the terminating null character. @@ -1493,7 +1493,7 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); gzputs returns the number of characters written, or -1 in case of error. */ -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +ZEXTERN char * ZEXPORT gzgets (gzFile file, char *buf, int len); /* Read and decompress bytes from file into buf, until len-1 characters are read, or until a newline character is read and transferred to buf, or an @@ -1507,13 +1507,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); buf are indeterminate. */ -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +ZEXTERN int ZEXPORT gzputc (gzFile file, int c); /* Compress and write c, converted to an unsigned char, into file. gzputc returns the value that was written, or -1 in case of error. */ -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +ZEXTERN int ZEXPORT gzgetc (gzFile file); /* Read and decompress one byte from file. gzgetc returns this byte or -1 in case of end of file or error. This is implemented as a macro for speed. @@ -1522,7 +1522,7 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); points to has been clobbered or not. */ -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +ZEXTERN int ZEXPORT gzungetc (int c, gzFile file); /* Push c back onto the stream for file to be read as the first character on the next read. At least one character of push-back is always allowed. @@ -1534,7 +1534,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); gzseek() or gzrewind(). */ -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +ZEXTERN int ZEXPORT gzflush (gzFile file, int flush); /* Flush all pending output to file. The parameter flush is as in the deflate() function. The return value is the zlib error number (see function @@ -1550,8 +1550,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); */ /* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); +ZEXTERN z_off_t ZEXPORT gzseek (gzFile file, + z_off_t offset, int whence); Set the starting position to offset relative to whence for the next gzread or gzwrite on file. The offset represents a number of bytes in the @@ -1569,7 +1569,7 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, would be before the current position. */ -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +ZEXTERN int ZEXPORT gzrewind (gzFile file); /* Rewind file. This function is supported only for reading. @@ -1577,7 +1577,7 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); */ /* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gztell (gzFile file); Return the starting position for the next gzread or gzwrite on file. This position represents a number of bytes in the uncompressed data stream, @@ -1588,7 +1588,7 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); */ /* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gzoffset (gzFile file); Return the current compressed (actual) read or write offset of file. This offset includes the count of bytes that precede the gzip stream, for example @@ -1597,7 +1597,7 @@ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); be used for a progress indicator. On error, gzoffset() returns -1. */ -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +ZEXTERN int ZEXPORT gzeof (gzFile file); /* Return true (1) if the end-of-file indicator for file has been set while reading, false (0) otherwise. Note that the end-of-file indicator is set @@ -1612,7 +1612,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file)); has grown since the previous end of file was detected. */ -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +ZEXTERN int ZEXPORT gzdirect (gzFile file); /* Return true (1) if file is being copied directly while reading, or false (0) if file is a gzip stream being decompressed. @@ -1633,7 +1633,7 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); gzip file reading and decompression, which may not be desired.) */ -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose (gzFile file); /* Flush all pending output for file, if necessary, close file and deallocate the (de)compression state. Note that once file is closed, you @@ -1646,8 +1646,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); last read ended in the middle of a gzip stream, or Z_OK on success. */ -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_r (gzFile file); +ZEXTERN int ZEXPORT gzclose_w (gzFile file); /* Same as gzclose(), but gzclose_r() is only for use when reading, and gzclose_w() is only for use when writing or appending. The advantage to @@ -1658,7 +1658,7 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); zlib library. */ -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +ZEXTERN const char * ZEXPORT gzerror (gzFile file, int *errnum); /* Return the error message for the last error which occurred on file. errnum is set to zlib error number. If an error occurred in the file system @@ -1674,7 +1674,7 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); functions above that do not distinguish those cases in their return values. */ -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +ZEXTERN void ZEXPORT gzclearerr (gzFile file); /* Clear the error and end-of-file flags for file. This is analogous to the clearerr() function in stdio. This is useful for continuing to read a gzip @@ -1691,7 +1691,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); library. */ -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT adler32 (uLong adler, const Bytef *buf, uInt len); /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. An Adler-32 value is in the range of a 32-bit @@ -1711,15 +1711,15 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); if (adler != original_adler) error(); */ -ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT adler32_z (uLong adler, const Bytef *buf, + z_size_t len); /* Same as adler32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); +ZEXTERN uLong ZEXPORT adler32_combine (uLong adler1, uLong adler2, + z_off_t len2); Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for @@ -1729,7 +1729,7 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, negative, the result has no meaning or utility. */ -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT crc32 (uLong crc, const Bytef *buf, uInt len); /* Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. @@ -1747,14 +1747,14 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); if (crc != original_crc) error(); */ -ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT crc32_z (uLong crc, const Bytef *buf, + z_size_t len); /* Same as crc32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2); Combine two CRC-32 check values into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were @@ -1764,13 +1764,13 @@ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); */ /* -ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t len2); Return the operator corresponding to length len2, to be used with crc32_combine_op(). */ -ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); +ZEXTERN uLong ZEXPORT crc32_combine_op (uLong crc1, uLong crc2, uLong op); /* Give the same result as crc32_combine(), using op in place of len2. op is is generated from len2 by crc32_combine_gen(). This will be faster than @@ -1783,20 +1783,20 @@ ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, +ZEXTERN int ZEXPORT deflateInit_ (z_streamp strm, int level, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateInit_ (z_streamp strm, + const char *version, int stream_size); +ZEXTERN int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + int stream_size); +ZEXTERN int ZEXPORT inflateInit2_ (z_streamp strm, int windowBits, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateBackInit_ (z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, - int stream_size)); + int stream_size); #ifdef Z_PREFIX_SET # define z_deflateInit(strm, level) \ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) @@ -1841,7 +1841,7 @@ struct gzFile_s { unsigned char *next; z_off64_t pos; }; -ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +ZEXTERN int ZEXPORT gzgetc_ (gzFile file); /* backward compatibility */ #ifdef Z_PREFIX_SET # undef z_gzgetc # define z_gzgetc(g) \ @@ -1858,13 +1858,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ * without large file support, _LFS64_LARGEFILE must also be true */ #ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); + ZEXTERN gzFile ZEXPORT gzopen64 (const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64 (gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64 (gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64 (gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off64_t); #endif #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) @@ -1886,44 +1886,44 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ # define crc32_combine_gen crc32_combine_gen64 # endif # ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen64 (const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek64 (gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell64 (gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset64 (gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off_t); # endif #else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen (const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek (gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell (gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset (gzFile); + ZEXTERN uLong ZEXPORT adler32_combine (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t); #endif #else /* Z_SOLO */ - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t); #endif /* !Z_SOLO */ /* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); -ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); -ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp)); -ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); -ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +ZEXTERN const char * ZEXPORT zError (int); +ZEXTERN int ZEXPORT inflateSyncPoint (z_streamp); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table (void); +ZEXTERN int ZEXPORT inflateUndermine (z_streamp, int); +ZEXTERN int ZEXPORT inflateValidate (z_streamp, int); +ZEXTERN unsigned long ZEXPORT inflateCodesUsed (z_streamp); +ZEXTERN int ZEXPORT inflateResetKeep (z_streamp); +ZEXTERN int ZEXPORT deflateResetKeep (z_streamp); #if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, - const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen_w (const wchar_t *path, + const char *mode); #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) # ifndef Z_SOLO diff --git a/lib/libvgz/zutil.c b/lib/libvgz/zutil.c index 6a5b32c3e..4082f65ac 100644 --- a/lib/libvgz/zutil.c +++ b/lib/libvgz/zutil.c @@ -302,9 +302,9 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) #ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); +extern voidp malloc (uInt size); +extern voidp calloc (uInt items, uInt size); +extern void free (voidpf ptr); #endif voidpf ZLIB_INTERNAL zcalloc ( diff --git a/lib/libvgz/zutil.h b/lib/libvgz/zutil.h index 03cdb4d38..1ae739f15 100644 --- a/lib/libvgz/zutil.h +++ b/lib/libvgz/zutil.h @@ -191,9 +191,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* provide prototypes for these when building zlib without LFS */ #if !defined(_WIN32) && \ (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off_t); #endif /* common defaults */ @@ -232,16 +232,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define zmemzero(dest, len) memset(dest, 0, len) # endif #else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); + void ZLIB_INTERNAL zmemcpy (Bytef* dest, const Bytef* source, uInt len); + int ZLIB_INTERNAL zmemcmp (const Bytef* s1, const Bytef* s2, uInt len); + void ZLIB_INTERNAL zmemzero (Bytef* dest, uInt len); #endif /* Diagnostic functions */ #ifdef ZLIB_DEBUG # include extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); + extern void ZLIB_INTERNAL z_error (char *m); # define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;} @@ -258,9 +258,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #endif #ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); - void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); + voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, + unsigned size); + void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr); #endif #define ZALLOC(strm, items, size) \ From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] ccdabb717 Update to zlib 1.3 Message-ID: <20251210154306.89882102945@lists.vinyl-cache.org> commit ccdabb7173eee73c14c264af148776e9292375a3 Author: Poul-Henning Kamp Date: Wed Aug 30 12:36:01 2023 +0000 Update to zlib 1.3 diff --git a/lib/libvgz/adler32.c b/lib/libvgz/adler32.c index 25f11472c..860645ac6 100644 --- a/lib/libvgz/adler32.c +++ b/lib/libvgz/adler32.c @@ -61,11 +61,7 @@ local uLong adler32_combine_ (uLong adler1, uLong adler2, z_off64_t len2); #endif /* ========================================================================= */ -uLong ZEXPORT adler32_z(adler, buf, len) - uLong adler; - const Bytef *buf; - z_size_t len; -{ +uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) { unsigned long sum2; unsigned n; @@ -132,20 +128,12 @@ uLong ZEXPORT adler32_z(adler, buf, len) } /* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ +uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { return adler32_z(adler, buf, len); } /* ========================================================================= */ -local uLong adler32_combine_(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ +local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) { unsigned long sum1; unsigned long sum2; unsigned rem; @@ -170,28 +158,15 @@ local uLong adler32_combine_(adler1, adler2, len2) } /* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off_t len2; -{ +uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) { return adler32_combine_(adler1, adler2, len2); } -uLong ZEXPORT adler32_combine64(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ +uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) { return adler32_combine_(adler1, adler2, len2); } #else /* NOVGZ */ -uLong ZEXPORT adler32( - uLong adler, - const Bytef *buf, - uInt len -) -{ +uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { (void)adler; (void)buf; (void)len; diff --git a/lib/libvgz/crc32.c b/lib/libvgz/crc32.c index fd68dcbdf..f6971159c 100644 --- a/lib/libvgz/crc32.c +++ b/lib/libvgz/crc32.c @@ -103,19 +103,6 @@ # define ARMCRC32 #endif -/* Local functions. */ -local z_crc_t multmodp (z_crc_t a, z_crc_t b); -local z_crc_t x2nmodp (z_off64_t n, unsigned k); - -#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) - local z_word_t byte_swap (z_word_t word); -#endif - -#if defined(W) && !defined(ARMCRC32) - local z_crc_t crc_word (z_word_t data); - local z_word_t crc_word_big (z_word_t data); -#endif - #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) /* Swap the bytes in a z_word_t to convert between little and big endian. Any @@ -123,12 +110,7 @@ local z_crc_t x2nmodp (z_off64_t n, unsigned k); instruction, if one is available. This assumes that word_t is either 32 bits or 64 bits. */ -local z_word_t byte_swap (z_word_t word); - -local z_word_t byte_swap( - z_word_t word -) -{ +local z_word_t byte_swap (z_word_t word) { # if W == 8 return (word & 0xff00000000000000) >> 56 | @@ -149,14 +131,67 @@ local z_word_t byte_swap( } #endif +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Table of powers of x for combining CRC-32s, filled in by make_crc_table() + * below. + */ + local z_crc_t FAR x2n_table[32]; +#else +/* ========================================================================= + * Tables for byte-wise and braided CRC-32 calculations, and a table of powers + * of x for combining CRC-32s, all made by make_crc_table(). + */ +# include "crc32.h" +#endif + /* CRC polynomial. */ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ -#ifdef DYNAMIC_CRC_TABLE +/* + Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, + reflected. For speed, this requires that a not be zero. + */ +local z_crc_t multmodp(z_crc_t a, z_crc_t b) { + z_crc_t m, p; + + m = (z_crc_t)1 << 31; + p = 0; + for (;;) { + if (a & m) { + p ^= b; + if ((a & (m - 1)) == 0) + break; + } + m >>= 1; + b = b & 1 ? (b >> 1) ^ POLY : b >> 1; + } + return p; +} + +/* + Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been + initialized. + */ +local z_crc_t x2nmodp(z_off64_t n, unsigned k) { + z_crc_t p; + + p = (z_crc_t)1 << 31; /* x^0 == 1 */ + while (n) { + if (n & 1) + p = multmodp(x2n_table[k & 31], p); + n >>= 1; + k++; + } + return p; +} +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Build the tables for byte-wise and braided CRC-32 calculations, and a table + * of powers of x for combining CRC-32s. + */ local z_crc_t FAR crc_table[256]; -local z_crc_t FAR x2n_table[32]; -local void make_crc_table (void); #ifdef W local z_word_t FAR crc_big_table[256]; local z_crc_t FAR crc_braid_table[W][256]; @@ -179,7 +214,6 @@ local void make_crc_table (void); /* Definition of once functionality. */ typedef struct once_s once_t; -local void once (once_t *, void (*)(void)); /* Check for the availability of atomics. */ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ @@ -199,10 +233,7 @@ struct once_s { invoke once() at the same time. The state must be a once_t initialized with ONCE_INIT. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!atomic_load(&state->done)) { if (atomic_flag_test_and_set(&state->begun)) while (!atomic_load(&state->done)) @@ -225,10 +256,7 @@ struct once_s { /* Test and set. Alas, not atomic, but tries to minimize the period of vulnerability. */ -local int test_and_set (int volatile *); -local int test_and_set(flag) - int volatile *flag; -{ +local int test_and_set (int volatile *flag) { int was; was = *flag; @@ -237,10 +265,7 @@ local int test_and_set(flag) } /* Run the provided init() function once. This is not thread-safe. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!state->done) { if (test_and_set(&state->begun)) while (!state->done) @@ -282,8 +307,7 @@ local once_t made = ONCE_INIT; combinations of CRC register values and incoming bytes. */ -local void make_crc_table() -{ +local void make_crc_table(void) { unsigned i, j, n; z_crc_t p; @@ -450,11 +474,7 @@ local void make_crc_table() Write the 32-bit values in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table(out, table, k) - FILE *out; - const z_crc_t FAR *table; - int k; -{ +local void write_table(FILE *out, const z_crc_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -467,11 +487,7 @@ local void write_table(out, table, k) Write the high 32-bits of each value in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table32hi(out, table, k) -FILE *out; -const z_word_t FAR *table; -int k; -{ +local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -487,11 +503,7 @@ int k; bits. If not, then the type cast and format string can be adjusted accordingly. */ -local void write_table64(out, table, k) - FILE *out; - const z_word_t FAR *table; - int k; -{ +local void write_table64(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -501,8 +513,7 @@ local void write_table64(out, table, k) } /* Actually do the deed. */ -int main() -{ +int main(void) { make_crc_table(); return 0; } @@ -514,12 +525,7 @@ int main() Generate the little and big-endian braid tables for the given n and z_word_t size w. Each array must have room for w blocks of 256 elements. */ -local void braid(ltl, big, n, w) - z_crc_t ltl[][256]; - z_word_t big[][256]; - int n; - int w; -{ +local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) { int k; z_crc_t i, p, q; for (k = 0; k < w; k++) { @@ -534,71 +540,13 @@ local void braid(ltl, big, n, w) } #endif -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables for byte-wise and braided CRC-32 calculations, and a table of powers - * of x for combining CRC-32s, all made by make_crc_table(). - */ -#include "crc32.h" #endif /* DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Routines used for CRC calculation. Some are also required for the table - * generation above. - */ - -/* - Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, - reflected. For speed, this requires that a not be zero. - */ -local z_crc_t multmodp( - z_crc_t a, - z_crc_t b -) -{ - z_crc_t m, p; - - m = (z_crc_t)1 << 31; - p = 0; - for (;;) { - if (a & m) { - p ^= b; - if ((a & (m - 1)) == 0) - break; - } - m >>= 1; - b = b & 1 ? (b >> 1) ^ POLY : b >> 1; - } - return p; -} - -/* - Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been - initialized. - */ -local z_crc_t x2nmodp( - z_off64_t n, - unsigned k -) -{ - z_crc_t p; - - p = (z_crc_t)1 << 31; /* x^0 == 1 */ - while (n) { - if (n & 1) - p = multmodp(x2n_table[k & 31], p); - n >>= 1; - k++; - } - return p; -} - /* ========================================================================= * This function can be used by asm versions of crc32(), and to force the * generation of the CRC tables in a threaded application. */ -const z_crc_t FAR * ZEXPORT get_crc_table(void) -{ +const z_crc_t FAR * ZEXPORT get_crc_table(void) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -624,11 +572,8 @@ const z_crc_t FAR * ZEXPORT get_crc_table(void) #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */ #define Z_BATCH_MIN 800 /* fewest words in a final batch */ -unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - z_size_t len; -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { z_crc_t val; z_word_t crc1, crc2; const z_word_t *word; @@ -728,24 +673,14 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) least-significant byte of the word as the first byte of data, without any pre or post conditioning. This is used to combine the CRCs of each braid. */ -local z_crc_t crc_word (z_word_t data); - -local z_crc_t crc_word( - z_word_t data -) -{ +local z_crc_t crc_word (z_word_t data) { int k; for (k = 0; k < W; k++) data = (data >> 8) ^ crc_table[data & 0xff]; return (z_crc_t)data; } -local z_word_t crc_word_big (z_word_t data); - -local z_word_t crc_word_big( - z_word_t data -) -{ +local z_word_t crc_word_big (z_word_t data) { int k; for (k = 0; k < W; k++) data = (data << 8) ^ @@ -756,12 +691,8 @@ local z_word_t crc_word_big( #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32_z( - unsigned long crc, - const unsigned char FAR *buf, - z_size_t len -) -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { /* Return initial CRC, if requested. */ if (buf == Z_NULL) return 0; @@ -793,8 +724,8 @@ unsigned long ZEXPORT crc32_z( words = (z_word_t const *)(intptr_t)buf; /* Do endian check at execution time instead of compile time, since ARM - processors can change the endianess at execution time. If the - compiler knows what the endianess will be, it can optimize out the + processors can change the endianness at execution time. If the + compiler knows what the endianness will be, it can optimize out the check and the unused branch. */ endian = 1; if (*(unsigned char *)&endian) { @@ -1081,22 +1012,13 @@ unsigned long ZEXPORT crc32_z( #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32( - unsigned long crc, - const unsigned char FAR *buf, - uInt len -) -{ +unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, + uInt len) { return crc32_z(crc, buf, len); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine64( - uLong crc1, - uLong crc2, - z_off64_t len2 -) -{ +uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1104,20 +1026,12 @@ uLong ZEXPORT crc32_combine64( } /* ========================================================================= */ -uLong ZEXPORT crc32_combine( - uLong crc1, - uLong crc2, - z_off_t len2 -) -{ +uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) { return crc32_combine64(crc1, crc2, (z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen64( - z_off64_t len2 -) -{ +uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1125,19 +1039,11 @@ uLong ZEXPORT crc32_combine_gen64( } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen( - z_off_t len2 -) -{ +uLong ZEXPORT crc32_combine_gen(z_off_t len2) { return crc32_combine_gen64((z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_op( - uLong crc1, - uLong crc2, - uLong op -) -{ +uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) { return multmodp(op, crc1) ^ (crc2 & 0xffffffff); } diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index 4dd3447aa..bd9d5f82a 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + * Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -53,7 +53,7 @@ extern const char deflate_copyright[]; const char deflate_copyright[] = - " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; + " deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -61,9 +61,6 @@ const char deflate_copyright[] = copyright string in the executable of your product. */ -/* =========================================================================== - * Function prototypes. - */ typedef enum { need_more, /* block not completed, need more input or more output */ block_done, /* block flush performed */ @@ -74,9 +71,6 @@ typedef enum { typedef block_state (*compress_func) (deflate_state *s, int flush); /* Compression function. Returns the block state after the call. */ -local int deflateStateCheck (z_streamp strm); -local void slide_hash (deflate_state *s); -local void fill_window (deflate_state *s); local block_state deflate_stored (deflate_state *s, int flush); local block_state deflate_fast (deflate_state *s, int flush); #ifndef FASTEST @@ -86,16 +80,6 @@ local block_state deflate_slow (deflate_state *s, int flush); local block_state deflate_rle (deflate_state *s, int flush); local block_state deflate_huff (deflate_state *s, int flush); #endif /* NOVGZ */ -local void lm_init (deflate_state *s); -local void putShortMSB (deflate_state *s, uInt b); -local void flush_pending (z_streamp strm); -local unsigned read_buf (z_streamp strm, Bytef *buf, unsigned size); -local uInt longest_match (deflate_state *s, IPos cur_match); - -#ifdef ZLIB_DEBUG -local void check_match (deflate_state *s, IPos start, IPos match, - int length); -#endif /* =========================================================================== * Local data @@ -198,10 +182,12 @@ local const config configuration_table[10] = { * bit values at the expense of memory usage). We slide even when level == 0 to * keep the hash table consistent if we switch back to level > 0 later. */ -local void slide_hash( - deflate_state *s -) -{ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __attribute__((no_sanitize("memory"))) +# endif +#endif +local void slide_hash(deflate_state *s) { unsigned n, m; Posf *p; uInt wsize = s->w_size; @@ -225,15 +211,171 @@ local void slide_hash( #endif } +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) { + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, buf, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, buf, len); + } +#endif + strm->next_in += len; + strm->total_in += len; + + return len; +} + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(deflate_state *s) { + unsigned n; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize+MAX_DIST(s)) { + + zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + if (s->insert > s->strstart) + s->insert = s->strstart; + slide_hash(s); + more += wsize; + } + if (s->strm->avail_in == 0) break; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead + s->insert >= MIN_MATCH) { + uInt str = s->strstart - s->insert; + s->ins_h = s->window[str]; + UPDATE_HASH(s, s->ins_h, s->window[str + 1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + while (s->insert) { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + s->insert--; + if (s->lookahead + s->insert < MIN_MATCH) + break; + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } + + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "not enough room for search"); +} + + #ifdef NOVGZ /* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ +int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, + int stream_size) { return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, version, stream_size); /* To do: ignore strm->next_in if we use it as window */ @@ -242,17 +384,9 @@ int ZEXPORT deflateInit_(strm, level, version, stream_size) #endif /* NOVGZ */ /* ========================================================================= */ -int ZEXPORT deflateInit2_( - z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy, - const char *version, - int stream_size -) -{ +int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, int strategy, + const char *version, int stream_size) { deflate_state *s; int wrap = 1; static const char my_version[] = ZLIB_VERSION; @@ -394,10 +528,7 @@ int ZEXPORT deflateInit2_( /* ========================================================================= * Check for a valid deflate stream state. Return 0 if ok, 1 if not. */ -local int deflateStateCheck ( - z_streamp strm -) -{ +local int deflateStateCheck(z_streamp strm) { deflate_state *s; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -422,11 +553,8 @@ local int deflateStateCheck ( #ifdef NOVGZ /* ========================================================================= */ -int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ +int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { deflate_state *s; uInt str, n; int wrap; @@ -491,11 +619,8 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) } /* ========================================================================= */ -int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) - z_streamp strm; - Bytef *dictionary; - uInt *dictLength; -{ +int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { deflate_state *s; uInt len; @@ -515,10 +640,7 @@ int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) #endif /* NOVGZ */ /* ========================================================================= */ -int ZEXPORT deflateResetKeep ( - z_streamp strm -) -{ +int ZEXPORT deflateResetKeep(z_streamp strm) { deflate_state *s; if (deflateStateCheck(strm)) { @@ -554,11 +676,32 @@ int ZEXPORT deflateResetKeep ( return Z_OK; } +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init(deflate_state *s) { + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->insert = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +} + /* ========================================================================= */ -int ZEXPORT deflateReset ( - z_streamp strm -) -{ +int ZEXPORT deflateReset(z_streamp strm) { int ret; ret = deflateResetKeep(strm); @@ -570,11 +713,7 @@ int ZEXPORT deflateReset ( #ifdef NOVGZ /* ========================================================================= */ -int ZEXPORT deflateSetHeader ( - z_streamp strm, - gz_headerp head -) -{ +int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { if (deflateStateCheck(strm) || strm->state->wrap != 2) return Z_STREAM_ERROR; strm->state->gzhead = head; @@ -582,12 +721,7 @@ int ZEXPORT deflateSetHeader ( } /* ========================================================================= */ -int ZEXPORT deflatePending ( - z_streamp strm, - unsigned *pending, - int *bits -) -{ +int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (pending != Z_NULL) *pending = strm->state->pending; @@ -597,11 +731,7 @@ int ZEXPORT deflatePending ( } /* ========================================================================= */ -int ZEXPORT deflatePrime (strm, bits, value) - z_streamp strm; - int bits; - int value; -{ +int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { deflate_state *s; int put; @@ -624,11 +754,7 @@ int ZEXPORT deflatePrime (strm, bits, value) } /* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ +int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { deflate_state *s; compress_func func; @@ -673,13 +799,8 @@ int ZEXPORT deflateParams(strm, level, strategy) } /* ========================================================================= */ -int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) - z_streamp strm; - int good_length; - int max_lazy; - int nice_length; - int max_chain; -{ +int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain) { deflate_state *s; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -715,10 +836,7 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) * * Shifts are used to approximate divisions, for speed. */ -uLong ZEXPORT deflateBound(strm, sourceLen) - z_streamp strm; - uLong sourceLen; -{ +uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { deflate_state *s; uLong fixedlen, storelen, wraplen; @@ -774,7 +892,8 @@ uLong ZEXPORT deflateBound(strm, sourceLen) /* if not default parameters, return one of the conservative bounds */ if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen; + return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + + wraplen; /* default settings: return tight bound for that case -- ~0.03% overhead plus a small constant */ @@ -789,11 +908,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen) * IN assertion: the stream state is correct and there is enough room in * pending_buf. */ -local void putShortMSB ( - deflate_state *s, - uInt b -) -{ +local void putShortMSB(deflate_state *s, uInt b) { put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b & 0xff)); } @@ -804,10 +919,7 @@ local void putShortMSB ( * applications may wish to modify it to avoid allocating a large * strm->next_out buffer and copying into it. (See also read_buf()). */ -local void flush_pending( - z_streamp strm -) -{ +local void flush_pending(z_streamp strm) { unsigned len; deflate_state *s = strm->state; @@ -838,11 +950,7 @@ local void flush_pending( } while (0) /* ========================================================================= */ -int ZEXPORT deflate ( - z_streamp strm, - int flush -) -{ +int ZEXPORT deflate(z_streamp strm, int flush) { int old_flush; /* value of flush param for previous deflate call */ deflate_state *s; @@ -1167,10 +1275,7 @@ int ZEXPORT deflate ( } /* ========================================================================= */ -int ZEXPORT deflateEnd ( - z_streamp strm -) -{ +int ZEXPORT deflateEnd(z_streamp strm) { int status; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1196,11 +1301,10 @@ int ZEXPORT deflateEnd ( * To simplify the source, this is not supported for 16-bit MSDOS (which * doesn't have enough memory anyway to duplicate compression states). */ -int ZEXPORT deflateCopy (dest, source) - z_streamp dest; - z_streamp source; -{ +int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { #ifdef MAXSEG_64K + (void)dest; + (void)source; return Z_STREAM_ERROR; #else deflate_state *ds; @@ -1250,67 +1354,7 @@ int ZEXPORT deflateCopy (dest, source) #endif /* NOVGZ */ -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local unsigned read_buf( - z_streamp strm, - Bytef *buf, - unsigned size -) -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init ( - deflate_state *s -) -{ - s->window_size = (ulg)2L*s->w_size; - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -} #ifndef FASTEST /* =========================================================================== @@ -1322,11 +1366,7 @@ local void lm_init ( * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * OUT assertion: the match length is not greater than s->lookahead. */ -local uInt longest_match( - deflate_state *s, - IPos cur_match /* current match */ -) -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { unsigned chain_length = s->max_chain_length;/* max hash chain length */ register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ @@ -1474,10 +1514,7 @@ local uInt longest_match( /* --------------------------------------------------------------------------- * Optimized version for FASTEST only */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ register int len; /* length of current match */ @@ -1538,11 +1575,7 @@ local uInt longest_match(s, cur_match) /* =========================================================================== * Check that the match at match_start is indeed a match. */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ +local void check_match(deflate_state *s, IPos start, IPos match, int length) { /* check that the match is indeed a match */ if (zmemcmp(s->window + match, s->window + start, length) != EQUAL) { @@ -1562,138 +1595,6 @@ local void check_match(s, start, match, length) # define check_match(s, start, match, length) #endif /* ZLIB_DEBUG */ -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window( - deflate_state *s -) -{ - unsigned n; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize+MAX_DIST(s)) { - - zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - if (s->insert > s->strstart) - s->insert = s->strstart; - slide_hash(s); - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - /* =========================================================================== * Flush the current block, with given end-of-file flag. * IN assertion: strstart is set to the end of the current match. @@ -1738,11 +1639,7 @@ local void fill_window( * copied. It is most efficient with large input and output buffers, which * maximizes the opportunities to have a single copy from next_in to next_out. */ -local block_state deflate_stored( - deflate_state *s, - int flush -) -{ +local block_state deflate_stored(deflate_state *s, int flush) { /* Smallest worthy block size when not flushing or finishing. By default * this is 32K. This can be as small as 507 bytes for memLevel == 1. For * large input and output buffers, the stored block size will be larger. @@ -1929,11 +1826,7 @@ local block_state deflate_stored( * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */ -local block_state deflate_fast( - deflate_state *s, - int flush -) -{ +local block_state deflate_fast(deflate_state *s, int flush) { IPos hash_head; /* head of the hash chain */ int bflush; /* set if current block must be flushed */ @@ -2032,11 +1925,7 @@ local block_state deflate_fast( * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */ -local block_state deflate_slow( - deflate_state *s, - int flush -) -{ +local block_state deflate_slow(deflate_state *s, int flush) { IPos hash_head; /* head of hash chain */ int bflush; /* set if current block must be flushed */ @@ -2166,10 +2055,7 @@ local block_state deflate_slow( * one. Do not maintain a hash table. (It will be regenerated if this run of * deflate switches away from Z_RLE.) */ -local block_state deflate_rle(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_rle(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ uInt prev; /* byte at distance one to match */ Bytef *scan, *strend; /* scan goes up to strend for length of run */ @@ -2240,10 +2126,7 @@ local block_state deflate_rle(s, flush) * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. * (It will be regenerated if this run of deflate switches away from Huffman.) */ -local block_state deflate_huff(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_huff(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ for (;;) { diff --git a/lib/libvgz/gzguts.h b/lib/libvgz/gzguts.h index 433c8d8af..cfde69df5 100644 --- a/lib/libvgz/gzguts.h +++ b/lib/libvgz/gzguts.h @@ -7,9 +7,8 @@ # ifndef _LARGEFILE_SOURCE # define _LARGEFILE_SOURCE 1 # endif -# ifdef _FILE_OFFSET_BITS # undef _FILE_OFFSET_BITS -# endif +# undef _TIME_BITS #endif #ifdef HAVE_HIDDEN diff --git a/lib/libvgz/inffast.c b/lib/libvgz/inffast.c index 01b00436b..1f49bd5a5 100644 --- a/lib/libvgz/inffast.c +++ b/lib/libvgz/inffast.c @@ -47,11 +47,7 @@ requires strm->avail_out >= 258 for each loop to avoid checking for output space. */ -void ZLIB_INTERNAL inflate_fast( - z_streamp strm, - unsigned start /* inflate()'s starting value for strm->avail_out */ -) -{ +void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { struct inflate_state FAR *state; z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *last; /* have enough input while in < last */ diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index 7cdee41b0..deae8231f 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -91,23 +91,7 @@ # endif #endif -/* function prototypes */ -local int inflateStateCheck (z_streamp strm); -local void fixedtables (struct inflate_state FAR *state); -local int updatewindow (z_streamp strm, const unsigned char FAR *end, - unsigned copy); -#ifdef BUILDFIXED - void makefixed (void); -#endif -#ifdef NOVGZ -local unsigned syncsearch (unsigned FAR *have, const unsigned char FAR *buf, - unsigned len); -#endif /* NOVGZ */ - -local int inflateStateCheck( - z_streamp strm -) -{ +local int inflateStateCheck(z_streamp strm) { struct inflate_state FAR *state; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -119,10 +103,7 @@ local int inflateStateCheck( return 0; } -int ZEXPORT inflateResetKeep( - z_streamp strm -) -{ +int ZEXPORT inflateResetKeep(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -147,10 +128,7 @@ int ZEXPORT inflateResetKeep( return Z_OK; } -int ZEXPORT inflateReset( - z_streamp strm -) -{ +int ZEXPORT inflateReset(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -161,11 +139,7 @@ int ZEXPORT inflateReset( return inflateResetKeep(strm); } -int ZEXPORT inflateReset2( - z_streamp strm, - int windowBits -) -{ +int ZEXPORT inflateReset2(z_streamp strm, int windowBits) { int wrap; struct inflate_state FAR *state; @@ -202,13 +176,8 @@ int ZEXPORT inflateReset2( return inflateReset(strm); } -int ZEXPORT inflateInit2_( - z_streamp strm, - int windowBits, - const char *version, - int stream_size -) -{ +int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size) { int ret; struct inflate_state FAR *state; @@ -249,24 +218,17 @@ int ZEXPORT inflateInit2_( #ifdef NOVGZ -int ZEXPORT inflateInit_( - z_streamp strm, - const char *version, - int stream_size -) -{ +int ZEXPORT inflateInit_(z_streamp strm, const char *version, + int stream_size) { return inflateInit2_(strm, DEF_WBITS, version, stream_size); } -int ZEXPORT inflatePrime( - z_streamp strm, - int bits, - int value -) -{ +int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits == 0) + return Z_OK; state = (struct inflate_state FAR *)strm->state; if (bits < 0) { state->hold = 0; @@ -292,10 +254,7 @@ int ZEXPORT inflatePrime( used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables( - struct inflate_state FAR *state -) -{ +local void fixedtables(struct inflate_state FAR *state) { #ifdef BUILDFIXED static int virgin = 1; static code *lenfix, *distfix; @@ -357,7 +316,7 @@ local void fixedtables( a.out > inffixed.h */ -void makefixed() +void makefixed(void) { unsigned low, size; struct inflate_state state; @@ -411,12 +370,7 @@ void makefixed() output will fall in the output data, making match copies simpler and faster. The advantage may be dependent on the size of the processor's data caches. */ -local int updatewindow( - z_streamp strm, - const Bytef *end, - unsigned copy -) -{ +local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) { struct inflate_state FAR *state; unsigned dist; @@ -638,11 +592,7 @@ local int updatewindow( will return Z_BUF_ERROR if it has not reached the end of the stream. */ -int ZEXPORT inflate( - z_streamp strm, - int flush -) -{ +int ZEXPORT inflate(z_streamp strm, int flush) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ @@ -1323,10 +1273,7 @@ int ZEXPORT inflate( return ret; } -int ZEXPORT inflateEnd( - z_streamp strm -) -{ +int ZEXPORT inflateEnd(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1340,11 +1287,8 @@ int ZEXPORT inflateEnd( #ifdef NOVGZ -int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) -z_streamp strm; -Bytef *dictionary; -uInt *dictLength; -{ +int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { struct inflate_state FAR *state; /* check state */ @@ -1363,11 +1307,8 @@ uInt *dictLength; return Z_OK; } -int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) -z_streamp strm; -const Bytef *dictionary; -uInt dictLength; -{ +int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { struct inflate_state FAR *state; unsigned long dictid; int ret; @@ -1398,10 +1339,7 @@ uInt dictLength; return Z_OK; } -int ZEXPORT inflateGetHeader(strm, head) -z_streamp strm; -gz_headerp head; -{ +int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) { struct inflate_state FAR *state; /* check state */ @@ -1426,11 +1364,8 @@ gz_headerp head; called again with more data and the *have state. *have is initialized to zero for the first call. */ -local unsigned syncsearch(have, buf, len) -unsigned FAR *have; -const unsigned char FAR *buf; -unsigned len; -{ +local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, + unsigned len) { unsigned got; unsigned next; @@ -1449,9 +1384,7 @@ unsigned len; return next; } -int ZEXPORT inflateSync(strm) -z_streamp strm; -{ +int ZEXPORT inflateSync(z_streamp strm) { unsigned len; /* number of bytes to look at or looked at */ int flags; /* temporary to save header status */ unsigned long in, out; /* temporary to save total_in and total_out */ @@ -1507,9 +1440,7 @@ z_streamp strm; block. When decompressing, PPP checks that at the end of input packet, inflate is waiting for these length bytes. */ -int ZEXPORT inflateSyncPoint(strm) -z_streamp strm; -{ +int ZEXPORT inflateSyncPoint(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1517,10 +1448,7 @@ z_streamp strm; return state->mode == STORED && state->bits == 0; } -int ZEXPORT inflateCopy(dest, source) -z_streamp dest; -z_streamp source; -{ +int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { struct inflate_state FAR *state; struct inflate_state FAR *copy; unsigned char FAR *window; @@ -1564,10 +1492,7 @@ z_streamp source; return Z_OK; } -int ZEXPORT inflateUndermine(strm, subvert) -z_streamp strm; -int subvert; -{ +int ZEXPORT inflateUndermine(z_streamp strm, int subvert) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1582,10 +1507,7 @@ int subvert; #endif } -int ZEXPORT inflateValidate(strm, check) -z_streamp strm; -int check; -{ +int ZEXPORT inflateValidate(z_streamp strm, int check) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1597,9 +1519,7 @@ int check; return Z_OK; } -long ZEXPORT inflateMark(strm) -z_streamp strm; -{ +long ZEXPORT inflateMark(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) @@ -1610,9 +1530,7 @@ z_streamp strm; (state->mode == MATCH ? state->was - state->length : 0)); } -unsigned long ZEXPORT inflateCodesUsed(strm) -z_streamp strm; -{ +unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return (unsigned long)-1; state = (struct inflate_state FAR *)strm->state; diff --git a/lib/libvgz/inftrees.c b/lib/libvgz/inftrees.c index a794b0e27..a6a8a9edc 100644 --- a/lib/libvgz/inftrees.c +++ b/lib/libvgz/inftrees.c @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2022 Mark Adler + * Copyright (C) 1995-2023 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -10,7 +10,7 @@ extern const char inflate_copyright[]; const char inflate_copyright[] = - " inflate 1.2.13 Copyright 1995-2022 Mark Adler "; + " inflate 1.3 Copyright 1995-2023 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -30,15 +30,9 @@ const char inflate_copyright[] = table index bits. It will differ if the request is greater than the longest code or if it is less than the shortest code. */ -int ZLIB_INTERNAL inflate_table( - codetype type, - unsigned short FAR *lens, - unsigned codes, - code FAR * FAR *table, - unsigned FAR *bits, - unsigned short FAR *work -) -{ +int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work) { unsigned len; /* a code's length in bits */ unsigned sym; /* index of code symbols */ unsigned min, max; /* minimum and maximum code lengths */ @@ -64,7 +58,7 @@ int ZLIB_INTERNAL inflate_table( 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c index 7f1f949fe..51fdadba8 100644 --- a/lib/libvgz/trees.c +++ b/lib/libvgz/trees.c @@ -122,36 +122,113 @@ struct static_tree_desc_s { int max_length; /* max bit length for the codes */ }; -local const static_tree_desc static_l_desc = +#ifdef NO_INIT_GLOBAL_POINTERS +# define TCONST +#else +# define TCONST const +#endif + +local TCONST static_tree_desc static_l_desc = {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; -local const static_tree_desc static_d_desc = +local TCONST static_tree_desc static_d_desc = {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; -local const static_tree_desc static_bl_desc = +local TCONST static_tree_desc static_bl_desc = {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; /* =========================================================================== - * Local (static) routines in this file. + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 */ +local unsigned bi_reverse(unsigned code, int len) { + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} -local void tr_static_init (void); -local void init_block (deflate_state *s); -local void pqdownheap (deflate_state *s, ct_data *tree, int k); -local void gen_bitlen (deflate_state *s, tree_desc *desc); -local void gen_codes (ct_data *tree, int max_code, ushf *bl_count); -local void build_tree (deflate_state *s, tree_desc *desc); -local void scan_tree (deflate_state *s, ct_data *tree, int max_code); -local void send_tree (deflate_state *s, ct_data *tree, int max_code); -local int build_bl_tree (deflate_state *s); -local void send_all_trees (deflate_state *s, int lcodes, int dcodes, - int blcodes); -local void compress_block (deflate_state *s, const ct_data *ltree, - const ct_data *dtree); -local int detect_data_type (deflate_state *s); -local unsigned bi_reverse (unsigned code, int len); -local void bi_windup (deflate_state *s); -local void bi_flush (deflate_state *s); +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(deflate_state *s) { + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(deflate_state *s) { + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef ZLIB_DEBUG + s->bits_sent = (s->bits_sent+7) & ~7; +#endif +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) { + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + unsigned code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + code = (code + bl_count[bits-1]) << 1; + next_code[bits] = (ush)code; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS]-1 == (1<> 8)); \ -} - /* =========================================================================== * Send a value on a given number of bits. * IN assertion: length <= 16 and value fits in length bits. */ #ifdef ZLIB_DEBUG -local void send_bits (deflate_state *s, int value, int length); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ +local void send_bits(deflate_state *s, int value, int length) { Tracevv((stderr," l %2d v %4x ", length, value)); Assert(length > 0 && length <= 15, "invalid length"); s->bits_sent += (ulg)length; @@ -229,8 +291,7 @@ local void send_bits(s, value, length) /* =========================================================================== * Initialize the various 'constant' tables. */ -local void tr_static_init(void) -{ +local void tr_static_init(void) { #if defined(GEN_TREES_H) || !defined(STDC) static int static_init_done = 0; int n; /* iterates over tree elements */ @@ -323,8 +384,7 @@ local void tr_static_init(void) ((i) == (last)? "\n};\n\n" : \ ((i) % (width) == (width)-1 ? ",\n" : ", ")) -void gen_trees_header() -{ +void gen_trees_header(void) { FILE *header = fopen("trees.h", "w"); int i; @@ -373,13 +433,26 @@ void gen_trees_header() } #endif /* GEN_TREES_H */ +/* =========================================================================== + * Initialize a new block. + */ +local void init_block(deflate_state *s) { + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->sym_next = s->matches = 0; +} + /* =========================================================================== * Initialize the tree data structures for a new zlib stream. */ -void ZLIB_INTERNAL _tr_init( - deflate_state *s -) -{ +void ZLIB_INTERNAL _tr_init(deflate_state *s) { tr_static_init(); s->l_desc.dyn_tree = s->dyn_ltree; @@ -402,25 +475,6 @@ void ZLIB_INTERNAL _tr_init( init_block(s); } -/* =========================================================================== - * Initialize a new block. - */ -local void init_block( - deflate_state *s -) -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->sym_next = s->matches = 0; -} - #define SMALLEST 1 /* Index within the heap array of least frequent node in the Huffman tree */ @@ -450,12 +504,7 @@ local void init_block( * when the heap property is re-established (each father smaller than its * two sons). */ -local void pqdownheap( - deflate_state *s, - ct_data *tree, /* the tree to restore */ - int k /* node to move down */ -) -{ +local void pqdownheap(deflate_state *s, ct_data *tree, int k) { int v = s->heap[k]; int j = k << 1; /* left son of k */ while (j <= s->heap_len) { @@ -486,11 +535,7 @@ local void pqdownheap( * The length opt_len is updated; static_len is also updated if stree is * not null. */ -local void gen_bitlen( - deflate_state *s, - tree_desc *desc /* the tree descriptor */ -) -{ +local void gen_bitlen(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; int max_code = desc->max_code; const ct_data *stree = desc->stat_desc->static_tree; @@ -565,49 +610,9 @@ local void gen_bitlen( } } -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes ( - ct_data *tree, /* the tree to decorate */ - int max_code, /* largest code with non zero frequency */ - ushf *bl_count /* number of codes at each bit length */ -) -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - unsigned code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits-1]) << 1; - next_code[bits] = (ush)code; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS]-1 == (1< +#endif /* =========================================================================== * Construct one Huffman tree and assigns the code bit strings and lengths. @@ -617,11 +622,7 @@ local void gen_codes ( * and corresponding code. The length opt_len is updated; static_len is * also updated if stree is not null. The field max_code is set. */ -local void build_tree( - deflate_state *s, - tree_desc *desc /* the tree descriptor */ -) -{ +local void build_tree(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; const ct_data *stree = desc->stat_desc->static_tree; int elems = desc->stat_desc->elems; @@ -706,12 +707,7 @@ local void build_tree( * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */ -local void scan_tree ( - deflate_state *s, - ct_data *tree, /* the tree to be scanned */ - int max_code /* and its largest code of non zero frequency */ -) -{ +local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -752,12 +748,7 @@ local void scan_tree ( * Send a literal or distance tree in compressed form, using the codes in * bl_tree. */ -local void send_tree ( - deflate_state *s, - ct_data *tree, /* the tree to be scanned */ - int max_code /* and its largest code of non zero frequency */ -) -{ +local void send_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -804,10 +795,7 @@ local void send_tree ( * Construct the Huffman tree for the bit lengths and return the index in * bl_order of the last bit length code to send. */ -local int build_bl_tree( - deflate_state *s -) -{ +local int build_bl_tree(deflate_state *s) { int max_blindex; /* index of last bit length code of non zero freq */ /* Determine the bit length frequencies for literal and distance trees */ @@ -840,13 +828,8 @@ local int build_bl_tree( * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ -local void send_all_trees( - deflate_state *s, - int lcodes, - int dcodes, - int blcodes /* number of codes for each tree */ -) -{ +local void send_all_trees(deflate_state *s, int lcodes, int dcodes, + int blcodes) { int rank; /* index in bl_order */ Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); @@ -872,13 +855,8 @@ local void send_all_trees( /* =========================================================================== * Send a stored block */ -void ZLIB_INTERNAL _tr_stored_block( - deflate_state *s, - charf *buf, /* input block */ - ulg stored_len, /* length of input block */ - int last /* one if this is the last block for a file */ -) -{ +void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { if (last) s->strm->last_bit = (s->strm->total_out + s->pending) * 8 + s->bi_valid; @@ -904,10 +882,7 @@ void ZLIB_INTERNAL _tr_stored_block( /* =========================================================================== * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) */ -void ZLIB_INTERNAL _tr_flush_bits( - deflate_state *s -) -{ +void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) { bi_flush(s); } @@ -915,10 +890,7 @@ void ZLIB_INTERNAL _tr_flush_bits( * Send one empty static block to give enough lookahead for inflate. * This takes 10 bits, of which 7 may remain in the bit buffer. */ -void ZLIB_INTERNAL _tr_align( - deflate_state *s -) -{ +void ZLIB_INTERNAL _tr_align(deflate_state *s) { send_bits(s, STATIC_TREES<<1, 3); send_code(s, END_BLOCK, static_ltree); #ifdef ZLIB_DEBUG @@ -927,17 +899,99 @@ void ZLIB_INTERNAL _tr_align( bi_flush(s); } +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(deflate_state *s, const ct_data *ltree, + const ct_data *dtree) { + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned sx = 0; /* running index in sym_buf */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->sym_next != 0) do { + dist = s->sym_buf[sx++] & 0xff; + dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; + lc = s->sym_buf[sx++]; + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code + LITERALS + 1, ltree); /* send length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= (unsigned)base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and sym_buf is ok: */ + Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); + + } while (sx < s->sym_next); + + send_code(s, END_BLOCK, ltree); +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "block list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local int detect_data_type(deflate_state *s) { + /* block_mask is the bit mask of block-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long block_mask = 0xf3ffc07fUL; + int n; + + /* Check for non-textual ("block-listed") bytes. */ + for (n = 0; n <= 31; n++, block_mask >>= 1) + if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("allow-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) + if (s->dyn_ltree[n].Freq != 0) + return Z_TEXT; + + /* There are no "block-listed" or "allow-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + /* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static * trees or store, and write out the encoded block. */ -void ZLIB_INTERNAL _tr_flush_block( - deflate_state *s, - charf *buf, /* input block, or NULL if too old */ - ulg stored_len, /* length of input block */ - int last /* one if this is the last block for a file */ -) -{ +void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex = 0; /* index of last bit length code of non zero freq */ @@ -1040,12 +1094,7 @@ void ZLIB_INTERNAL _tr_flush_block( * Save the match info and tally the frequency counts. Return true if * the current block must be flushed. */ -int ZLIB_INTERNAL _tr_tally ( - deflate_state *s, - unsigned dist, /* distance of matched string */ - unsigned lc /* match length - MIN_MATCH or unmatched char (dist==0) */ -) -{ +int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)lc; @@ -1065,152 +1114,3 @@ int ZLIB_INTERNAL _tr_tally ( } return (s->sym_next == s->sym_end); } - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block( - deflate_state *s, - const ct_data *ltree, /* literal tree */ - const ct_data *dtree /* distance tree */ -) -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in sym_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->sym_next != 0) do { - dist = s->sym_buf[sx++] & 0xff; - dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; - lc = s->sym_buf[sx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code + LITERALS + 1, ltree); /* send length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= (unsigned)base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and sym_buf is ok: */ - Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); - - } while (sx < s->sym_next); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "block list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type( - deflate_state *s -) -{ - /* block_mask is the bit mask of block-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long block_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("block-listed") bytes. */ - for (n = 0; n <= 31; n++, block_mask >>= 1) - if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("allow-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "block-listed" or "allow-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse( - unsigned code, /* the value to invert */ - int len /* its bit length */ -) -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush( - deflate_state *s -) -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup( - deflate_state *s -) -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->bits_sent = (s->bits_sent+7) & ~7; -#endif -} diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h index a91fd3d66..b423e9efd 100644 --- a/lib/libvgz/vgz.h +++ b/lib/libvgz/vgz.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.13, October 13th, 2022 + version 1.3, August 18th, 2023 - Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.13" -#define ZLIB_VERNUM 0x12d0 +#define ZLIB_VERSION "1.3" +#define ZLIB_VERNUM 0x1300 #define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 13 +#define ZLIB_VER_MINOR 3 +#define ZLIB_VER_REVISION 0 #define ZLIB_VER_SUBREVISION 0 /* @@ -235,7 +235,7 @@ ZEXTERN int ZEXPORT deflateInit (z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. + allocation functions. total_in, total_out, adler, and msg are initialized. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all @@ -325,8 +325,8 @@ ZEXTERN int ZEXPORT deflate (z_streamp strm, int flush); with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. + avail_out is greater than six when the flush marker begins, in order to avoid + repeated flush markers upon calling deflate() again when avail_out == 0. If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was @@ -388,7 +388,8 @@ ZEXTERN int ZEXPORT inflateInit (z_streamp strm); read or consumed. The allocation of a sliding window will be deferred to the first call of inflate (if the decompression does not complete on the first call). If zalloc and zfree are set to Z_NULL, inflateInit updates - them to use default allocation functions. + them to use default allocation functions. total_in, total_out, adler, and + msg are initialized. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the @@ -701,7 +702,7 @@ ZEXTERN int ZEXPORT deflateReset (z_streamp strm); This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream will leave the compression level and any other attributes that may have been - set unchanged. + set unchanged. total_in, total_out, adler, and msg are initialized. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). @@ -734,7 +735,7 @@ ZEXTERN int ZEXPORT deflateParams (z_streamp strm, Then no more input data should be provided before the deflateParams() call. If this is done, the old level and strategy will be applied to the data compressed before deflateParams(), and the new level and strategy will be - applied to the the data compressed after deflateParams(). + applied to the data compressed after deflateParams(). deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if @@ -826,8 +827,9 @@ ZEXTERN int ZEXPORT deflateSetHeader (z_streamp strm, gzip file" and give up. If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). + the time set to zero, and os set to the current operating system, with no + extra, name, or comment fields. The gzip header is returned to the default + state by deflateReset(). deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. @@ -966,6 +968,7 @@ ZEXTERN int ZEXPORT inflateReset (z_streamp strm); This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The stream will keep attributes that may have been set by inflateInit2. + total_in, total_out, adler, and msg are initialized. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). @@ -1470,7 +1473,7 @@ ZEXTERN z_size_t ZEXPORT gzfwrite (voidpc buf, z_size_t size, is returned, and the error state is set to Z_STREAM_ERROR. */ -ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +ZEXTERN int ZEXPORTVA gzprintf (gzFile file, const char *format, ...); /* Convert, format, compress, and write the arguments (...) to file under control of the string format, as in fprintf. gzprintf returns the number of @@ -1927,9 +1930,9 @@ ZEXTERN gzFile ZEXPORT gzopen_w (const wchar_t *path, #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) # ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, +ZEXTERN int ZEXPORTVA gzvprintf (gzFile file, const char *format, - va_list va)); + va_list va); # endif #endif diff --git a/lib/libvgz/zconf.h b/lib/libvgz/zconf.h index bf977d3e7..fb76ffe31 100644 --- a/lib/libvgz/zconf.h +++ b/lib/libvgz/zconf.h @@ -241,7 +241,11 @@ #endif #ifdef Z_SOLO - typedef unsigned long z_size_t; +# ifdef _WIN64 + typedef unsigned long long z_size_t; +# else + typedef unsigned long z_size_t; +# endif #else # define z_longlong long long # if defined(NO_SIZE_T) @@ -520,7 +524,7 @@ typedef uLong FAR uLongf; #if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# if defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t diff --git a/lib/libvgz/zutil.c b/lib/libvgz/zutil.c index 4082f65ac..911b04ef6 100644 --- a/lib/libvgz/zutil.c +++ b/lib/libvgz/zutil.c @@ -25,13 +25,11 @@ z_const char * const z_errmsg[10] = { #ifdef NOVGZ -const char * ZEXPORT zlibVersion() -{ +const char * ZEXPORT zlibVersion(void) { return ZLIB_VERSION; } -uLong ZEXPORT zlibCompileFlags() -{ +uLong ZEXPORT zlibCompileFlags(void) { uLong flags; flags = 0; @@ -122,9 +120,7 @@ uLong ZEXPORT zlibCompileFlags() # endif int ZLIB_INTERNAL z_verbose = verbose; -void ZLIB_INTERNAL z_error (m) - char *m; -{ +void ZLIB_INTERNAL z_error (char *m) { fprintf(stderr, "%s\n", m); exit(1); } @@ -133,9 +129,7 @@ void ZLIB_INTERNAL z_error (m) /* exported to allow conversion of error code to string for compress() and * uncompress() */ -const char * ZEXPORT zError(err) - int err; -{ +const char * ZEXPORT zError(int err) { return ERR_MSG(err); } @@ -149,22 +143,14 @@ const char * ZEXPORT zError(err) #ifndef HAVE_MEMCPY -void ZLIB_INTERNAL zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ +void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) { if (len == 0) return; do { *dest++ = *source++; /* ??? to be unrolled */ } while (--len != 0); } -int ZLIB_INTERNAL zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ +int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) { uInt j; for (j = 0; j < len; j++) { @@ -173,10 +159,7 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len) return 0; } -void ZLIB_INTERNAL zmemzero(dest, len) - Bytef* dest; - uInt len; -{ +void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) { if (len == 0) return; do { *dest++ = 0; /* ??? to be unrolled */ @@ -219,8 +202,7 @@ local ptr_table table[MAX_PTR]; * a protected system like OS/2. Use Microsoft C instead. */ -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) -{ +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) { voidpf buf; ulg bsize = (ulg)items*size; @@ -245,8 +227,7 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) return buf; } -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) { int n; (void)opaque; @@ -282,14 +263,12 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) # define _hfree hfree #endif -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) -{ +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) { (void)opaque; return _halloc((long)items, size); } -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) { (void)opaque; _hfree(ptr); } @@ -307,22 +286,13 @@ extern voidp calloc (uInt items, uInt size); extern void free (voidpf ptr); #endif -voidpf ZLIB_INTERNAL zcalloc ( - voidpf opaque, - unsigned items, - unsigned size -) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { (void)opaque; return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : (voidpf)calloc(items, size); } -void ZLIB_INTERNAL zcfree ( - voidpf opaque, - voidpf ptr -) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { (void)opaque; free(ptr); } From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] 380aa8b00 Sync up with github/madler/zlib Message-ID: <20251210154306.A370D10294F@lists.vinyl-cache.org> commit 380aa8b00522673e107d2b607c9c82e40e577536 Author: Poul-Henning Kamp Date: Mon May 13 07:48:03 2024 +0000 Sync up with github/madler/zlib diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index bd9d5f82a..a2b341d98 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -53,7 +53,7 @@ extern const char deflate_copyright[]; const char deflate_copyright[] = - " deflate 1.3 Copyright 1995-2023 Jean-loup Gailly and Mark Adler "; + " deflate 1.3.1.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -370,7 +370,6 @@ local void fill_window(deflate_state *s) { "not enough room for search"); } - #ifdef NOVGZ /* ========================================================================= */ @@ -501,8 +500,8 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, * symbols from which it is being constructed. */ - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4); - s->pending_buf_size = (ulg)s->lit_bufsize * 4; + s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS); + s->pending_buf_size = (ulg)s->lit_bufsize * LIT_BUFS; if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { @@ -511,8 +510,14 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, deflateEnd (strm); return Z_MEM_ERROR; } +#ifdef LIT_MEM + s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1)); + s->l_buf = s->pending_buf + (s->lit_bufsize << 2); + s->sym_end = s->lit_bufsize - 1; +#else s->sym_buf = s->pending_buf + s->lit_bufsize; s->sym_end = (s->lit_bufsize - 1) * 3; +#endif /* We avoid equality with lit_bufsize*3 because of wraparound at 64K * on 16 bit machines and because stored blocks are restricted to * 64K-1 bytes. @@ -737,9 +742,15 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; s = strm->state; +#ifdef LIT_MEM + if (bits < 0 || bits > 16 || + (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3)) + return Z_BUF_ERROR; +#else if (bits < 0 || bits > 16 || s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) return Z_BUF_ERROR; +#endif do { put = Buf_size - s->bi_valid; if (put > bits) @@ -851,13 +862,13 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { storelen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) + (sourceLen >> 11) + 7; - /* if can't get parameters, return larger bound plus a zlib wrapper */ + /* if can't get parameters, return larger bound plus a wrapper */ if (deflateStateCheck(strm)) - return (fixedlen > storelen ? fixedlen : storelen) + 6; + return (fixedlen > storelen ? fixedlen : storelen) + 18; /* compute wrapper length */ s = strm->state; - switch (s->wrap) { + switch (s->wrap < 0 ? -s->wrap : s->wrap) { case 0: /* raw deflate */ wraplen = 0; break; @@ -887,7 +898,7 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { break; #endif default: /* for compiler happiness */ - wraplen = 6; + wraplen = 18; } /* if not default parameters, return one of the conservative bounds */ @@ -1328,7 +1339,7 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS); if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || ds->pending_buf == Z_NULL) { @@ -1339,10 +1350,15 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->sym_buf = ds->pending_buf + ds->lit_bufsize; +#ifdef LIT_MEM + ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1)); + ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2); +#else + ds->sym_buf = ds->pending_buf + ds->lit_bufsize; +#endif ds->l_desc.dyn_tree = ds->dyn_ltree; ds->d_desc.dyn_tree = ds->dyn_dtree; @@ -1354,8 +1370,6 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { #endif /* NOVGZ */ - - #ifndef FASTEST /* =========================================================================== * Set match_start to the longest match starting at the given string and @@ -1577,13 +1591,21 @@ local uInt longest_match(deflate_state *s, IPos cur_match) { */ local void check_match(deflate_state *s, IPos start, IPos match, int length) { /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); + Bytef *back = s->window + (int)match, *here = s->window + start; + IPos len = length; + if (match == (IPos)-1) { + /* match starts one byte before the current window -- just compare the + subsequent length-1 bytes */ + back++; + here++; + len--; + } + if (zmemcmp(back, here, len) != EQUAL) { + fprintf(stderr, " start %u, match %d, length %d\n", + start, (int)match, length); do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); + fprintf(stderr, "(%02x %02x)", *back++, *here++); + } while (--len != 0); z_error("invalid match"); } if (z_verbose > 1) { @@ -1619,10 +1641,8 @@ local void check_match(deflate_state *s, IPos start, IPos match, int length) { /* Maximum stored block length in deflate format (not including header). */ #define MAX_STORED 65535 -#if !defined(MIN) /* Minimum of a and b. */ #define MIN(a, b) ((a) > (b) ? (b) : (a)) -#endif /* =========================================================================== * Copy without compression as much as possible from the input stream, return @@ -1650,7 +1670,8 @@ local block_state deflate_stored(deflate_state *s, int flush) { * possible. If flushing, copy the remaining available input to next_out as * stored blocks, if there is enough space. */ - unsigned len, left, have, last = 0; + int last = 0; + unsigned len, left, have; unsigned used = s->strm->avail_in; do { /* Set len to the maximum size block that we can copy directly with the @@ -1686,10 +1707,10 @@ local block_state deflate_stored(deflate_state *s, int flush) { _tr_stored_block(s, (char *)0, 0L, last); /* Replace the lengths in the dummy stored block with len. */ - s->pending_buf[s->pending - 4] = len; - s->pending_buf[s->pending - 3] = len >> 8; - s->pending_buf[s->pending - 2] = ~len; - s->pending_buf[s->pending - 1] = ~len >> 8; + s->pending_buf[s->pending - 4] = (Bytef)len; + s->pending_buf[s->pending - 3] = (Bytef)(len >> 8); + s->pending_buf[s->pending - 2] = (Bytef)~len; + s->pending_buf[s->pending - 1] = (Bytef)(~len >> 8); /* Write the stored block header bytes. */ flush_pending(s->strm); diff --git a/lib/libvgz/deflate.h b/lib/libvgz/deflate.h index 6d9f6945e..720dca7e4 100644 --- a/lib/libvgz/deflate.h +++ b/lib/libvgz/deflate.h @@ -1,5 +1,5 @@ /* deflate.h -- internal compression state - * Copyright (C) 1995-2018 Jean-loup Gailly + * Copyright (C) 1995-2024 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -23,6 +23,10 @@ # define GZIP #endif +/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at + the cost of a larger memory footprint */ +/* #define LIT_MEM */ + /* =========================================================================== * Internal compression state. */ @@ -217,7 +221,14 @@ typedef struct internal_state { /* Depth of each subtree used as tie breaker for trees of equal frequency */ +#ifdef LIT_MEM +# define LIT_BUFS 5 + ushf *d_buf; /* buffer for distances */ + uchf *l_buf; /* buffer for literals/lengths */ +#else +# define LIT_BUFS 4 uchf *sym_buf; /* buffer for distances and literals/lengths */ +#endif uInt lit_bufsize; /* Size of match buffer for literals/lengths. There are 4 reasons for @@ -239,7 +250,7 @@ typedef struct internal_state { * - I can't count above 4 */ - uInt sym_next; /* running index in sym_buf */ + uInt sym_next; /* running index in symbol buffer */ uInt sym_end; /* symbol table full when sym_next reaches this */ ulg opt_len; /* bit length of current block with optimal trees */ @@ -318,6 +329,25 @@ void ZLIB_INTERNAL _tr_stored_block (deflate_state *s, charf *buf, extern const uch ZLIB_INTERNAL _dist_code[]; #endif +#ifdef LIT_MEM +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->sym_next] = 0; \ + s->l_buf[s->sym_next++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (uch)(length); \ + ush dist = (ush)(distance); \ + s->d_buf[s->sym_next] = dist; \ + s->l_buf[s->sym_next++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +#else # define _tr_tally_lit(s, c, flush) \ { uch cc = (c); \ s->sym_buf[s->sym_next++] = 0; \ @@ -337,6 +367,7 @@ void ZLIB_INTERNAL _tr_stored_block (deflate_state *s, charf *buf, s->dyn_dtree[d_code(dist)].Freq++; \ flush = (s->sym_next == s->sym_end); \ } +#endif #else # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_dist(s, distance, length, flush) \ diff --git a/lib/libvgz/gzguts.h b/lib/libvgz/gzguts.h index cfde69df5..6c238b52d 100644 --- a/lib/libvgz/gzguts.h +++ b/lib/libvgz/gzguts.h @@ -1,5 +1,5 @@ /* gzguts.h -- zlib internal header definitions for gz* operations - * Copyright (C) 2004-2019 Mark Adler + * Copyright (C) 2004-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -17,6 +17,18 @@ # define ZLIB_INTERNAL #endif +#if defined(_WIN32) +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS +# endif +# ifndef _CRT_NONSTDC_NO_DEPRECATE +# define _CRT_NONSTDC_NO_DEPRECATE +# endif +#endif + #include #include "vgz.h" #ifdef STDC @@ -25,8 +37,8 @@ # include #endif -#ifndef _POSIX_SOURCE -# define _POSIX_SOURCE +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L #endif #include @@ -36,19 +48,13 @@ #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) # include +# include #endif -#if defined(_WIN32) +#if defined(_WIN32) && !defined(WIDECHAR) # define WIDECHAR #endif -#ifdef WINAPI_FAMILY -# define open _open -# define read _read -# define write _write -# define close _close -#endif - #ifdef NO_DEFLATE /* for compatibility with old definition */ # define NO_GZCOMPRESS #endif @@ -72,33 +78,28 @@ #endif #ifndef HAVE_VSNPRINTF -# ifdef MSDOS +# if !defined(NO_vsnprintf) && \ + (defined(MSDOS) || defined(__TURBOC__) || defined(__SASC) || \ + defined(VMS) || defined(__OS400) || defined(__MVS__)) /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), but for now we just assume it doesn't. */ # define NO_vsnprintf # endif -# ifdef __TURBOC__ -# define NO_vsnprintf -# endif # ifdef WIN32 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ -# if !defined(vsnprintf) && !defined(NO_vsnprintf) -# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) -# define vsnprintf _vsnprintf +# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) +# ifndef vsnprintf +# define vsnprintf _vsnprintf # endif # endif -# endif -# ifdef __SASC -# define NO_vsnprintf -# endif -# ifdef VMS -# define NO_vsnprintf -# endif -# ifdef __OS400__ -# define NO_vsnprintf -# endif -# ifdef __MVS__ -# define NO_vsnprintf +# elif !defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L +/* Otherwise if C89/90, assume no C99 snprintf() or vsnprintf() */ +# ifndef NO_snprintf +# define NO_snprintf +# endif +# ifndef NO_vsnprintf +# define NO_vsnprintf +# endif # endif #endif @@ -210,9 +211,5 @@ char ZLIB_INTERNAL *gz_strwinerror (DWORD error); /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t value -- needed when comparing unsigned to z_off64_t, which is signed (possible z_off64_t types off_t, off64_t, and long are all signed) */ -#ifdef INT_MAX -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) -#else unsigned ZLIB_INTERNAL gz_intmax (void); # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) -#endif diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index deae8231f..07a5f36c9 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -1399,7 +1399,7 @@ int ZEXPORT inflateSync(z_streamp strm) { /* if first time, start search in bit buffer */ if (state->mode != SYNC) { state->mode = SYNC; - state->hold <<= state->bits & 7; + state->hold >>= state->bits & 7; state->bits -= state->bits & 7; len = 0; while (state->bits >= 8) { diff --git a/lib/libvgz/inflate.h b/lib/libvgz/inflate.h index f127b6b1f..f758e0dcc 100644 --- a/lib/libvgz/inflate.h +++ b/lib/libvgz/inflate.h @@ -100,7 +100,7 @@ struct inflate_state { unsigned char FAR *window; /* allocated sliding window, if needed */ /* bit accumulator */ unsigned long hold; /* input bit accumulator */ - unsigned bits; /* number of bits in "in" */ + unsigned bits; /* number of bits in hold */ /* for string and stored block copying */ unsigned length; /* literal or length of data to copy */ unsigned offset; /* distance back to copy string from */ diff --git a/lib/libvgz/inftrees.c b/lib/libvgz/inftrees.c index a6a8a9edc..fc15f4676 100644 --- a/lib/libvgz/inftrees.c +++ b/lib/libvgz/inftrees.c @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2023 Mark Adler + * Copyright (C) 1995-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -10,7 +10,7 @@ extern const char inflate_copyright[]; const char inflate_copyright[] = - " inflate 1.3 Copyright 1995-2023 Mark Adler "; + " inflate 1.3.1.1 Copyright 1995-2024 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -58,7 +58,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 198, 203}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 200}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff --git a/lib/libvgz/inftrees.h b/lib/libvgz/inftrees.h index c96d3b62a..4664eaee9 100644 --- a/lib/libvgz/inftrees.h +++ b/lib/libvgz/inftrees.h @@ -41,8 +41,8 @@ typedef struct { examples/enough.c found in the zlib distribution. The arguments to that program are the number of symbols, the initial root table size, and the maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument of the + returns 852, and "enough 30 6 15" for distance codes returns 592. The + initial root table size (9 or 6) is found in the fifth argument of the inflate_table() calls in inflate.c and infback.c. If the root table size is changed, then these maximum sizes would be need to be recalculated and updated. */ diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c index 51fdadba8..bbaa24870 100644 --- a/lib/libvgz/trees.c +++ b/lib/libvgz/trees.c @@ -1,5 +1,5 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2021 Jean-loup Gailly + * Copyright (C) 1995-2024 Jean-loup Gailly * detect_data_type() function provided freely by Cosmin Truta, 2006 * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -724,7 +724,7 @@ local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { if (++count < max_count && curlen == nextlen) { continue; } else if (count < min_count) { - s->bl_tree[curlen].Freq += count; + s->bl_tree[curlen].Freq += (ush)count; } else if (curlen != 0) { if (curlen != prevlen) s->bl_tree[curlen].Freq++; s->bl_tree[REP_3_6].Freq++; @@ -906,14 +906,19 @@ local void compress_block(deflate_state *s, const ct_data *ltree, const ct_data *dtree) { unsigned dist; /* distance of matched string */ int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in sym_buf */ + unsigned sx = 0; /* running index in symbol buffers */ unsigned code; /* the code to send */ int extra; /* number of extra bits to send */ if (s->sym_next != 0) do { +#ifdef LIT_MEM + dist = s->d_buf[sx]; + lc = s->l_buf[sx++]; +#else dist = s->sym_buf[sx++] & 0xff; dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; lc = s->sym_buf[sx++]; +#endif if (dist == 0) { send_code(s, lc, ltree); /* send a literal byte */ Tracecv(isgraph(lc), (stderr," '%c' ", lc)); @@ -938,8 +943,12 @@ local void compress_block(deflate_state *s, const ct_data *ltree, } } /* literal or match pair ? */ - /* Check that the overlay between pending_buf and sym_buf is ok: */ + /* Check for no overlay of pending_buf on needed symbols */ +#ifdef LIT_MEM + Assert(s->pending < 2 * (s->lit_bufsize + sx), "pendingBuf overflow"); +#else Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); +#endif } while (sx < s->sym_next); @@ -1095,9 +1104,14 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, * the current block must be flushed. */ int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { +#ifdef LIT_MEM + s->d_buf[s->sym_next] = (ush)dist; + s->l_buf[s->sym_next++] = (uch)lc; +#else s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)lc; +#endif if (dist == 0) { /* lc is the unmatched char */ s->dyn_ltree[lc].Freq++; diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h index b423e9efd..97b140531 100644 --- a/lib/libvgz/vgz.h +++ b/lib/libvgz/vgz.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.3, August 18th, 2023 + version 1.3.1.1, January xxth, 2024 - Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,12 +37,12 @@ extern "C" { #endif -#define ZLIB_VERSION "1.3" -#define ZLIB_VERNUM 0x1300 +#define ZLIB_VERSION "1.3.1.1-motley" +#define ZLIB_VERNUM 0x1311 #define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MINOR 3 -#define ZLIB_VER_REVISION 0 -#define ZLIB_VER_SUBREVISION 0 +#define ZLIB_VER_REVISION 1 +#define ZLIB_VER_SUBREVISION 1 /* The 'zlib' compression library provides in-memory compression and @@ -592,18 +592,21 @@ ZEXTERN int ZEXPORT deflateInit2 (z_streamp strm, The strategy parameter is used to tune the compression algorithm. Use the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match), or Z_RLE to limit match distances to one (run-length - encoding). Filtered data consists mostly of small values with a somewhat - random distribution. In this case, the compression algorithm is tuned to - compress them better. The effect of Z_FILTERED is to force more Huffman - coding and less string matching; it is somewhat intermediate between - Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as - fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The - strategy parameter only affects the compression ratio but not the - correctness of the compressed output even if it is not set appropriately. - Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler - decoder for special applications. + filter (or predictor), Z_RLE to limit match distances to one (run-length + encoding), or Z_HUFFMAN_ONLY to force Huffman encoding only (no string + matching). Filtered data consists mostly of small values with a somewhat + random distribution, as produced by the PNG filters. In this case, the + compression algorithm is tuned to compress them better. The effect of + Z_FILTERED is to force more Huffman coding and less string matching than the + default; it is intermediate between Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. + Z_RLE is almost as fast as Z_HUFFMAN_ONLY, but should give better + compression for PNG image data than Huffman only. The degree of string + matching from most to none is: Z_DEFAULT_STRATEGY, Z_FILTERED, Z_RLE, then + Z_HUFFMAN. The strategy parameter affects the compression ratio but never + the correctness of the compressed output, even if it is not set optimally + for the given data. Z_FIXED uses the default string matching, but prevents + the use of dynamic Huffman codes, allowing for a simpler decoder for special + applications. deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid @@ -941,10 +944,10 @@ ZEXTERN int ZEXPORT inflateSync (z_streamp strm); inflateSync returns Z_OK if a possible full flush point has been found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current current value of - total_in which indicates where valid compressed data was found. In the - error case, the application may repeatedly call inflateSync, providing more - input each time, until success or end of the input data. + In the success case, the application may save the current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. */ ZEXTERN int ZEXPORT inflateCopy (z_streamp dest, @@ -1763,14 +1766,14 @@ ZEXTERN uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2); seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. + len2. len2 must be non-negative. */ /* ZEXTERN uLong ZEXPORT crc32_combine_gen (z_off_t len2); Return the operator corresponding to length len2, to be used with - crc32_combine_op(). + crc32_combine_op(). len2 must be non-negative. */ ZEXTERN uLong ZEXPORT crc32_combine_op (uLong crc1, uLong crc2, uLong op); @@ -1893,9 +1896,9 @@ ZEXTERN int ZEXPORT gzgetc_ (gzFile file); /* backward compatibility */ ZEXTERN z_off_t ZEXPORT gzseek64 (gzFile, z_off_t, int); ZEXTERN z_off_t ZEXPORT gztell64 (gzFile); ZEXTERN z_off_t ZEXPORT gzoffset64 (gzFile); - ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off_t); + ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off64_t); # endif #else ZEXTERN gzFile ZEXPORT gzopen (const char *, const char *); diff --git a/lib/libvgz/zconf.h b/lib/libvgz/zconf.h index fb76ffe31..ea3b6d685 100644 --- a/lib/libvgz/zconf.h +++ b/lib/libvgz/zconf.h @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -300,14 +300,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have @@ -478,12 +470,8 @@ typedef uLong FAR uLongf; #endif #ifndef Z_HAVE_UNISTD_H -# ifdef __WATCOMC__ -# define Z_HAVE_UNISTD_H -# endif -#endif -#ifndef Z_HAVE_UNISTD_H -# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32) +# if defined(__WATCOMC__) || defined(__GO32__) || \ + (defined(_LARGEFILE64_SOURCE) && !defined(_WIN32)) # define Z_HAVE_UNISTD_H # endif #endif @@ -523,12 +511,14 @@ typedef uLong FAR uLongf; #if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t +#elif defined(__MINGW32__) +# define z_off64_t long long +#elif defined(_WIN32) && !defined(__GNUC__) +# define z_off64_t __int64 +#elif defined(__GO32__) +# define z_off64_t offset_t #else -# if defined(_WIN32) && !defined(__GNUC__) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif +# define z_off64_t z_off_t #endif /* MVS linker does not support external names larger than 8 bytes */ diff --git a/lib/libvgz/zutil.h b/lib/libvgz/zutil.h index 1ae739f15..a74201f02 100644 --- a/lib/libvgz/zutil.h +++ b/lib/libvgz/zutil.h @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2022 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -56,7 +56,7 @@ typedef unsigned long ulg; extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] +#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)] #define ERR_RETURN(strm,err) \ return (strm->msg = ERR_MSG(err), (err)) @@ -137,20 +137,11 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # endif #endif -#if defined(MACOS) || defined(TARGET_OS_MAC) +#if defined(MACOS) # define OS_CODE 7 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif #endif -#ifdef __acorn +#if defined(__acorn) || defined(__riscos) # define OS_CODE 13 #endif @@ -170,18 +161,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define OS_CODE 19 #endif -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - #if defined(__BORLANDC__) && !defined(MSDOS) #pragma warn -8004 #pragma warn -8008 @@ -189,11 +168,10 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #endif /* provide prototypes for these when building zlib without LFS */ -#if !defined(_WIN32) && \ - (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off_t); +#ifndef Z_LARGE64 + ZEXTERN uLong ZEXPORT adler32_combine64 (uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine64 (uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64 (z_off64_t); #endif /* common defaults */ From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] a8e83add9 Sync libvgz with github/madler/zlib Message-ID: <20251210154306.C229A102977@lists.vinyl-cache.org> commit a8e83add9cd0fd2f68f6f8038b7ce2de67c36d3c Author: Poul-Henning Kamp Date: Tue Jul 2 11:40:26 2024 +0000 Sync libvgz with github/madler/zlib diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index a2b341d98..05a2d4517 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -501,7 +501,7 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, */ s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS); - s->pending_buf_size = (ulg)s->lit_bufsize * LIT_BUFS; + s->pending_buf_size = (ulg)s->lit_bufsize * 4; // Pretty sure this should be LIT_BUFS /phk if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { @@ -735,6 +735,14 @@ int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { return Z_OK; } +/* ========================================================================= */ +int ZEXPORT deflateUsed(z_streamp strm, int *bits) { + if (deflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits != Z_NULL) + *bits = strm->state->bi_used; + return Z_OK; +} + /* ========================================================================= */ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { deflate_state *s; @@ -1743,7 +1751,7 @@ local block_state deflate_stored(deflate_state *s, int flush) { s->strm->total_out += len; } } while (last == 0); - if (last) + if (last) s->strm->stop_bit = (s->strm->total_out + s->pending) * 8 + s->bi_valid; diff --git a/lib/libvgz/deflate.h b/lib/libvgz/deflate.h index 720dca7e4..4d93b2acf 100644 --- a/lib/libvgz/deflate.h +++ b/lib/libvgz/deflate.h @@ -271,6 +271,9 @@ typedef struct internal_state { /* Number of valid bits in bi_buf. All bits above the last valid bit * are always zero. */ + int bi_used; + /* Last number of used bits when going to a byte boundary. + */ ulg high_water; /* High water mark offset in window for initialized bytes -- bytes above diff --git a/lib/libvgz/inffast.c b/lib/libvgz/inffast.c index 1f49bd5a5..f7b550b8b 100644 --- a/lib/libvgz/inffast.c +++ b/lib/libvgz/inffast.c @@ -155,7 +155,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { dist += (unsigned)hold & ((1U << op) - 1); #ifdef INFLATE_STRICT if (dist > dmax) { - strm->msg = "invalid distance too far back"; + strm->msg = (z_const char *)"invalid distance too far back"; state->mode = BAD; break; } @@ -169,7 +169,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { if (op > whave) { if (state->sane) { strm->msg = - "invalid distance too far back"; + (z_const char *)"invalid distance too far back"; state->mode = BAD; break; } @@ -265,7 +265,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { goto dodist; } else { - strm->msg = "invalid distance code"; + strm->msg = (z_const char *)"invalid distance code"; state->mode = BAD; break; } @@ -280,7 +280,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { break; } else { - strm->msg = "invalid literal/length code"; + strm->msg = (z_const char *)"invalid literal/length code"; state->mode = BAD; break; } diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index 07a5f36c9..5c7494f47 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -647,12 +647,12 @@ int ZEXPORT inflate(z_streamp strm, int flush) { if ( #endif ((BITS(8) << 8) + (hold >> 8)) % 31) { - strm->msg = "incorrect header check"; + strm->msg = (z_const char *)"incorrect header check"; state->mode = BAD; break; } if (BITS(4) != Z_DEFLATED) { - strm->msg = "unknown compression method"; + strm->msg = (z_const char *)"unknown compression method"; state->mode = BAD; break; } @@ -661,7 +661,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { if (state->wbits == 0) state->wbits = len; if (len > 15 || len > state->wbits) { - strm->msg = "invalid window size"; + strm->msg = (z_const char *)"invalid window size"; state->mode = BAD; break; } @@ -677,12 +677,12 @@ int ZEXPORT inflate(z_streamp strm, int flush) { NEEDBITS(16); state->flags = (int)(hold); if ((state->flags & 0xff) != Z_DEFLATED) { - strm->msg = "unknown compression method"; + strm->msg = (z_const char *)"unknown compression method"; state->mode = BAD; break; } if (state->flags & 0xe000) { - strm->msg = "unknown header flags set"; + strm->msg = (z_const char *)"unknown header flags set"; state->mode = BAD; break; } @@ -798,7 +798,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { if (state->flags & 0x0200) { NEEDBITS(16); if ((state->wrap & 4) && hold != (state->check & 0xffff)) { - strm->msg = "header crc mismatch"; + strm->msg = (z_const char *)"header crc mismatch"; state->mode = BAD; break; } @@ -865,7 +865,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { state->mode = TABLE; break; case 3: - strm->msg = "invalid block type"; + strm->msg = (z_const char *)"invalid block type"; state->mode = BAD; } DROPBITS(2); @@ -874,7 +874,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { BYTEBITS(); /* go to byte boundary */ NEEDBITS(32); if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = "invalid stored block lengths"; + strm->msg = (z_const char *)"invalid stored block lengths"; state->mode = BAD; break; } @@ -915,7 +915,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { DROPBITS(4); #ifndef PKZIP_BUG_WORKAROUND if (state->nlen > 286 || state->ndist > 30) { - strm->msg = "too many length or distance symbols"; + strm->msg = (z_const char *)"too many length or distance symbols"; state->mode = BAD; break; } @@ -938,7 +938,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { ret = inflate_table(CODES, state->lens, 19, &(state->next), &(state->lenbits), state->work); if (ret) { - strm->msg = "invalid code lengths set"; + strm->msg = (z_const char *)"invalid code lengths set"; state->mode = BAD; break; } @@ -962,7 +962,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { NEEDBITS(here.bits + 2); DROPBITS(here.bits); if (state->have == 0) { - strm->msg = "invalid bit length repeat"; + strm->msg = (z_const char *)"invalid bit length repeat"; state->mode = BAD; break; } @@ -985,7 +985,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { DROPBITS(7); } if (state->have + copy > state->nlen + state->ndist) { - strm->msg = "invalid bit length repeat"; + strm->msg = (z_const char *)"invalid bit length repeat"; state->mode = BAD; break; } @@ -999,7 +999,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { /* check for end-of-block code (better have one) */ if (state->lens[256] == 0) { - strm->msg = "invalid code -- missing end-of-block"; + strm->msg = (z_const char *)"invalid code -- missing end-of-block"; state->mode = BAD; break; } @@ -1013,7 +1013,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), &(state->lenbits), state->work); if (ret) { - strm->msg = "invalid literal/lengths set"; + strm->msg = (z_const char *)"invalid literal/lengths set"; state->mode = BAD; break; } @@ -1022,7 +1022,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, &(state->next), &(state->distbits), state->work); if (ret) { - strm->msg = "invalid distances set"; + strm->msg = (z_const char *)"invalid distances set"; state->mode = BAD; break; } @@ -1076,7 +1076,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { break; } if (here.op & 64) { - strm->msg = "invalid literal/length code"; + strm->msg = (z_const char *)"invalid literal/length code"; state->mode = BAD; break; } @@ -1114,7 +1114,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { DROPBITS(here.bits); state->back += here.bits; if (here.op & 64) { - strm->msg = "invalid distance code"; + strm->msg = (z_const char *)"invalid distance code"; state->mode = BAD; break; } @@ -1131,7 +1131,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { } #ifdef INFLATE_STRICT if (state->offset > state->dmax) { - strm->msg = "invalid distance too far back"; + strm->msg = (z_const char *)"invalid distance too far back"; state->mode = BAD; break; } @@ -1146,7 +1146,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { copy = state->offset - copy; if (copy > state->whave) { if (state->sane) { - strm->msg = "invalid distance too far back"; + strm->msg = (z_const char *)"invalid distance too far back"; state->mode = BAD; break; } @@ -1205,7 +1205,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { state->flags ? hold : #endif ZSWAP32(hold)) != state->check) { - strm->msg = "incorrect data check"; + strm->msg = (z_const char *)"incorrect data check"; state->mode = BAD; break; } @@ -1219,7 +1219,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { if (state->wrap && state->flags) { NEEDBITS(32); if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) { - strm->msg = "incorrect length check"; + strm->msg = (z_const char *)"incorrect length check"; state->mode = BAD; break; } diff --git a/lib/libvgz/trees.c b/lib/libvgz/trees.c index bbaa24870..76e45b36d 100644 --- a/lib/libvgz/trees.c +++ b/lib/libvgz/trees.c @@ -184,6 +184,7 @@ local void bi_windup(deflate_state *s) { } else if (s->bi_valid > 0) { put_byte(s, (Byte)s->bi_buf); } + s->bi_used = ((s->bi_valid - 1) & 7) + 1; s->bi_buf = 0; s->bi_valid = 0; #ifdef ZLIB_DEBUG @@ -466,6 +467,7 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) { s->bi_buf = 0; s->bi_valid = 0; + s->bi_used = 0; #ifdef ZLIB_DEBUG s->compressed_len = 0L; s->bits_sent = 0L; diff --git a/lib/libvgz/vgz.h b/lib/libvgz/vgz.h index 97b140531..e339f0e10 100644 --- a/lib/libvgz/vgz.h +++ b/lib/libvgz/vgz.h @@ -602,11 +602,11 @@ ZEXTERN int ZEXPORT deflateInit2 (z_streamp strm, Z_RLE is almost as fast as Z_HUFFMAN_ONLY, but should give better compression for PNG image data than Huffman only. The degree of string matching from most to none is: Z_DEFAULT_STRATEGY, Z_FILTERED, Z_RLE, then - Z_HUFFMAN. The strategy parameter affects the compression ratio but never - the correctness of the compressed output, even if it is not set optimally - for the given data. Z_FIXED uses the default string matching, but prevents - the use of dynamic Huffman codes, allowing for a simpler decoder for special - applications. + Z_HUFFMAN_ONLY. The strategy parameter affects the compression ratio but + never the correctness of the compressed output, even if it is not set + optimally for the given data. Z_FIXED uses the default string matching, but + prevents the use of dynamic Huffman codes, allowing for a simpler decoder + for special applications. deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid @@ -796,6 +796,18 @@ ZEXTERN int ZEXPORT deflatePending (z_streamp strm, stream state was inconsistent. */ +ZEXTERN int ZEXPORT deflateUsed(z_streamp strm, + int *bits); +/* + deflateUsed() returns in *bits the most recent number of deflate bits used + in the last byte when flushing to a byte boundary. The result is in 1..8, or + 0 if there has not yet been a flush. This helps determine the location of + the last bit of a deflate stream. + + deflateUsed returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + ZEXTERN int ZEXPORT deflatePrime (z_streamp strm, int bits, int value); diff --git a/lib/libvgz/zconf.h b/lib/libvgz/zconf.h index ea3b6d685..4a52aed7c 100644 --- a/lib/libvgz/zconf.h +++ b/lib/libvgz/zconf.h @@ -59,6 +59,7 @@ # define deflateSetDictionary z_deflateSetDictionary # define deflateSetHeader z_deflateSetHeader # define deflateTune z_deflateTune +# define deflateUsed z_deflateUsed # define deflate_copyright z_deflate_copyright # define get_crc_table z_get_crc_table # ifndef Z_SOLO @@ -506,7 +507,7 @@ typedef uLong FAR uLongf; #endif #ifndef z_off_t -# define z_off_t long +# define z_off_t long long #endif #if !defined(_WIN32) && defined(Z_LARGE64) diff --git a/tools/cmp_libz.sh b/tools/cmp_libz.sh deleted file mode 100644 index b9c5c6b0d..000000000 --- a/tools/cmp_libz.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -# This script compares libvgz to zlib in FreeBSD source tree - -LZ=/usr/src/contrib/zlib - -if [ ! -d lib/libvgz ] ; then - echo "Run this from to of tree" 1>&2 - exit 2 -fi - -for i in lib/libvgz/*.[ch] -do - b=`basename $i` - if [ "$b" == "vgz.h" ] ; then - b="zlib.h" - fi - if [ -f ${LZ}/$b ] ; then - echo "==== $b" - sed ' - s/vgz.h/zlib.h/ - /strm->msg =/s/"/(char *)"/ - ' $i | - diff -u ${LZ}/$b - - else - echo "#### $b #### NOT FOUND ####" - fi -done diff --git a/tools/cmp_zlib.sh b/tools/cmp_zlib.sh new file mode 100644 index 000000000..a3acbd2b8 --- /dev/null +++ b/tools/cmp_zlib.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Compare libvgz with github/madler/zlib + +LZ=/tmp/zlib + +if [ "${LZ}" = "/tmp/zlib" -a ! -d ${LZ} ] ; then + rm -rf ${LZ} + git clone https://github.com/madler/zlib ${LZ} +else + (cd ${LZ} && git pull) +fi + +for i in varnish-cache/lib/libvgz/*.[ch] +do + b=`basename $i` + if [ "$b" == "vgz.h" ] ; then + b="zlib.h" + fi + if [ -f ${LZ}/$b ] ; then + echo "#################################### $b" + sed ' + s/vgz.h/zlib.h/ + # /strm->msg =/s/"/(char *)"/ + ' $i | + diff -wu - ${LZ}/$b + else + echo "#### $b #### NOT FOUND ####" + fi +done From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] 45cba4eb5 spelling: formerly Message-ID: <20251210154306.DC232102982@lists.vinyl-cache.org> commit 45cba4eb5408fa58250ed2f7eed886d251da7815 Author: Josh Soref <2119212+jsoref at users.noreply.github.com> Date: Wed Aug 7 08:30:56 2024 -0400 spelling: formerly Signed-off-by: Josh Soref <2119212+jsoref at users.noreply.github.com> diff --git a/lib/libvgz/README b/lib/libvgz/README index 9b2fb3977..77dad0005 100644 --- a/lib/libvgz/README +++ b/lib/libvgz/README @@ -66,7 +66,7 @@ Notes for some targets: - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works when compiled with cc. -- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is +- On Digital Unix 4.0D (formerly OSF/1) on AlphaServer, the cc option -std1 is necessary to get gzprintf working correctly. This is done by configure. - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with From walid.boudebouda at gmail.com Wed Dec 10 15:43:06 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:06 +0000 (UTC) Subject: [6.0] 405cc6767 spelling: irix Message-ID: <20251210154306.F3F1510298F@lists.vinyl-cache.org> commit 405cc6767e0b1f2bc28f9c8e19affbfc20036b6f Author: Josh Soref <2119212+jsoref at users.noreply.github.com> Date: Wed Aug 7 08:30:58 2024 -0400 spelling: irix Signed-off-by: Josh Soref <2119212+jsoref at users.noreply.github.com> diff --git a/lib/libvgz/README b/lib/libvgz/README index 77dad0005..c07b6b6b3 100644 --- a/lib/libvgz/README +++ b/lib/libvgz/README @@ -59,7 +59,7 @@ Notes for some targets: - For Windows DLL versions, please see win32/DLL_FAQ.txt -- For 64-bit Irix, deflate.c must be compiled without any optimization. With +- For 64-bit IRIX, deflate.c must be compiled without any optimization. With -O, one libpng test fails. The test works in 32 bit mode (with the -n32 compiler flag). The compiler bug has been reported to SGI. From walid.boudebouda at gmail.com Wed Dec 10 15:43:07 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:07 +0000 (UTC) Subject: [6.0] 9b6130f76 Cherry-pick (f7d01aae6ec611) from madler/zlib: Message-ID: <20251210154307.2269A102999@lists.vinyl-cache.org> commit 9b6130f76caf21d1fd5dc41f6090104bdf89841a Author: Poul-Henning Kamp Date: Mon Sep 23 13:33:05 2024 +0000 Cherry-pick (f7d01aae6ec611) from madler/zlib: Avoid out-of-bounds pointer arithmetic in inflateCopy(). Though it does not matter for code correctness, clang's UBSan injects code that complains about computing a pointer from an array where the result is out-of-bounds for that array, even though the pointer is never dereferenced. Go figure. This commit avoids that possibility when computing distcode in inflateCopy(). diff --git a/lib/libvgz/inflate.c b/lib/libvgz/inflate.c index 5c7494f47..b9545e918 100644 --- a/lib/libvgz/inflate.c +++ b/lib/libvgz/inflate.c @@ -933,7 +933,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) { while (state->have < 19) state->lens[order[state->have++]] = 0; state->next = state->codes; - state->lencode = (const code FAR *)(state->next); + state->lencode = state->distcode = (const code FAR *)(state->next); state->lenbits = 7; ret = inflate_table(CODES, state->lens, 19, &(state->next), &(state->lenbits), state->work); From walid.boudebouda at gmail.com Wed Dec 10 15:43:07 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:07 +0000 (UTC) Subject: [6.0] 8dc759333 Cherry pick 545f194963 from madler/zlib Message-ID: <20251210154307.390E81029A1@lists.vinyl-cache.org> commit 8dc759333dea79877d52ad67e0ed7c54d6885610 Author: Poul-Henning Kamp Date: Mon Sep 23 13:41:41 2024 +0000 Cherry pick 545f194963 from madler/zlib Add old gcc ULONG_LONG_MAX macro to find a 64-bit type in zutil.h. diff --git a/lib/libvgz/zutil.h b/lib/libvgz/zutil.h index a74201f02..c095a04d1 100644 --- a/lib/libvgz/zutil.h +++ b/lib/libvgz/zutil.h @@ -48,6 +48,8 @@ typedef unsigned long ulg; # define Z_U8 unsigned long # elif (ULLONG_MAX == 0xffffffffffffffff) # define Z_U8 unsigned long long +# elif (ULONG_LONG_MAX == 0xffffffffffffffff) +# define Z_U8 unsigned long long # elif (UINT_MAX == 0xffffffffffffffff) # define Z_U8 unsigned # endif From walid.boudebouda at gmail.com Wed Dec 10 15:43:07 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:07 +0000 (UTC) Subject: [6.0] 1c7e07f91 Track libz changes Message-ID: <20251210154307.536691029A7@lists.vinyl-cache.org> commit 1c7e07f910ba045c95a0f9f69edff4fd899561dd Author: Poul-Henning Kamp Date: Mon Nov 24 14:00:13 2025 +0000 Track libz changes diff --git a/lib/libvgz/deflate.c b/lib/libvgz/deflate.c index 05a2d4517..a3c8935b8 100644 --- a/lib/libvgz/deflate.c +++ b/lib/libvgz/deflate.c @@ -1792,8 +1792,10 @@ local block_state deflate_stored(deflate_state *s, int flush) { s->high_water = s->strstart; /* If the last block was written to next_out, then done. */ - if (last) + if (last) { + s->bi_used = 8; return finish_done; + } /* If flushing and all input has been consumed, then done. */ if (flush != Z_NO_FLUSH && flush != Z_FINISH && @@ -1845,6 +1847,8 @@ local block_state deflate_stored(deflate_state *s, int flush) { } /* We've done all we can with the available input and output. */ + if (last) + s->bi_used = 8; return last ? finish_started : need_more; } diff --git a/lib/libvgz/zconf.h b/lib/libvgz/zconf.h index 4a52aed7c..2c7991abf 100644 --- a/lib/libvgz/zconf.h +++ b/lib/libvgz/zconf.h @@ -235,10 +235,12 @@ # endif #endif -#if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const -#else -# define z_const +#ifndef z_const +# ifdef ZLIB_CONST +# define z_const const +# else +# define z_const +# endif #endif #ifdef Z_SOLO @@ -434,11 +436,11 @@ typedef uLong FAR uLongf; typedef unsigned long z_crc_t; #endif -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +#if HAVE_UNISTD_H-0 /* may be set to #if 1 by ./configure */ # define Z_HAVE_UNISTD_H #endif -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +#if HAVE_STDARG_H-0 /* may be set to #if 1 by ./configure */ # define Z_HAVE_STDARG_H #endif diff --git a/lib/libvgz/zutil.h b/lib/libvgz/zutil.h index c095a04d1..0dfa02357 100644 --- a/lib/libvgz/zutil.h +++ b/lib/libvgz/zutil.h @@ -65,7 +65,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* To be used only when the state is known to be valid */ /* common constants */ - +#if MAX_WBITS < 9 || MAX_WBITS > 15 +# error MAX_WBITS must be in 9..15 +#endif #ifndef DEF_WBITS # define DEF_WBITS MAX_WBITS #endif From walid.boudebouda at gmail.com Wed Dec 10 15:43:07 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 10 Dec 2025 15:43:07 +0000 (UTC) Subject: [6.0] 375afc077 vmod_blob: Account for NUL to simplify alphabet initialization Message-ID: <20251210154307.6D0751029B6@lists.vinyl-cache.org> commit 375afc0779623e578b9e37768638dc2c3c954a6f Author: Nils Goroll Date: Wed Mar 19 16:31:23 2025 +0100 vmod_blob: Account for NUL to simplify alphabet initialization Alphabets for base64 and hex are 64 and 16 bytes long, respectively, but initializing them with a string needs one additional byte for the final NUL. Fixes #4300 Conflicts: lib/libvmod_blob/vmod_blob.h diff --git a/lib/libvmod_blob/base64.h b/lib/libvmod_blob/base64.h index 962ae22cd..7e30e1e78 100644 --- a/lib/libvmod_blob/base64.h +++ b/lib/libvmod_blob/base64.h @@ -32,7 +32,7 @@ #define PAD ((int8_t) 126) static const struct b64_alphabet { - const char b64[64]; + const char b64[65]; const int8_t i64[256]; const int padding; } b64_alphabet[] = { diff --git a/lib/libvmod_blob/hex.c b/lib/libvmod_blob/hex.c index adcf94b24..c14c5f4fd 100644 --- a/lib/libvmod_blob/hex.c +++ b/lib/libvmod_blob/hex.c @@ -38,7 +38,7 @@ #include "vmod_blob.h" -const char hex_alphabet[][16] = { +const char hex_alphabet[][17] = { "0123456789abcdef", "0123456789ABCDEF" }; diff --git a/lib/libvmod_blob/hex.h b/lib/libvmod_blob/hex.h index 53cfc8915..1f529a63c 100644 --- a/lib/libvmod_blob/hex.h +++ b/lib/libvmod_blob/hex.h @@ -32,6 +32,6 @@ /* These are defined in hex.c */ -extern const char hex_alphabet[][16]; +extern const char hex_alphabet[][17]; extern const uint8_t nibble[]; From nils.goroll at uplex.de Thu Dec 11 16:26:04 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 11 Dec 2025 16:26:04 +0000 (UTC) Subject: [master] 63806461a cache_main: Change order of shutdown slightly Message-ID: <20251211162604.C002111146D@lists.vinyl-cache.org> commit 63806461a205a11da12deb21051f654e35acee9e Author: Nils Goroll Date: Thu Dec 11 17:18:58 2025 +0100 cache_main: Change order of shutdown slightly Until VCL_Shutdown() is complete, objects will get dereferenced, but if EXP is already shut down, they will starve in the exp inbox. So, conversely, EXP should stay alive until after VCL_Shutdown(). diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index 3c90d3a44..95ed67244 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -559,9 +559,9 @@ child_main(int sigmagic, size_t altstksz) VCA_Shutdown(); BAN_Shutdown(); - EXP_Shutdown(); STV_warn(); VCL_Shutdown(); + EXP_Shutdown(); STV_close(); printf("Child dies\n"); From walid.boudebouda at gmail.com Wed Dec 17 14:42:04 2025 From: walid.boudebouda at gmail.com (Walid Boudebouda) Date: Wed, 17 Dec 2025 14:42:04 +0000 (UTC) Subject: [master] 6e4e674b9 cli_cmds.h: Doc fixup Message-ID: <20251217144204.D7F9711EBAA@lists.vinyl-cache.org> commit 6e4e674b9bef2e58eab3d755856244e2c9541068 Author: Walid Boudebouda Date: Wed Dec 17 15:39:01 2025 +0100 cli_cmds.h: Doc fixup debug.reqpool.fail is a cli command, not a param. diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h index 3c398575b..dd2235935 100644 --- a/include/tbl/cli_cmds.h +++ b/include/tbl/cli_cmds.h @@ -361,7 +361,7 @@ CLI_CMD(DEBUG_REQPOOLFAIL, "debug.reqpool.fail", "Schedule req-pool failures.", "The argument is read L-R and 'f' means fail:\n\n" - "\tparam.set debug.reqpoolfail F__F_F\n\n" + "\tdebug.reqpool.fail F__F_F\n\n" "In the example above the first, fourth and sixth attempted\n" "allocations will fail.", 1, 1 From nils.goroll at uplex.de Fri Dec 19 14:03:02 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 19 Dec 2025 14:03:02 +0000 (UTC) Subject: [master] 39a9dae89 Add std.rfc_ttl() Message-ID: <20251219140302.EBE5A106166@lists.vinyl-cache.org> commit 39a9dae89d6b1069dcb2dd731f130f2276e2f085 Author: Nils Goroll Date: Wed Dec 10 17:48:22 2025 +0100 Add std.rfc_ttl() From the added documentation: Re-calculate the object timers (``beresp.ttl``, ``beresp.grace`` and ``beresp.keep``) based on the current state of ``beresp`` as if it had been processed by core code before ``vcl_backend_response`` was called. This does not change ``beresp.uncacheable``. This is useful to get the default ttl calculations after modifications of relevant properties like ``beresp.status``, ``beresp.http.Date``, ``beresp.http.Age`` or ``beresp.http.Cache-Control``. Documentation details polished by SashankBhamidi, thank you. diff --git a/vmod/tests/std_b00015.vtc b/vmod/tests/std_b00015.vtc new file mode 100644 index 000000000..d2004e101 --- /dev/null +++ b/vmod/tests/std_b00015.vtc @@ -0,0 +1,87 @@ +varnishtest "std.rfc_ttl()" + +server s1 { + rxreq + txresp -status 202 -hdr "Cache-Control: public, s-maxage=4711" + + rxreq + expect req.url == "/200" + txresp -status 200 \ + -hdr "Cache-Control: public, s-maxage=0, stale-while-revalidate=99" \ + -hdr {Etag: "foo"} \ + -bodylen 64 + + rxreq + expect req.url == "/200" + expect req.http.If-None-Match == {"foo"} + txresp -status 304 -hdr "Cache-Control: s-maxage=11, stale-while-revalidate=77" +} -start + +varnish v1 -vcl+backend { + import std; + + sub vcl_backend_refresh { + set beresp.http.Cache-Control = "s-maxage=10, stale-while-revalidate=42"; + std.rfc_ttl(); + } + + sub vcl_backend_response { + if (beresp.status == 202) { + set beresp.status = 200; + std.rfc_ttl(); + set beresp.status = 202; + } + # avoid zero ttl which is uncacheable + set beresp.ttl += 0.001s; + } +} -start + +logexpect l1 -v v1 -g vxid -q "vxid == 1002" { + fail add * Error + fail add * VCL_Error + fail add * End + expect * 1002 TTL {^RFC -1 } + expect 1 = BerespStatus {^200} + expect 1 = TTL {^RFC 4711 } + fail clear +} -start + +logexpect l2 -v v1 -g vxid -q "vxid == 1004" { + fail add * Error + fail add * VCL_Error + fail add * End + expect * 1004 BereqURL {^/200} + expect * = BerespStatus {^200} + expect * = TTL {^RFC 0 99 } + fail clear +} -start + +logexpect l3 -v v1 -g vxid -q "vxid == 1006" { + fail add * Error + fail add * VCL_Error + fail add * End + expect * 1006 BereqURL {^/200} + expect * = BerespStatus {^304} + expect * = TTL {^RFC 11 77 } + expect * = TTL {^RFC 10 42 } + fail clear +} -start + + +client c1 { + txreq + rxresp + expect resp.status == 202 + + txreq -url "/200" + rxresp + expect resp.status == 200 + + txreq -url "/200" + rxresp + expect resp.status == 200 +} -run + +logexpect l1 -wait +logexpect l2 -wait +logexpect l3 -wait diff --git a/vmod/vmod_std.c b/vmod/vmod_std.c index b2c9566b7..fc0f4d62c 100644 --- a/vmod/vmod_std.c +++ b/vmod/vmod_std.c @@ -385,3 +385,23 @@ vmod_timed_call(VRT_CTX, VCL_SUB sub) VRT_call(ctx, sub); return (VTIM_mono() - b); } + +VCL_VOID v_matchproto_(td_std_rfc_ttl) +vmod_rfc_ttl(VRT_CTX) +{ + struct busyobj *bo; + struct objcore *oc; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + // $Restrict guarantees + bo = ctx->bo; + CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); + oc = bo->fetch_objcore; + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); + + RFC2616_Ttl(bo, ctx->now, + &oc->t_origin, + &oc->ttl, + &oc->grace, + &oc->keep); +} diff --git a/vmod/vmod_std.vcc b/vmod/vmod_std.vcc index 87978f615..25593c9bb 100644 --- a/vmod/vmod_std.vcc +++ b/vmod/vmod_std.vcc @@ -696,6 +696,19 @@ $Function DURATION timed_call(SUB) Call the given SUB and return a high precision measurement of the execution time. +$Function VOID rfc_ttl() + +$Restrict vcl_backend_response vcl_backend_refresh + +Re-calculate the object timers (``beresp.ttl``, ``beresp.grace`` and +``beresp.keep``) based on the current state of ``beresp`` as if it had been +processed by core code before ``vcl_backend_response`` was called. This does not +change ``beresp.uncacheable``. + +This is useful to get the default ttl calculations after modifications of +relevant properties like ``beresp.status``, ``beresp.http.Date``, +``beresp.http.Age`` or ``beresp.http.Cache-Control``. + SEE ALSO ======== From phk at FreeBSD.org Mon Dec 22 14:48:05 2025 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 22 Dec 2025 14:48:05 +0000 (UTC) Subject: [master] 913069f45 Tell the C-compiler that VCL_INT is long-long-int. Message-ID: <20251222144805.458F911003C@lists.vinyl-cache.org> commit 913069f45f43df92bbdad97891f7a5d92cd23afb Author: Poul-Henning Kamp Date: Mon Dec 22 14:46:04 2025 +0000 Tell the C-compiler that VCL_INT is long-long-int. Spottedby: @nigoroll Fixes: #4431 diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 4f1d41c95..090a7b5e5 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -747,7 +747,7 @@ vcc_number(struct vcc *tl, struct expr **e, vcc_type_t fmt, const char *sign) } else if (fmt == REAL || t->tok == FNUM) { e1 = vcc_mk_expr(REAL, "%s%.3f", sign, t->num); } else { - e1 = vcc_mk_expr(INT, "%s%.0f", sign, t->num); + e1 = vcc_mk_expr(INT, "%s%.0fLL", sign, t->num); } } e1->constant = EXPR_CONST; From nils.goroll at uplex.de Mon Dec 22 18:31:05 2025 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 22 Dec 2025 18:31:05 +0000 (UTC) Subject: [master] 76bc57e3d vmod_std: test negative number in string argument to std.duration() Message-ID: <20251222183105.08AA311C4CA@lists.vinyl-cache.org> commit 76bc57e3d5b3b54878e263833856f11bcad193ed Author: Nils Goroll Date: Mon Dec 22 19:29:57 2025 +0100 vmod_std: test negative number in string argument to std.duration() diff --git a/vmod/tests/std_b00002.vtc b/vmod/tests/std_b00002.vtc index de5f7c4d7..e19ca6bef 100644 --- a/vmod/tests/std_b00002.vtc +++ b/vmod/tests/std_b00002.vtc @@ -20,6 +20,9 @@ varnish v1 -vcl+backend { } else if (req.http.duration-nf) { set resp.http.duration = std.duration(req.http.duration) + 1000000s; + } else if (req.http.duration-lit) { + set resp.http.duration = + std.duration(req.http.duration-lit, 0.42s); } else { set resp.http.duration = std.duration(req.http.duration, 1s) + 1000000s; @@ -133,6 +136,10 @@ client c1 { expect resp.http.duration == 1036000.000 expect resp.http.bytes == 131941395845 + txreq -hdr "duration-lit: -12.345s" + rxresp + expect resp.http.duration == -12.345 + txreq -hdr "d-real: -100" rxresp expect resp.http.duration == 999900.000