mruby-sprintf to use mrb_int formatting macros; ref #3076

parent 3cf5af68
......@@ -22,6 +22,8 @@ struct mrb_state;
# error "You can't define MRB_INT16 and MRB_INT64 at the same time."
#endif
#include <inttypes.h>
#if defined(MRB_INT64)
typedef int64_t mrb_int;
# define MRB_INT_BIT 64
......
......@@ -150,6 +150,7 @@ create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, cha
}
cxt->capture_errors = TRUE;
cxt->no_optimize = TRUE;
// cxt->dump_result = TRUE;
p = mrb_parse_nstring(mrb, s, len, cxt);
......
......@@ -759,7 +759,7 @@ retry:
case 'B':
case 'u': {
mrb_value val = GETARG();
char fbuf[32], nbuf[68], *s;
char nbuf[68], *s;
const char *prefix = NULL;
int sign = 0, dots = 0;
char sc = 0;
......@@ -836,8 +836,6 @@ retry:
}
}
if (sign) {
char c = *p;
if (c == 'i') c = 'd'; /* %d and %i are identical */
if (v < 0) {
v = -v;
sc = '-';
......@@ -851,28 +849,40 @@ retry:
sc = ' ';
width--;
}
if (base == 2) {
snprintf(nbuf, sizeof(nbuf), "%s", RSTRING_PTR(val));
}
else {
snprintf(fbuf, sizeof(fbuf), "%%l%c", c);
snprintf(nbuf, sizeof(nbuf), fbuf, v);
switch (base) {
case 2:
strncpy(nbuf, RSTRING_PTR(val), sizeof(nbuf));
break;
case 8:
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRIo, v);
break;
case 10:
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRId, v);
break;
case 16:
snprintf(nbuf, sizeof(nbuf), "%"MRB_PRIx, v);
break;
}
s = nbuf;
}
else {
char c = *p;
if (c == 'X') c = 'x';
s = nbuf;
if (v < 0) {
dots = 1;
}
if (base == 2) {
snprintf(++s, sizeof(nbuf) - 1, "%s", RSTRING_PTR(val));
}
else {
snprintf(fbuf, sizeof(fbuf), "%%l%c", c);
snprintf(++s, sizeof(nbuf) - 1, fbuf, v);
switch (base) {
case 2:
strncpy(++s, RSTRING_PTR(val), sizeof(nbuf)-1);
break;
case 8:
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRIo, v);
break;
case 10:
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRId, v);
break;
case 16:
snprintf(++s, sizeof(nbuf)-1, "%"MRB_PRIx, v);
break;
}
if (v < 0) {
char d;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment