Make the status type a const char*, not a struct

This commit is contained in:
Nigel Tao committed 2018-08-12 16:05:14 +10:00
1 parent e0311e3bb2
commit b840c80040
24 files changed
+624 -815

No files matched your search

@@ -56,10 +56,10 @@ static inline void wuffs_base__ignore_check_wuffs_version_status(
case n:;
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
if (status.code < 0) { \
goto exit; \
} else if (status.code == 0) { \
if (!status) { \
goto ok; \
} else if (*status != '$') { \
goto exit; \
} \
coro_susp_point = n; \
goto suspend; \
+13 -29
View File
@@ -99,45 +99,29 @@ typedef struct {
// --------
// A status code is either zero (OK), positive (a recoverable suspension or
// 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.
// A status is either NULL (meaning OK or no error) or string message. That
// message is human-readable, for programmers, but it is not for end users. It
// is not localized, and does not contain additional contextual information
// such as a source filename.
//
// Do not manipulate these bits directly; they are private implementation
// details. Use methods such as wuffs_base__status__is_error instead.
typedef struct {
int32_t code;
const char* msg;
} wuffs_base__status;
// Status strings are statically allocated and should never be free'd.
typedef const char* wuffs_base__status;
// !! INSERT wuffs_base__status names.
// TODO: turn WUFFS_BASE__MAKE_STATUS into a macro, and add a msg field.
static inline wuffs_base__status //
WUFFS_BASE__MAKE_STATUS(int32_t code) {
return ((wuffs_base__status){
.code = code,
.msg = NULL,
});
static inline bool //
wuffs_base__status__is_error(wuffs_base__status z) {
return z && (*z != '$');
}
static inline bool //
wuffs_base__status__is_error(wuffs_base__status s) {
return s.code < 0;
wuffs_base__status__is_ok(wuffs_base__status z) {
return z == NULL;
}
static inline bool //
wuffs_base__status__is_ok(wuffs_base__status s) {
return s.code == 0;
}
static inline bool //
wuffs_base__status__is_suspension(wuffs_base__status s) {
return s.code > 0;
wuffs_base__status__is_suspension(wuffs_base__status z) {
return z && (*z == '$');
}
const char* //
@@ -809,18 +809,17 @@ wuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,
wuffs_base__pixel_config* pixcfg,
wuffs_base__slice_u8 pixbuf_memory) {
if (!b) {
return WUFFS_BASE__MAKE_STATUS(WUFFS_BASE__ERROR_BAD_RECEIVER);
return wuffs_base__error__bad_receiver;
}
*b = ((wuffs_base__pixel_buffer){});
if (!pixcfg) {
return WUFFS_BASE__MAKE_STATUS(WUFFS_BASE__ERROR_BAD_ARGUMENT);
return wuffs_base__error__bad_argument;
}
// TODO: don't assume 1 byte per pixel. Don't assume packed.
uint64_t wh = ((uint64_t)pixcfg->private_impl.width) *
((uint64_t)pixcfg->private_impl.height);
if (wh > pixbuf_memory.len) {
return WUFFS_BASE__MAKE_STATUS(
WUFFS_BASE__ERROR_BAD_ARGUMENT_LENGTH_TOO_SHORT);
return wuffs_base__error__bad_argument_length_too_short;
}
b->private_impl.pixcfg = *pixcfg;
wuffs_base__table_u8* tab = &b->private_impl.planes[0];
@@ -828,7 +827,7 @@ wuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,
tab->width = pixcfg->private_impl.width;
tab->height = pixcfg->private_impl.height;
tab->stride = pixcfg->private_impl.width;
return WUFFS_BASE__MAKE_STATUS(WUFFS_BASE__STATUS_OK);
return NULL;
}
// The palette argument is ignored unless its length is exactly 1024.