1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-23 23:36:27 -07:00

Declaring result codes using a relational macro, so that tests can print more meaningful output, and to eliminate redundant code.

Copied from Perforce
 Change: 184382
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Richard Brooksby 2014-02-19 11:55:14 +00:00
parent 9d0644c05e
commit ba1a4f78cb
4 changed files with 41 additions and 51 deletions

View file

@ -371,23 +371,8 @@ enum {
/* .result-codes: Result Codes -- see <design/type/#res> */
/* These definitions must match <code/mps.h#result-codes>. */
/* This is checked by <code/mpsi.c#check.rc>. */
/* Changing this list entails changing the list in */
/* <code/mps.h#result-codes> and the check in <code/mpsi.c#check.rc> */
enum {
ResOK = 0, /* MPS_RES_OK */
ResFAIL, /* MPS_RES_FAIL */
ResRESOURCE, /* MPS_RES_RESOURCE */
ResMEMORY, /* MPS_RES_MEMORY */
ResLIMIT, /* MPS_RES_LIMIT */
/* note "LIMIT" does _not_ have usual end-of-enum meaning -rhsk */
ResUNIMPL, /* MPS_RES_UNIMPL */
ResIO, /* MPS_RES_IO */
ResCOMMIT_LIMIT, /* MPS_RES_COMMIT_LIMIT */
ResPARAM /* MPS_RES_PARAM */
};
_mps_ENUM_DEF(_mps_RES_ENUM, Res)
/* TraceStates -- see <design/trace/> */

View file

@ -77,21 +77,25 @@ typedef mps_word_t mps_clock_t; /* processor time */
typedef mps_word_t mps_label_t; /* telemetry label */
/* Result Codes */
/* .result-codes: Keep in sync with <code/mpmtypes.h#result-codes> */
/* and the check in <code/mpsi.c#check.rc> */
enum {
MPS_RES_OK = 0, /* success (always zero) */
MPS_RES_FAIL, /* unspecified failure */
MPS_RES_RESOURCE, /* unable to obtain resources */
MPS_RES_MEMORY, /* unable to obtain memory */
MPS_RES_LIMIT, /* limitation reached */
MPS_RES_UNIMPL, /* unimplemented facility */
MPS_RES_IO, /* system I/O error */
MPS_RES_COMMIT_LIMIT, /* arena commit limit exceeded */
MPS_RES_PARAM /* illegal user parameter value */
};
#define _mps_RES_ENUM(R, X) \
R(X, OK, "success (always zero)") \
R(X, FAIL, "unspecified failure") \
R(X, RESOURCE, "unable to obtain resources") \
R(X, MEMORY, "unable to obtain memory") \
R(X, LIMIT, "limitation reached") \
R(X, UNIMPL, "unimplemented facility") \
R(X, IO, "system I/O error") \
R(X, COMMIT_LIMIT, "arena commit limit exceeded") \
R(X, PARAM, "illegal user parameter value")
#define _mps_ENUM_DEF_ROW(prefix, ident, doc) prefix##ident,
#define _mps_ENUM_DEF(REL, prefix) \
enum { \
REL(_mps_ENUM_DEF_ROW, prefix) \
_mps_##prefix##LIMIT \
};
_mps_ENUM_DEF(_mps_RES_ENUM, MPS_RES_)
/* Format and Root Method Types */
/* see design.mps.root-interface */

View file

@ -72,18 +72,7 @@ SRCID(mpsi, "$Id$");
static Bool mpsi_check(void)
{
/* .check.rc: Check that external and internal result codes match. */
/* See <code/mps.h#result-codes> and <code/mpmtypes.h#result-codes>. */
/* Also see .check.enum.cast. */
CHECKL(COMPATTYPE(mps_res_t, Res));
CHECKL((int)MPS_RES_OK == (int)ResOK);
CHECKL((int)MPS_RES_FAIL == (int)ResFAIL);
CHECKL((int)MPS_RES_RESOURCE == (int)ResRESOURCE);
CHECKL((int)MPS_RES_MEMORY == (int)ResMEMORY);
CHECKL((int)MPS_RES_LIMIT == (int)ResLIMIT);
CHECKL((int)MPS_RES_UNIMPL == (int)ResUNIMPL);
CHECKL((int)MPS_RES_IO == (int)ResIO);
CHECKL((int)MPS_RES_COMMIT_LIMIT == (int)ResCOMMIT_LIMIT);
/* Check that external and internal message types match. */
/* See <code/mps.h#message.types> and */

View file

@ -326,6 +326,17 @@ void rnd_state_set_v2(unsigned long seed0_v2)
}
/* res_strings -- human readable MPS result codes */
static struct {
const char *ident;
const char *doc;
} res_strings[] = {
#define RES_STRINGS_ROW(X, ident, doc) {#ident, #doc},
_mps_RES_ENUM(RES_STRINGS_ROW, X)
};
/* verror -- die with message */
void verror(const char *format, va_list args)
@ -359,26 +370,27 @@ void error(const char *format, ...)
}
/* die -- Test a return code, and exit on error */
void die(mps_res_t res, const char *s)
{
if (res != MPS_RES_OK) {
error("\n%s: %d\n", s, res);
}
}
/* die_expect -- Test a return code, and exit on unexpected result */
void die_expect(mps_res_t res, mps_res_t expected, const char *s)
{
if (res != expected) {
error("\n%s: %d\n", s, res);
if (0 <= res && (unsigned)res < sizeof(res_strings) / sizeof(res_strings[0]))
error("\n%s: %s: %s\n", s, res_strings[res].ident, res_strings[res].doc);
else
error("\n%s: %d: unknown result code\n", s, res);
}
}
/* die -- Test a return code, and exit on error */
void die(mps_res_t res, const char *s)
{
die_expect(res, MPS_RES_OK, s);
}
/* cdie -- Test a C boolean, and exit on error */
void cdie(int res, const char *s)