Redo the encoding of error codes

This commit is contained in:
Nigel Tao committed 2018-06-10 21:22:41 +10:00
1 parent 2ac2424e77
commit 43bb14e886
29 files changed
+1069 -1021

No files matched your search

+106 -91
View File
@@ -58,7 +58,14 @@ typedef struct {
// --------
// A status code is either zero (OK), positive (a recoverable suspension or
// pause in processing) or negative (a non-recoverable error).
// pause in processing) or negative (a non-recoverable error). Its bits:
// - bit 31 (the sign bit) indicates unrecoverable-ness: an error.
// - bits 30 .. 24 are a package-namespaced numeric code
// - bits 23 .. 21 are reserved.
// - bits 20 .. 0 are the packageid (a namespace) as a base38 value.
//
// Do not manipulate these bits directly; they are private implementation
// details. Use methods such as wuffs_base__status__is_error instead.
typedef int32_t wuffs_base__status;
#define WUFFS_BASE__STATUS_OK 0 // 0x00000000
@@ -1271,38 +1278,30 @@ extern "C" {
// ---------------- Status Codes
// Status codes are int32_t values. Its bits:
// - bit 31 (the sign bit) indicates unrecoverable-ness: an error.
// - bits 30 .. 10 are the packageid: a namespace.
// - bits 9 .. 8 are reserved.
// - bits 7 .. 0 are a package-namespaced numeric code.
//
// Do not manipulate these bits directly; they are private implementation
// details. Use methods such as wuffs_lzw__status__is_error instead.
typedef int32_t wuffs_lzw__status;
#define wuffs_lzw__packageid 1316776 // 0x001417A8
#define WUFFS_LZW__STATUS_OK 0 // 0x00000000
#define WUFFS_LZW__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
#define WUFFS_LZW__ERROR_BAD_SIZEOF_RECEIVER -2147483646 // 0x80000002
#define WUFFS_LZW__ERROR_BAD_RECEIVER -2147483645 // 0x80000003
#define WUFFS_LZW__ERROR_BAD_ARGUMENT -2147483644 // 0x80000004
#define WUFFS_LZW__STATUS_OK 0 // 0x00000000
#define WUFFS_LZW__ERROR_BAD_WUFFS_VERSION -16777216 // 0xFF000000
#define WUFFS_LZW__ERROR_BAD_SIZEOF_RECEIVER -33554432 // 0xFE000000
#define WUFFS_LZW__ERROR_BAD_RECEIVER -50331648 // 0xFD000000
#define WUFFS_LZW__ERROR_BAD_ARGUMENT -67108864 // 0xFC000000
#define WUFFS_LZW__ERROR_CHECK_WUFFS_VERSION_NOT_CALLED \
-2147483643 // 0x80000005
-268435456 // 0xF0000000
#define WUFFS_LZW__ERROR_CHECK_WUFFS_VERSION_CALLED_TWICE \
-2147483642 // 0x80000006
#define WUFFS_LZW__ERROR_INVALID_I_O_OPERATION -2147483641 // 0x80000007
#define WUFFS_LZW__ERROR_CLOSED_FOR_WRITES -2147483640 // 0x80000008
#define WUFFS_LZW__ERROR_UNEXPECTED_EOF -2147483639 // 0x80000009
#define WUFFS_LZW__SUSPENSION_SHORT_READ 10 // 0x0000000A
#define WUFFS_LZW__SUSPENSION_SHORT_WRITE 11 // 0x0000000B
#define WUFFS_LZW__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483636 // 0x8000000C
#define WUFFS_LZW__ERROR_INVALID_CALL_SEQUENCE -2147483635 // 0x8000000D
#define WUFFS_LZW__SUSPENSION_END_OF_DATA 14 // 0x0000000E
-285212672 // 0xEF000000
#define WUFFS_LZW__ERROR_INVALID_I_O_OPERATION -805306368 // 0xD0000000
#define WUFFS_LZW__ERROR_CLOSED_FOR_WRITES -1073741824 // 0xC0000000
#define WUFFS_LZW__ERROR_UNEXPECTED_EOF -822083584 // 0xCF000000
#define WUFFS_LZW__SUSPENSION_SHORT_READ 33554432 // 0x02000000
#define WUFFS_LZW__SUSPENSION_SHORT_WRITE 50331648 // 0x03000000
#define WUFFS_LZW__ERROR_CANNOT_RETURN_A_SUSPENSION -536870912 // 0xE0000000
#define WUFFS_LZW__ERROR_INVALID_CALL_SEQUENCE -301989888 // 0xEE000000
#define WUFFS_LZW__SUSPENSION_END_OF_DATA 16777216 // 0x01000000
#define WUFFS_LZW__ERROR_BAD_CODE -799105024 // 0xD05EA000
#define WUFFS_LZW__ERROR_CYCLICAL_PREFIX_CHAIN -799105023 // 0xD05EA001
#define WUFFS_LZW__ERROR_BAD_CODE -15460440 // 0xFF1417A8
#define WUFFS_LZW__ERROR_CYCLICAL_PREFIX_CHAIN -32237656 // 0xFE1417A8
bool wuffs_lzw__status__is_error(wuffs_lzw__status s);
@@ -1381,45 +1380,37 @@ extern "C" {
// ---------------- Status Codes
// Status codes are int32_t values. Its bits:
// - bit 31 (the sign bit) indicates unrecoverable-ness: an error.
// - bits 30 .. 10 are the packageid: a namespace.
// - bits 9 .. 8 are reserved.
// - bits 7 .. 0 are a package-namespaced numeric code.
//
// Do not manipulate these bits directly; they are private implementation
// details. Use methods such as wuffs_gif__status__is_error instead.
typedef int32_t wuffs_gif__status;
#define wuffs_gif__packageid 1017222 // 0x000F8586
#define WUFFS_GIF__STATUS_OK 0 // 0x00000000
#define WUFFS_GIF__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
#define WUFFS_GIF__ERROR_BAD_SIZEOF_RECEIVER -2147483646 // 0x80000002
#define WUFFS_GIF__ERROR_BAD_RECEIVER -2147483645 // 0x80000003
#define WUFFS_GIF__ERROR_BAD_ARGUMENT -2147483644 // 0x80000004
#define WUFFS_GIF__STATUS_OK 0 // 0x00000000
#define WUFFS_GIF__ERROR_BAD_WUFFS_VERSION -16777216 // 0xFF000000
#define WUFFS_GIF__ERROR_BAD_SIZEOF_RECEIVER -33554432 // 0xFE000000
#define WUFFS_GIF__ERROR_BAD_RECEIVER -50331648 // 0xFD000000
#define WUFFS_GIF__ERROR_BAD_ARGUMENT -67108864 // 0xFC000000
#define WUFFS_GIF__ERROR_CHECK_WUFFS_VERSION_NOT_CALLED \
-2147483643 // 0x80000005
-268435456 // 0xF0000000
#define WUFFS_GIF__ERROR_CHECK_WUFFS_VERSION_CALLED_TWICE \
-2147483642 // 0x80000006
#define WUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483641 // 0x80000007
#define WUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483640 // 0x80000008
#define WUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483639 // 0x80000009
#define WUFFS_GIF__SUSPENSION_SHORT_READ 10 // 0x0000000A
#define WUFFS_GIF__SUSPENSION_SHORT_WRITE 11 // 0x0000000B
#define WUFFS_GIF__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483636 // 0x8000000C
#define WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE -2147483635 // 0x8000000D
#define WUFFS_GIF__SUSPENSION_END_OF_DATA 14 // 0x0000000E
-285212672 // 0xEF000000
#define WUFFS_GIF__ERROR_INVALID_I_O_OPERATION -805306368 // 0xD0000000
#define WUFFS_GIF__ERROR_CLOSED_FOR_WRITES -1073741824 // 0xC0000000
#define WUFFS_GIF__ERROR_UNEXPECTED_EOF -822083584 // 0xCF000000
#define WUFFS_GIF__SUSPENSION_SHORT_READ 33554432 // 0x02000000
#define WUFFS_GIF__SUSPENSION_SHORT_WRITE 50331648 // 0x03000000
#define WUFFS_GIF__ERROR_CANNOT_RETURN_A_SUSPENSION -536870912 // 0xE0000000
#define WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE -301989888 // 0xEE000000
#define WUFFS_GIF__SUSPENSION_END_OF_DATA 16777216 // 0x01000000
#define WUFFS_GIF__ERROR_BAD_BLOCK -1105848320 // 0xBE161800
#define WUFFS_GIF__ERROR_BAD_EXTENSION_LABEL -1105848319 // 0xBE161801
#define WUFFS_GIF__ERROR_BAD_GRAPHIC_CONTROL -1105848318 // 0xBE161802
#define WUFFS_GIF__ERROR_BAD_HEADER -1105848317 // 0xBE161803
#define WUFFS_GIF__ERROR_BAD_LITERAL_WIDTH -1105848316 // 0xBE161804
#define WUFFS_GIF__ERROR_NOT_ENOUGH_PIXEL_DATA -1105848315 // 0xBE161805
#define WUFFS_GIF__ERROR_TOO_MUCH_PIXEL_DATA -1105848314 // 0xBE161806
#define WUFFS_GIF__ERROR_BAD_BLOCK -15759994 // 0xFF0F8586
#define WUFFS_GIF__ERROR_BAD_EXTENSION_LABEL -32537210 // 0xFE0F8586
#define WUFFS_GIF__ERROR_BAD_GRAPHIC_CONTROL -49314426 // 0xFD0F8586
#define WUFFS_GIF__ERROR_BAD_HEADER -66091642 // 0xFC0F8586
#define WUFFS_GIF__ERROR_BAD_LITERAL_WIDTH -82868858 // 0xFB0F8586
#define WUFFS_GIF__ERROR_NOT_ENOUGH_PIXEL_DATA -99646074 // 0xFA0F8586
#define WUFFS_GIF__ERROR_TOO_MUCH_PIXEL_DATA -116423290 // 0xF90F8586
#define WUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_RI_WI \
-1105848313 // 0xBE161807
-1072724602 // 0xC00F8586
bool wuffs_gif__status__is_error(wuffs_gif__status s);
@@ -2119,25 +2110,6 @@ static inline wuffs_base__empty_struct wuffs_base__io_writer__set_mark(
o->private_impl.bounds[0] = mark;
return ((wuffs_base__empty_struct){});
}
static const char* wuffs_base__status__strings[15] = {
"ok",
"bad wuffs version",
"bad sizeof receiver",
"bad receiver",
"bad argument",
"check_wuffs_version not called",
"check_wuffs_version called twice",
"invalid I/O operation",
"closed for writes",
"unexpected EOF",
"short read",
"short write",
"cannot return a suspension",
"invalid call sequence",
"end of data",
};
#endif // WUFFS_BASE_PRIVATE_H
// ---------------- Status Codes Implementations
@@ -2146,30 +2118,73 @@ bool wuffs_gif__status__is_error(wuffs_gif__status s) {
return s < 0;
}
const char* wuffs_gif__status__strings[8] = {
"gif: bad block", "gif: bad extension label",
"gif: bad graphic control", "gif: bad header",
"gif: bad literal width", "gif: not enough pixel data",
"gif: too much pixel data", "gif: internal error: inconsistent ri/wi",
static const char wuffs_gif__status__string_data[] = {
0x00, 0x67, 0x69, 0x66, 0x3A, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x6E,
0x61, 0x6C, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x3A, 0x20, 0x69, 0x6E,
0x63, 0x6F, 0x6E, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6E, 0x74, 0x20, 0x72,
0x69, 0x2F, 0x77, 0x69, 0x00, 0x67, 0x69, 0x66, 0x3A, 0x20, 0x74, 0x6F,
0x6F, 0x20, 0x6D, 0x75, 0x63, 0x68, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6C,
0x20, 0x64, 0x61, 0x74, 0x61, 0x00, 0x67, 0x69, 0x66, 0x3A, 0x20, 0x6E,
0x6F, 0x74, 0x20, 0x65, 0x6E, 0x6F, 0x75, 0x67, 0x68, 0x20, 0x70, 0x69,
0x78, 0x65, 0x6C, 0x20, 0x64, 0x61, 0x74, 0x61, 0x00, 0x67, 0x69, 0x66,
0x3A, 0x20, 0x62, 0x61, 0x64, 0x20, 0x6C, 0x69, 0x74, 0x65, 0x72, 0x61,
0x6C, 0x20, 0x77, 0x69, 0x64, 0x74, 0x68, 0x00, 0x67, 0x69, 0x66, 0x3A,
0x20, 0x62, 0x61, 0x64, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x00,
0x67, 0x69, 0x66, 0x3A, 0x20, 0x62, 0x61, 0x64, 0x20, 0x67, 0x72, 0x61,
0x70, 0x68, 0x69, 0x63, 0x20, 0x63, 0x6F, 0x6E, 0x74, 0x72, 0x6F, 0x6C,
0x00, 0x67, 0x69, 0x66, 0x3A, 0x20, 0x62, 0x61, 0x64, 0x20, 0x65, 0x78,
0x74, 0x65, 0x6E, 0x73, 0x69, 0x6F, 0x6E, 0x20, 0x6C, 0x61, 0x62, 0x65,
0x6C, 0x00, 0x67, 0x69, 0x66, 0x3A, 0x20, 0x62, 0x61, 0x64, 0x20, 0x62,
0x6C, 0x6F, 0x63, 0x6B, 0x00,
};
static const uint16_t wuffs_gif__status__string_offsets[] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0029, 0x0042, 0x005D,
0x0074, 0x0084, 0x009D, 0x00B6,
};
const char* wuffs_gif__status__string(wuffs_gif__status s) {
const char** a = NULL;
uint32_t n = 0;
switch ((s >> 10) & 0x1FFFFF) {
uint16_t o;
switch (s & 0x1FFFFF) {
case 0:
a = wuffs_base__status__strings;
n = 15;
break;
return wuffs_base__status__string(s);
case wuffs_gif__packageid:
a = wuffs_gif__status__strings;
n = 8;
o = wuffs_gif__status__string_offsets[(uint8_t)(s >> 24)];
if (o) {
return wuffs_gif__status__string_data + o;
}
break;
case wuffs_lzw__packageid:
return wuffs_lzw__status__string(s);
}
uint32_t i = s & 0xFF;
return i < n ? a[i] : "unknown status";
return "unknown status";
}
// ---------------- Private Consts