diff --git a/cmd/wuffs-c/internal/cgen/base-header.h b/cmd/wuffs-c/internal/cgen/base-header.h index 0f400fc7..da665be3 100644 --- a/cmd/wuffs-c/internal/cgen/base-header.h +++ b/cmd/wuffs-c/internal/cgen/base-header.h @@ -28,16 +28,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in diff --git a/cmd/wuffs-c/internal/cgen/cgen.go b/cmd/wuffs-c/internal/cgen/cgen.go index 6e37cc94..4af7d435 100644 --- a/cmd/wuffs-c/internal/cgen/cgen.go +++ b/cmd/wuffs-c/internal/cgen/cgen.go @@ -665,7 +665,7 @@ func (g *gen) writeInitializerSignature(b *buffer, n *a.Struct, public bool) err b.printf("//\n") b.printf("// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.\n") } - b.printf("void %s%s__check_wuffs_version(%s%s *self, size_t sizeof_star_self, uint32_t wuffs_version)", + b.printf("void %s%s__check_wuffs_version(%s%s *self, size_t sizeof_star_self, uint64_t wuffs_version)", g.pkgPrefix, structName, g.pkgPrefix, structName) return nil } @@ -695,7 +695,8 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error { b.printf("self->private_impl.status = %sERROR_BAD_SIZEOF_RECEIVER;\n", g.PKGPREFIX) b.printf("return;\n") b.printf("}\n") - b.printf("if (wuffs_version != WUFFS_VERSION) {\n") + b.printf("if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || " + + "(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {\n") b.printf("self->private_impl.status = %sERROR_BAD_WUFFS_VERSION;\n", g.PKGPREFIX) b.printf("return;\n") b.printf("}\n") diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index b8f5feea..4c920a28 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -17,8 +17,9 @@ package cgen const baseHeader = "" + - "#ifndef WUFFS_BASE_HEADER_H\n#define WUFFS_BASE_HEADER_H\n\n// Copyright 2017 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#include \n#include \n#include \n\n// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n\n// WUFFS_VERSION is the major.minor version number " + - "as a uint32_t. The major\n// number is the high 16 bits. The minor number is the low 16 bits.\n//\n// The intention is to bump the version number at least on every API / ABI\n// backwards incompatible change.\n//\n// For now, the API and ABI are simply unstable and can change at any time.\n//\n// TODO: don't hard code this in base-header.h.\n#define WUFFS_VERSION ((uint32_t)0x00001)\n\n// wuffs_base__empty_struct is used when a Wuffs function returns an empty\n// struct. In C, if a function f returns void, you can't say \"x = f()\", but in\n// Wuffs, if a function g returns empty, you can say \"y = g()\".\ntypedef struct {\n} wuffs_base__empty_struct;\n\n" + + "#ifndef WUFFS_BASE_HEADER_H\n#define WUFFS_BASE_HEADER_H\n\n// Copyright 2017 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#include \n#include \n#include \n\n// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n\n// WUFFS_VERSION is the major.minor.patch version, " + + "as per https://semver.org/,\n// as a uint64_t. The major number is the high 32 bits. The minor number is the\n// middle 16 bits. The patch number is the low 16 bits. The version extension\n// (such as \"\", \"beta\" or \"rc.1\") is part of the string representation (such as\n// \"1.2.3-beta\") but not the uint64_t representation.\n//\n// All three of major, minor and patch being zero means that this is a\n// work-in-progress version, not a release version, and has no backwards or\n// forwards compatibility guarantees.\n//\n// !! Some code generation programs can override WUFFS_VERSION.\n#define WUFFS_VERSION ((uint64_t)0)\n#define WUFFS_VERSION_MAJOR ((uint64_t)0)\n#define WUFFS_VERSION_MINOR ((uint64_t)0)\n#define WUFFS_VERSION_PATCH ((uint64_t)0)\n#define WUFFS_VERSION_EXTENSION \"\"\n#define WUFFS_VERSION_STRING \"0.0.0\"\n\n// wuffs_base__empty_struct is used when a Wuffs function returns an empty\n// struct. In C, if a function f returns void, you can't say \"x = f()\", but in\n// Wuffs, if a function g returns empty, you can say \"y = g(" + + ")\".\ntypedef struct {\n} wuffs_base__empty_struct;\n\n" + "" + "// ---------------- Numeric Types\n\n// Flicks are a unit of time. One flick (frame-tick) is 1 / 705_600_000 of a\n// second. See https://github.com/OculusVR/Flicks\ntypedef int64_t wuffs_base__flicks;\n\n#define WUFFS_BASE__FLICKS_PER_SECOND ((uint64_t)705600000)\n#define WUFFS_BASE__FLICKS_PER_MILLISECOND ((uint64_t)705600)\n\n" + "" + diff --git a/gen/c/std/adler32.c b/gen/c/std/adler32.c index 1ee786c1..0e49207a 100644 --- a/gen/c/std/adler32.c +++ b/gen/c/std/adler32.c @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1275,7 +1282,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1902,7 +1909,7 @@ const char* wuffs_adler32__status__string(wuffs_adler32__status s) { void wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version) { + uint64_t wuffs_version) { if (!self) { return; } @@ -1910,7 +1917,8 @@ void wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self, self->private_impl.status = WUFFS_ADLER32__ERROR_BAD_SIZEOF_RECEIVER; return; } - if (wuffs_version != WUFFS_VERSION) { + if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || + (((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) { self->private_impl.status = WUFFS_ADLER32__ERROR_BAD_WUFFS_VERSION; return; } diff --git a/gen/c/std/crc32.c b/gen/c/std/crc32.c index 982b756b..a1827547 100644 --- a/gen/c/std/crc32.c +++ b/gen/c/std/crc32.c @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1274,7 +1281,7 @@ typedef struct { void wuffs_crc32__ieee_hasher__check_wuffs_version( wuffs_crc32__ieee_hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -2265,7 +2272,7 @@ static const uint32_t wuffs_crc32__ieee_table[8][256] = { void wuffs_crc32__ieee_hasher__check_wuffs_version( wuffs_crc32__ieee_hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version) { + uint64_t wuffs_version) { if (!self) { return; } @@ -2273,7 +2280,8 @@ void wuffs_crc32__ieee_hasher__check_wuffs_version( self->private_impl.status = WUFFS_CRC32__ERROR_BAD_SIZEOF_RECEIVER; return; } - if (wuffs_version != WUFFS_VERSION) { + if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || + (((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) { self->private_impl.status = WUFFS_CRC32__ERROR_BAD_WUFFS_VERSION; return; } diff --git a/gen/c/std/deflate.c b/gen/c/std/deflate.c index 3a80bee9..e84ad4ae 100644 --- a/gen/c/std/deflate.c +++ b/gen/c/std/deflate.c @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1363,7 +1370,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -2085,7 +2092,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow( void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version) { + uint64_t wuffs_version) { if (!self) { return; } @@ -2093,7 +2100,8 @@ void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self, self->private_impl.status = WUFFS_DEFLATE__ERROR_BAD_SIZEOF_RECEIVER; return; } - if (wuffs_version != WUFFS_VERSION) { + if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || + (((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) { self->private_impl.status = WUFFS_DEFLATE__ERROR_BAD_WUFFS_VERSION; return; } diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 96bf7eec..91172acb 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1303,7 +1310,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1493,7 +1500,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -2191,7 +2198,7 @@ static wuffs_gif__status wuffs_gif__decoder__copy_to_image_buffer( void wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version) { + uint64_t wuffs_version) { if (!self) { return; } @@ -2199,7 +2206,8 @@ void wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self, self->private_impl.status = WUFFS_GIF__ERROR_BAD_SIZEOF_RECEIVER; return; } - if (wuffs_version != WUFFS_VERSION) { + if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || + (((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) { self->private_impl.status = WUFFS_GIF__ERROR_BAD_WUFFS_VERSION; return; } diff --git a/gen/c/std/gzip.c b/gen/c/std/gzip.c index e9f1cae8..13826152 100644 --- a/gen/c/std/gzip.c +++ b/gen/c/std/gzip.c @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1283,7 +1290,7 @@ typedef struct { void wuffs_crc32__ieee_hasher__check_wuffs_version( wuffs_crc32__ieee_hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1467,7 +1474,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1573,7 +1580,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -2213,7 +2220,7 @@ const char* wuffs_gzip__status__string(wuffs_gzip__status s) { void wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version) { + uint64_t wuffs_version) { if (!self) { return; } @@ -2221,7 +2228,8 @@ void wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self, self->private_impl.status = WUFFS_GZIP__ERROR_BAD_SIZEOF_RECEIVER; return; } - if (wuffs_version != WUFFS_VERSION) { + if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || + (((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) { self->private_impl.status = WUFFS_GZIP__ERROR_BAD_WUFFS_VERSION; return; } diff --git a/gen/c/std/lzw.c b/gen/c/std/lzw.c index bb03afc7..66687912 100644 --- a/gen/c/std/lzw.c +++ b/gen/c/std/lzw.c @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1294,7 +1301,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1928,7 +1935,7 @@ const char* wuffs_lzw__status__string(wuffs_lzw__status s) { void wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version) { + uint64_t wuffs_version) { if (!self) { return; } @@ -1936,7 +1943,8 @@ void wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self, self->private_impl.status = WUFFS_LZW__ERROR_BAD_SIZEOF_RECEIVER; return; } - if (wuffs_version != WUFFS_VERSION) { + if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || + (((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) { self->private_impl.status = WUFFS_LZW__ERROR_BAD_WUFFS_VERSION; return; } diff --git a/gen/c/std/zlib.c b/gen/c/std/zlib.c index 86342c05..a4ea5a42 100644 --- a/gen/c/std/zlib.c +++ b/gen/c/std/zlib.c @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1284,7 +1291,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1468,7 +1475,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1572,7 +1579,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -2213,7 +2220,7 @@ const char* wuffs_zlib__status__string(wuffs_zlib__status s) { void wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version) { + uint64_t wuffs_version) { if (!self) { return; } @@ -2221,7 +2228,8 @@ void wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self, self->private_impl.status = WUFFS_ZLIB__ERROR_BAD_SIZEOF_RECEIVER; return; } - if (wuffs_version != WUFFS_VERSION) { + if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || + (((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) { self->private_impl.status = WUFFS_ZLIB__ERROR_BAD_WUFFS_VERSION; return; } diff --git a/gen/h/std/adler32.h b/gen/h/std/adler32.h index 46ae0e23..9445e9b1 100644 --- a/gen/h/std/adler32.h +++ b/gen/h/std/adler32.h @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1275,7 +1282,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes diff --git a/gen/h/std/crc32.h b/gen/h/std/crc32.h index 9743039b..2656225b 100644 --- a/gen/h/std/crc32.h +++ b/gen/h/std/crc32.h @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1274,7 +1281,7 @@ typedef struct { void wuffs_crc32__ieee_hasher__check_wuffs_version( wuffs_crc32__ieee_hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes diff --git a/gen/h/std/deflate.h b/gen/h/std/deflate.h index a6c55a0f..b4dfd40f 100644 --- a/gen/h/std/deflate.h +++ b/gen/h/std/deflate.h @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1363,7 +1370,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index 05064e48..a60d0681 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1303,7 +1310,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1493,7 +1500,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes diff --git a/gen/h/std/gzip.h b/gen/h/std/gzip.h index 68c1ff5c..07a84dbe 100644 --- a/gen/h/std/gzip.h +++ b/gen/h/std/gzip.h @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1283,7 +1290,7 @@ typedef struct { void wuffs_crc32__ieee_hasher__check_wuffs_version( wuffs_crc32__ieee_hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1467,7 +1474,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1573,7 +1580,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes diff --git a/gen/h/std/lzw.h b/gen/h/std/lzw.h index 8d192940..8918e776 100644 --- a/gen/h/std/lzw.h +++ b/gen/h/std/lzw.h @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1294,7 +1301,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes diff --git a/gen/h/std/zlib.h b/gen/h/std/zlib.h index 22a51752..e6889ab0 100644 --- a/gen/h/std/zlib.h +++ b/gen/h/std/zlib.h @@ -31,16 +31,23 @@ #error "Wuffs requires a word size of either 32 or 64 bits" #endif -// WUFFS_VERSION is the major.minor version number as a uint32_t. The major -// number is the high 16 bits. The minor number is the low 16 bits. +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. // -// The intention is to bump the version number at least on every API / ABI -// backwards incompatible change. +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. // -// For now, the API and ABI are simply unstable and can change at any time. -// -// TODO: don't hard code this in base-header.h. -#define WUFFS_VERSION ((uint32_t)0x00001) +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" // wuffs_base__empty_struct is used when a Wuffs function returns an empty // struct. In C, if a function f returns void, you can't say "x = f()", but in @@ -1284,7 +1291,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1468,7 +1475,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes @@ -1572,7 +1579,7 @@ typedef struct { // Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version. void wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self, size_t sizeof_star_self, - uint32_t wuffs_version); + uint64_t wuffs_version); // ---------------- Public Function Prototypes diff --git a/test/c/std/gif.c b/test/c/std/gif.c index a7d59c44..ed2f06b1 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -79,7 +79,7 @@ void test_basic_bad_wuffs_version() { CHECK_FOCUS(__func__); wuffs_gif__decoder dec = ((wuffs_gif__decoder){}); wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, - WUFFS_VERSION ^ 0x12345678); + WUFFS_VERSION ^ 0x123456789ABC); if (dec.private_impl.status != WUFFS_GIF__ERROR_BAD_WUFFS_VERSION) { FAIL("decode_config: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", dec.private_impl.status,