Skip to content

Commit

Permalink
stop using strtol (via readint) except in load.c; use custom readint_…
Browse files Browse the repository at this point in the history
…float
  • Loading branch information
matz committed Jun 13, 2012
1 parent 8004168 commit 6919ca6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion include/mrbconf.h
Expand Up @@ -19,7 +19,6 @@ typedef double mrb_float;

typedef int mrb_int;
typedef intptr_t mrb_sym;
#define readint(p,base) strtol((p),NULL,(base))

#undef PARSER_DUMP /* do not print out parser state */
//#define PARSER_DUMP /* print out parser state */
Expand Down
19 changes: 11 additions & 8 deletions src/codegen.c
Expand Up @@ -1575,16 +1575,18 @@ codegen(codegen_scope *s, node *tree, int val)
if (val) {
char *p = (char*)tree->car;
int base = (intptr_t)tree->cdr->car;
long i = readint(p, base);
mrb_float f;
mrb_int i;
mrb_code co;

if ((i == LONG_MAX && errno == ERANGE) || !FIXABLE(i)) {
mrb_float f = readint_float(s, p, base);
f = readint_float(s, p, base);
if (!FIXABLE(f)) {
int off = new_lit(s, mrb_float_value(f));

genop(s, MKOP_ABx(OP_LOADL, cursp(), off));
}
else {
i = (mrb_int)f;
if (i < MAXARG_sBx && i > -MAXARG_sBx) {
co = MKOP_AsBx(OP_LOADI, cursp(), i);
}
Expand Down Expand Up @@ -1629,17 +1631,18 @@ codegen(codegen_scope *s, node *tree, int val)
{
char *p = (char*)tree->car;
int base = (intptr_t)tree->cdr->car;
long i = readint(p, base);
mrb_float f;
mrb_int i;
mrb_code co;

if ((i == LONG_MAX && errno == ERANGE) || !FIXABLE(i)) {
mrb_float f = readint_float(s, p, base);
f = readint_float(s, p, base);
if (!FIXABLE(f)) {
int off = new_lit(s, mrb_float_value(-f));

genop(s, MKOP_ABx(OP_LOADL, cursp(), off));
}
else {
i = -i;
i = (mrb_int)-f;
if (i < MAXARG_sBx && i > -MAXARG_sBx) {
co = MKOP_AsBx(OP_LOADI, cursp(), i);
}
Expand Down
2 changes: 1 addition & 1 deletion src/load.c
Expand Up @@ -413,7 +413,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32

switch (tt) { //pool data
case MRB_TT_FIXNUM:
fix_num = readint(buf, 10);
fix_num = strtol(buf, NULL, 10);
irep->pool[i] = mrb_fixnum_value(fix_num);
break;

Expand Down

0 comments on commit 6919ca6

Please sign in to comment.