summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-06-13 23:16:53 +0900
committerYukihiro Matsumoto <[email protected]>2012-06-13 23:16:53 +0900
commit6919ca61edb2da9ea81217fdc355eef1208a6398 (patch)
tree45db6c83b9331d5bff31308039151539c496f093
parent8004168725dc7e3c6975400c40fc9419a0ffed65 (diff)
downloadmruby-6919ca61edb2da9ea81217fdc355eef1208a6398.tar.gz
mruby-6919ca61edb2da9ea81217fdc355eef1208a6398.zip
stop using strtol (via readint) except in load.c; use custom readint_float
-rw-r--r--include/mrbconf.h1
-rw-r--r--src/codegen.c19
-rw-r--r--src/load.c2
3 files changed, 12 insertions, 10 deletions
diff --git a/include/mrbconf.h b/include/mrbconf.h
index f2b23258e..5848eee1a 100644
--- a/include/mrbconf.h
+++ b/include/mrbconf.h
@@ -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 */
diff --git a/src/codegen.c b/src/codegen.c
index 5f8d17314..63531eac1 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -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);
}
@@ -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);
}
diff --git a/src/load.c b/src/load.c
index 1b607909c..053ec2d7e 100644
--- a/src/load.c
+++ b/src/load.c
@@ -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;