Tweak the status code int32_t representation.

This commit is contained in:
Nigel Tao committed 2017-07-06 12:27:55 +10:00
1 parent 17b518376f
commit f7f57eaa21
5 files changed
+149 -95

No files matched your search

+29 -20
View File
@@ -78,27 +78,36 @@ extern "C" {
// ---------------- Status Codes
// Status codes are non-positive integers.
// Status codes are int32_t values:
// - the sign bit indicates a non-recoverable status code: an error
// - bits 10-30 hold the packageid: a namespace
// - bits 8-9 are reserved
// - bits 0-7 are a package-namespaced numeric code
//
// The least significant bit indicates a non-recoverable status code: an error.
typedef enum {
puffs_gif_status_ok = 0,
puffs_gif_error_bad_version = -2 + 1,
puffs_gif_error_bad_receiver = -4 + 1,
puffs_gif_error_bad_argument = -6 + 1,
puffs_gif_error_constructor_not_called = -8 + 1,
puffs_gif_error_unexpected_eof = -10 + 1,
puffs_gif_status_short_read = -12,
puffs_gif_status_short_write = -14,
puffs_gif_error_closed_for_writes = -16 + 1,
puffs_gif_error_bad_gif_block = -256 + 1,
puffs_gif_error_bad_gif_extension_label = -258 + 1,
puffs_gif_error_bad_gif_header = -260 + 1,
puffs_gif_error_bad_lzw_literal_width = -262 + 1,
puffs_gif_error_todo_unsupported_local_color_table = -264 + 1,
puffs_gif_error_lzw_code_is_out_of_range = -266 + 1,
puffs_gif_error_lzw_prefix_chain_is_cyclical = -268 + 1,
} puffs_gif_status;
// Do not manipulate these bits directly. Use the API functions such as
// puffs_gif_status_is_error instead.
typedef int32_t puffs_gif_status;
#define puffs_gif_packageid 1017222 // 0x000f8586
#define puffs_gif_status_ok 0 // 0x00000000
#define puffs_gif_error_bad_version -2147483647 // 0x80000001
#define puffs_gif_error_bad_receiver -2147483646 // 0x80000002
#define puffs_gif_error_bad_argument -2147483645 // 0x80000003
#define puffs_gif_error_constructor_not_called -2147483644 // 0x80000004
#define puffs_gif_error_unexpected_eof -2147483643 // 0x80000005
#define puffs_gif_status_short_read 6 // 0x00000006
#define puffs_gif_status_short_write 7 // 0x00000007
#define puffs_gif_error_closed_for_writes -2147483640 // 0x80000008
#define puffs_gif_error_bad_gif_block -1105848320 // 0xbe161800
#define puffs_gif_error_bad_gif_extension_label -1105848319 // 0xbe161801
#define puffs_gif_error_bad_gif_header -1105848318 // 0xbe161802
#define puffs_gif_error_bad_lzw_literal_width -1105848317 // 0xbe161803
#define puffs_gif_error_todo_unsupported_local_color_table \
-1105848316 // 0xbe161804
#define puffs_gif_error_lzw_code_is_out_of_range -1105848315 // 0xbe161805
#define puffs_gif_error_lzw_prefix_chain_is_cyclical -1105848314 // 0xbe161806
bool puffs_gif_status_is_error(puffs_gif_status s);