Add a status.msg field

This commit is contained in:
Nigel Tao committed 2018-08-11 13:39:17 +10:00
1 parent 2a32a86a6c
commit ff85296c1c
3 files changed
+6 -2

No files matched your search

@@ -110,6 +110,7 @@ typedef struct {
// details. Use methods such as wuffs_base__status__is_error instead.
typedef struct {
int32_t code;
const char* msg;
} wuffs_base__status;
// !! INSERT wuffs_base__status names.
@@ -120,6 +121,7 @@ static inline wuffs_base__status //
WUFFS_BASE__MAKE_STATUS(int32_t code) {
return ((wuffs_base__status){
.code = code,
.msg = NULL,
});
}
+2 -2
View File
@@ -22,8 +22,8 @@ const baseBasePublicH = "" +
"nt.com/nothings/stb/master/docs/stb_howto.txt\n#ifdef WUFFS_CONFIG__STATIC_FUNCTIONS\n#define WUFFS_BASE__MAYBE_STATIC static\n#else\n#define WUFFS_BASE__MAYBE_STATIC\n#endif\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\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 // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n " +
"//\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__empty_struct;\n\n// wuffs_base__utility is a placeholder receiver type. It enables what Java\n// calls static methods, as opposed to regular methods.\ntypedef struct {\n // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n //\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__utility;\n\n" +
"" +
"// --------\n\n// A status code is either zero (OK), positive (a recoverable suspension or\n// pause in processing) or negative (a non-recoverable error). Its bits:\n// - bit 31 (the sign bit) indicates unrecoverable-ness: an error.\n// - bits 30 .. 24 are a package-namespaced numeric code\n// - bits 23 .. 21 are reserved.\n// - bits 20 .. 0 are the packageid (a namespace) as a base38 value.\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__status__is_error instead.\ntypedef struct {\n int32_t code;\n} wuffs_base__status;\n\n// !! INSERT wuffs_base__status names.\n\n// TODO: turn WUFFS_BASE__MAKE_STATUS into a macro, and add a msg field.\n\nstatic inline wuffs_base__status //\nWUFFS_BASE__MAKE_STATUS(int32_t code) {\n return ((wuffs_base__status){\n .code = code,\n });\n}\n\nstatic inline bool //\nwuffs_base__status__is_error(wuffs_base__status s) {\n return s.code < 0;\n}\n\nstatic inline bool //\nwuffs_base__status__is_ok(wuffs_base__status s" +
") {\n return s.code == 0;\n}\n\nstatic inline bool //\nwuffs_base__status__is_suspension(wuffs_base__status s) {\n return s.code > 0;\n}\n\nconst char* //\nwuffs_base__status__string(int32_t status_code);\n\n" +
"// --------\n\n// A status code is either zero (OK), positive (a recoverable suspension or\n// pause in processing) or negative (a non-recoverable error). Its bits:\n// - bit 31 (the sign bit) indicates unrecoverable-ness: an error.\n// - bits 30 .. 24 are a package-namespaced numeric code\n// - bits 23 .. 21 are reserved.\n// - bits 20 .. 0 are the packageid (a namespace) as a base38 value.\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__status__is_error instead.\ntypedef struct {\n int32_t code;\n const char* msg;\n} wuffs_base__status;\n\n// !! INSERT wuffs_base__status names.\n\n// TODO: turn WUFFS_BASE__MAKE_STATUS into a macro, and add a msg field.\n\nstatic inline wuffs_base__status //\nWUFFS_BASE__MAKE_STATUS(int32_t code) {\n return ((wuffs_base__status){\n .code = code,\n .msg = NULL,\n });\n}\n\nstatic inline bool //\nwuffs_base__status__is_error(wuffs_base__status s) {\n return s.code < 0;\n}\n\nstatic inline bool //\nwuffs_ba" +
"se__status__is_ok(wuffs_base__status s) {\n return s.code == 0;\n}\n\nstatic inline bool //\nwuffs_base__status__is_suspension(wuffs_base__status s) {\n return s.code > 0;\n}\n\nconst char* //\nwuffs_base__status__string(int32_t status_code);\n\n" +
"" +
"// --------\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" +
"" +
+2
View File
@@ -134,6 +134,7 @@ typedef struct {
// details. Use methods such as wuffs_base__status__is_error instead.
typedef struct {
int32_t code;
const char* msg;
} wuffs_base__status;
#define WUFFS_BASE__STATUS_OK 0 // 0x00000000
@@ -157,6 +158,7 @@ static inline wuffs_base__status //
WUFFS_BASE__MAKE_STATUS(int32_t code) {
return ((wuffs_base__status){
.code = code,
.msg = NULL,
});
}