Skip to content
Permalink
Browse files

Eliminate Get_Word_Name() wrapper

A problem in the emscripten build revealed there is a routine called
Get_Word_Name() that takes a REBVAL*, and if it is NULL subtly returns
the literal string "unnamed".  This behavior is undesirable, and clients
that need NULL tolerance are rare and should be coded specially to
handle the case.

Several uses were in commented out code.  This removes those, and
inlines the rest without the NULL tolerance.  Any attempts to get the
name of a NULL REBVAL* will now crash at the offending location.
  • Loading branch information
hostilefork committed Mar 15, 2016
1 parent 3b8a482 commit e8eb14017d7c20c5f36ffb16d01e9a4a5d92d52b
Showing with 14 additions and 40 deletions.
  1. +0 −2 src/core/c-frame.c
  2. +0 −10 src/core/c-word.c
  3. +6 −4 src/core/d-dump.c
  4. +1 −1 src/core/d-print.c
  5. +5 −2 src/core/s-mold.c
  6. +1 −1 src/core/t-integer.c
  7. +0 −18 src/core/t-money.c
  8. +0 −1 src/core/t-string.c
  9. +1 −1 src/core/t-tuple.c
@@ -1230,8 +1230,6 @@ void Resolve_Context(
) {
if (m < 0) SET_UNSET(var); // no value in source context
else *var = *CTX_VAR(source, m);
//Debug_Num("type:", VAL_TYPE(vals));
//Debug_Str(Get_Word_Name(words));
}
}
}
@@ -353,16 +353,6 @@ const REBYTE *Get_Sym_Name(REBCNT num)
}


//
// Get_Word_Name: C
//
const REBYTE *Get_Word_Name(const REBVAL *value)
{
if (value) return Get_Sym_Name(VAL_WORD_SYM(value));
return cb_cast("(unnamed)");
}


//
// Get_Type_Name: C
//
@@ -130,7 +130,7 @@ void Dump_Values(REBVAL *vp, REBCNT count)

cp = buf;
for (l = 0; l < count; l++) {
REBVAL *val = (REBVAL*)bp;
REBVAL *val = cast(REBVAL*, bp);
cp = Form_Hex_Pad(cp, l, 8);

*cp++ = ':';
@@ -147,9 +147,11 @@ void Dump_Values(REBVAL *vp, REBCNT count)
*cp++ = ' ';
}
n = 0;
if (IS_WORD((REBVAL*)val) || IS_GET_WORD((REBVAL*)val) || IS_SET_WORD((REBVAL*)val)) {
const char * name = cs_cast(Get_Word_Name((REBVAL*)val));
n = snprintf(s_cast(cp), sizeof(buf) - (cp - buf), " (%s)", name);
if (IS_WORD(val) || IS_GET_WORD(val) || IS_SET_WORD(val)) {
const REBYTE *name = Get_Sym_Name(VAL_WORD_SYM(val));
n = snprintf(
s_cast(cp), sizeof(buf) - (cp - buf), " (%s)", cs_cast(name)
);
}

*(cp + n) = 0;
@@ -460,7 +460,7 @@ void Debug_Space(REBCNT num)
//
void Debug_Word(const REBVAL *word)
{
Debug_Str(cs_cast(Get_Word_Name(word)));
Debug_Str(cs_cast(Get_Sym_Name(VAL_WORD_SYM(word))));
}


@@ -85,13 +85,16 @@ REBSER *Emit(REB_MOLD *mold, const char *fmt, ...)

for (; *fmt; fmt++) {
switch (*fmt) {
case 'W': // Word symbol
case 'W': { // Word symbol
REBVAL *any_word = va_arg(va, const REBVAL*);

This comment has been minimized.

Copy link
@giuliolunati

giuliolunati Mar 16, 2016

emcc complains about discarding const qualifier. Maybe change to: const REVAL *any_word = ... ?

This comment has been minimized.

Copy link
@hostilefork

hostilefork Mar 18, 2016

Author Member

Thanks! (Travis actually caught it, I was just lazy about doing anything about it...figured I'd wait until the next commit, but there hasn't been one... so I went ahead and made a commit just for this)

Append_UTF8_May_Fail(
series,
Get_Word_Name(va_arg(va, const REBVAL*)),
Get_Sym_Name(VAL_WORD_SYM(any_word)),
-1
);
break;
}

case 'V': // Value
Mold_Value(mold, va_arg(va, const REBVAL*), TRUE);
break;
@@ -186,7 +186,7 @@ void Value_To_Int64(REBI64 *out, const REBVAL *value, REBOOL no_sign)
// more sense as these would be hexes likely typed in by users,
// who rarely do 2s-complement math in their head.

const REBYTE *bp = Get_Word_Name(value);
const REBYTE *bp = Get_Sym_Name(VAL_WORD_SYM(value));
REBCNT len = LEN_BYTES(bp);

if (len > MAX_HEX_LEN) {
@@ -77,24 +77,6 @@ void Bin_To_Money_May_Fail(REBVAL *result, REBVAL *val)
if (len > 12) len = 12;
memcpy(buf, VAL_BIN_AT(val), len);
}
#ifdef removed
else if (IS_ISSUE(val)) {
//if (!(len = Scan_Hex_Bytes(val, 24, buf))) return FALSE;
REBYTE *ap = Get_Word_Name(val);
REBYTE *bp = &buf[0];
REBCNT alen;
REBUNI c;
len = LEN_BYTES(ap); // UTF-8 len
if (len & 1) return FALSE; // must have even # of chars
len /= 2;
if (len > 12) return FALSE; // valid even for UTF-8
for (alen = 0; alen < len; alen++) {
if (!Scan_Hex2(ap, &c, 0)) return FALSE;
*bp++ = (REBYTE)c;
ap += 2;
}
}
#endif
else
fail (Error_Invalid_Arg(val));

@@ -242,7 +242,6 @@ static REBSER *make_string(REBVAL *arg, REBOOL make)
// MAKE/TO <type> <any-word>
else if (ANY_WORD(arg)) {
ser = Copy_Mold_Value(arg, 0 /* opts... MOPT_0? */);
//ser = Append_UTF8_May_Fail(0, Get_Word_Name(arg), -1);
}
// MAKE/TO <type> #"A"
else if (IS_CHAR(arg)) {
@@ -385,7 +385,7 @@ REBTYPE(Tuple)
vp = VAL_TUPLE(value);
if (IS_ISSUE(arg)) {
REBUNI c;
ap = Get_Word_Name(arg);
ap = Get_Sym_Name(VAL_WORD_SYM(arg));
len = LEN_BYTES(ap); // UTF-8 len
if (len & 1) goto bad_arg; // must have even # of chars
len /= 2;

0 comments on commit e8eb140

Please sign in to comment.
You can’t perform that action at this time.