Skip to content

Commit

Permalink
Let number reader save error message
Browse files Browse the repository at this point in the history
If the number reader is called with numread_packet->throwerror is FALSE,
the internal reader just returns #f on parse error and the detailed
error msg was lost.  Now we keep the error message in numread_packet
so that the public API can pass it to caller.

Preparation to fix #912.
  • Loading branch information
shirok committed Dec 28, 2024
1 parent e9d6be1 commit bbf12b4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/number.c
Original file line number Diff line number Diff line change
Expand Up @@ -4351,6 +4351,8 @@ struct numread_packet {
int strict; /* reject gauche extension */
int throwerror; /* throws error on parse, instead of
returning #f. */
const char *errormsg; /* if throwerror == FALSE, the error message
is kept here. */
};

enum { /* used in the exactness flag */
Expand Down Expand Up @@ -4937,6 +4939,8 @@ static ScmObj numread_error(const char *msg, struct numread_packet *ctx)
Scm_Error("bad number format %s: %A", msg,
Scm_MakeString(ctx->buffer, ctx->buflen,
ctx->buflen, 0));
} else {
ctx->errormsg = msg;
}
return SCM_FALSE;
}
Expand All @@ -4963,6 +4967,7 @@ ScmObj Scm_StringToNumber(ScmString *str, int radix, u_long flags)
ctx.explicit = FALSE;
ctx.strict = flags&SCM_NUMBER_FORMAT_STRICT_R7RS;
ctx.throwerror = FALSE;
ctx.errormsg = NULL;
ctx.radix = radix;
ctx.noradixprefix = flags&SCM_NUMBER_FORMAT_ALT_RADIX;
return read_number(&ctx);
Expand Down

0 comments on commit bbf12b4

Please sign in to comment.