aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorR. Blaine Whittle <[email protected]>2013-02-20 14:46:20 +0100
committerSverker Eriksson <[email protected]>2013-02-21 18:44:05 +0100
commitd78e430de1f22ed122d58ad49984ff88a8171b8f (patch)
tree691c14b255c6436b3667f6f908fbbf1156f7e151
parente41674160b3059a1bc507b4718c173c9879e506a (diff)
downloadotp-d78e430de1f22ed122d58ad49984ff88a8171b8f.tar.gz
otp-d78e430de1f22ed122d58ad49984ff88a8171b8f.tar.bz2
otp-d78e430de1f22ed122d58ad49984ff88a8171b8f.zip
erts: Correct internal printf integer type for win64
-rw-r--r--erts/emulator/beam/erl_printf_term.c54
-rw-r--r--erts/include/internal/erl_printf_format.h23
-rw-r--r--erts/lib_src/common/erl_printf_format.c64
3 files changed, 79 insertions, 62 deletions
diff --git a/erts/emulator/beam/erl_printf_term.c b/erts/emulator/beam/erl_printf_term.c
index 2320b64295..2ec59febcb 100644
--- a/erts/emulator/beam/erl_printf_term.c
+++ b/erts/emulator/beam/erl_printf_term.c
@@ -57,17 +57,17 @@ do { \
(CNT) += res__; \
} while (0)
-#define PRINT_ULONG(CNT, FN, ARG, C, P, W, I) \
+#define PRINT_UWORD(CNT, FN, ARG, C, P, W, I) \
do { \
- int res__ = erts_printf_ulong((FN), (ARG), (C), (P), (W), (I)); \
+ int res__ = erts_printf_uword((FN), (ARG), (C), (P), (W), (I)); \
if (res__ < 0) \
return res__; \
(CNT) += res__; \
} while (0)
-#define PRINT_SLONG(CNT, FN, ARG, C, P, W, I) \
+#define PRINT_SWORD(CNT, FN, ARG, C, P, W, I) \
do { \
- int res__ = erts_printf_slong((FN), (ARG), (C), (P), (W), (I)); \
+ int res__ = erts_printf_sword((FN), (ARG), (C), (P), (W), (I)); \
if (res__ < 0) \
return res__; \
(CNT) += res__; \
@@ -153,7 +153,7 @@ static int print_atom_name(fmtfn_t fn, void* arg, Eterm atom, long *dcount)
if ((i < 0) || (i >= atom_table_size()) || (atom_tab(i) == NULL)) {
PRINT_STRING(res, fn, arg, "<bad atom index: ");
- PRINT_SLONG(res, fn, arg, 'd', 0, 1, (signed long) i);
+ PRINT_SWORD(res, fn, arg, 'd', 0, 1, (ErlPfSWord) i);
PRINT_CHAR(res, fn, arg, '>');
return res;
}
@@ -203,7 +203,7 @@ static int print_atom_name(fmtfn_t fn, void* arg, Eterm atom, long *dcount)
default:
if (IS_CNTRL(c)) {
PRINT_CHAR(res, fn, arg, '\\');
- PRINT_ULONG(res, fn, arg, 'o', 1, 3, (unsigned long) c);
+ PRINT_UWORD(res, fn, arg, 'o', 1, 3, (ErlPfUWord) c);
}
else
PRINT_CHAR(res, fn, arg, (char) c);
@@ -334,7 +334,7 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount,
break;
}
case SMALL_DEF:
- PRINT_SLONG(res, fn, arg, 'd', 0, 1, (signed long) signed_val(obj));
+ PRINT_SWORD(res, fn, arg, 'd', 0, 1, (ErlPfSWord) signed_val(obj));
break;
case BIG_DEF: {
int print_res;
@@ -360,36 +360,36 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount,
case REF_DEF:
case EXTERNAL_REF_DEF:
PRINT_STRING(res, fn, arg, "#Ref<");
- PRINT_ULONG(res, fn, arg, 'u', 0, 1,
- (unsigned long) ref_channel_no(wobj));
+ PRINT_UWORD(res, fn, arg, 'u', 0, 1,
+ (ErlPfUWord) ref_channel_no(wobj));
ref_num = ref_numbers(wobj);
for (i = ref_no_of_numbers(wobj)-1; i >= 0; i--) {
PRINT_CHAR(res, fn, arg, '.');
- PRINT_ULONG(res, fn, arg, 'u', 0, 1, (unsigned long) ref_num[i]);
+ PRINT_UWORD(res, fn, arg, 'u', 0, 1, (ErlPfUWord) ref_num[i]);
}
PRINT_CHAR(res, fn, arg, '>');
break;
case PID_DEF:
case EXTERNAL_PID_DEF:
PRINT_CHAR(res, fn, arg, '<');
- PRINT_ULONG(res, fn, arg, 'u', 0, 1,
- (unsigned long) pid_channel_no(wobj));
+ PRINT_UWORD(res, fn, arg, 'u', 0, 1,
+ (ErlPfUWord) pid_channel_no(wobj));
PRINT_CHAR(res, fn, arg, '.');
- PRINT_ULONG(res, fn, arg, 'u', 0, 1,
- (unsigned long) pid_number(wobj));
+ PRINT_UWORD(res, fn, arg, 'u', 0, 1,
+ (ErlPfUWord) pid_number(wobj));
PRINT_CHAR(res, fn, arg, '.');
- PRINT_ULONG(res, fn, arg, 'u', 0, 1,
- (unsigned long) pid_serial(wobj));
+ PRINT_UWORD(res, fn, arg, 'u', 0, 1,
+ (ErlPfUWord) pid_serial(wobj));
PRINT_CHAR(res, fn, arg, '>');
break;
case PORT_DEF:
case EXTERNAL_PORT_DEF:
PRINT_STRING(res, fn, arg, "#Port<");
- PRINT_ULONG(res, fn, arg, 'u', 0, 1,
- (unsigned long) port_channel_no(wobj));
+ PRINT_UWORD(res, fn, arg, 'u', 0, 1,
+ (ErlPfUWord) port_channel_no(wobj));
PRINT_CHAR(res, fn, arg, '.');
- PRINT_ULONG(res, fn, arg, 'u', 0, 1,
- (unsigned long) port_number(wobj));
+ PRINT_UWORD(res, fn, arg, 'u', 0, 1,
+ (ErlPfUWord) port_number(wobj));
PRINT_CHAR(res, fn, arg, '>');
break;
case LIST_DEF:
@@ -446,7 +446,7 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount,
PRINT_STRING(res, fn, arg, "<<1 byte>>");
else {
PRINT_STRING(res, fn, arg, "<<");
- PRINT_ULONG(res, fn, arg, 'u', 0, 1, (unsigned long) pb->size);
+ PRINT_UWORD(res, fn, arg, 'u', 0, 1, (ErlPfUWord) pb->size);
PRINT_STRING(res, fn, arg, " bytes>>");
}
}
@@ -462,8 +462,8 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount,
PRINT_CHAR(res, fn, arg, '.');
PRINT_BUF(res, fn, arg, name->name, name->len);
PRINT_CHAR(res, fn, arg, '.');
- PRINT_SLONG(res, fn, arg, 'd', 0, 1,
- (signed long) ep->code[2]);
+ PRINT_SWORD(res, fn, arg, 'd', 0, 1,
+ (ErlPfSWord) ep->code[2]);
PRINT_CHAR(res, fn, arg, '>');
}
break;
@@ -475,11 +475,11 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount,
PRINT_STRING(res, fn, arg, "#Fun<");
PRINT_BUF(res, fn, arg, ap->name, ap->len);
PRINT_CHAR(res, fn, arg, '.');
- PRINT_SLONG(res, fn, arg, 'd', 0, 1,
- (signed long) funp->fe->old_index);
+ PRINT_SWORD(res, fn, arg, 'd', 0, 1,
+ (ErlPfSWord) funp->fe->old_index);
PRINT_CHAR(res, fn, arg, '.');
- PRINT_SLONG(res, fn, arg, 'd', 0, 1,
- (signed long) funp->fe->old_uniq);
+ PRINT_SWORD(res, fn, arg, 'd', 0, 1,
+ (ErlPfSWord) funp->fe->old_uniq);
PRINT_CHAR(res, fn, arg, '>');
}
break;
diff --git a/erts/include/internal/erl_printf_format.h b/erts/include/internal/erl_printf_format.h
index 064c4a5c09..6fe4af8fbb 100644
--- a/erts/include/internal/erl_printf_format.h
+++ b/erts/include/internal/erl_printf_format.h
@@ -28,6 +28,22 @@
#include <stdarg.h>
#include <stdlib.h>
+#include "erl_int_sizes_config.h"
+
+#if SIZEOF_VOID_P == SIZEOF_LONG
+typedef unsigned long ErlPfUWord;
+typedef long ErlPfSWord;
+#elif SIZEOF_VOID_P == SIZEOF_INT
+typedef unsigned int ErlPfUWord;
+typedef int ErlPfSWord;
+#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
+typedef unsigned long long ErlPfUWord;
+typedef long long ErlPfSWord;
+#else
+#error Found no appropriate type to use for 'Eterm', 'Uint' and 'Sint'
+#endif
+
+
typedef int (*fmtfn_t)(void*, char*, size_t);
extern int erts_printf_format(fmtfn_t, void*, char*, va_list);
@@ -36,11 +52,12 @@ extern int erts_printf_char(fmtfn_t, void*, char);
extern int erts_printf_string(fmtfn_t, void*, char *);
extern int erts_printf_buf(fmtfn_t, void*, char *, size_t);
extern int erts_printf_pointer(fmtfn_t, void*, void *);
-extern int erts_printf_ulong(fmtfn_t, void*, char, int, int, unsigned long);
-extern int erts_printf_slong(fmtfn_t, void*, char, int, int, signed long);
+extern int erts_printf_uword(fmtfn_t, void*, char, int, int, ErlPfUWord);
+extern int erts_printf_sword(fmtfn_t, void*, char, int, int, ErlPfSWord);
extern int erts_printf_double(fmtfn_t, void *, char, int, int, double);
extern int (*erts_printf_eterm_func)(fmtfn_t, void*, unsigned long, long, unsigned long*);
-#endif
+
+#endif /* ERL_PRINTF_FORMAT_H__ */
diff --git a/erts/lib_src/common/erl_printf_format.c b/erts/lib_src/common/erl_printf_format.c
index 384b1b1ad7..7148b5149b 100644
--- a/erts/lib_src/common/erl_printf_format.c
+++ b/erts/lib_src/common/erl_printf_format.c
@@ -234,7 +234,7 @@ static int fmt_fld(fmtfn_t fn,void* arg,
return 0;
}
-static int fmt_long(fmtfn_t fn,void* arg,int sign,unsigned long uval,
+static int fmt_uword(fmtfn_t fn,void* arg,int sign,ErlPfUWord uval,
int width,int precision,int fmt,int* count)
{
char buf[32];
@@ -475,7 +475,7 @@ int erts_printf_format(fmtfn_t fn, void* arg, char* fmt, va_list ap)
int res = 0;
while(*ptr) {
- unsigned long ul_val;
+ ErlPfUWord ul_val;
int fmt = 0;
int width = -1;
int precision = -1;
@@ -661,22 +661,22 @@ int erts_printf_format(fmtfn_t fn, void* arg, char* fmt, va_list ap)
switch(fmt & FMTL_MASK) {
case FMTL_hh: {
signed char tval = (signed char) va_arg(ap,int);
- ul_val = (unsigned long) (tval < 0 ? (-tval) : tval);
- res = fmt_long(fn,arg,SIGN(tval),ul_val,
+ ul_val = (ErlPfUWord) (tval < 0 ? (-tval) : tval);
+ res = fmt_uword(fn,arg,SIGN(tval),ul_val,
width,precision,fmt,&count);
break;
}
case FMTL_h: {
signed short tval = (signed short) va_arg(ap,int);
- ul_val = (unsigned long) (tval < 0 ? (-tval) : tval);
- res = fmt_long(fn,arg,SIGN(tval),ul_val,
+ ul_val = (ErlPfUWord) (tval < 0 ? (-tval) : tval);
+ res = fmt_uword(fn,arg,SIGN(tval),ul_val,
width,precision,fmt,&count);
break;
}
case FMTL_l: {
signed long tval = (signed long) va_arg(ap,long);
- ul_val = (unsigned long) (tval < 0 ? (-tval) : tval);
- res = fmt_long(fn,arg,SIGN(tval),ul_val,
+ ul_val = (ErlPfUWord) (tval < 0 ? (-tval) : tval);
+ res = fmt_uword(fn,arg,SIGN(tval),ul_val,
width,precision,fmt,&count);
break;
}
@@ -693,8 +693,8 @@ int erts_printf_format(fmtfn_t fn, void* arg, char* fmt, va_list ap)
#endif
default: {
signed int tval = (signed int) va_arg(ap,int);
- ul_val = (unsigned long) (tval < 0 ? (-tval) : tval);
- res = fmt_long(fn,arg,SIGN(tval),ul_val,
+ ul_val = (ErlPfUWord) (tval < 0 ? (-tval) : tval);
+ res = fmt_uword(fn,arg,SIGN(tval),ul_val,
width,precision,fmt,&count);
break;
}
@@ -707,21 +707,21 @@ int erts_printf_format(fmtfn_t fn, void* arg, char* fmt, va_list ap)
switch(fmt & FMTL_MASK) {
case FMTL_hh: {
unsigned char tval = (unsigned char) va_arg(ap,int);
- ul_val = (unsigned long) tval;
- res = fmt_long(fn,arg,USIGN(tval),ul_val,
+ ul_val = (ErlPfUWord) tval;
+ res = fmt_uword(fn,arg,USIGN(tval),ul_val,
width,precision,fmt,&count);
break;
}
case FMTL_h: {
unsigned short tval = (unsigned short) va_arg(ap,int);
- ul_val = (unsigned long) tval;
- res = fmt_long(fn,arg,USIGN(tval),ul_val,
+ ul_val = (ErlPfUWord) tval;
+ res = fmt_uword(fn,arg,USIGN(tval),ul_val,
width,precision,fmt,&count);
break;
}
case FMTL_l: {
- ul_val = (unsigned long) va_arg(ap,long);
- res = fmt_long(fn,arg,USIGN(ul_val),ul_val,
+ ul_val = (ErlPfUWord) va_arg(ap,long);
+ res = fmt_uword(fn,arg,USIGN(ul_val),ul_val,
width,precision,fmt,&count);
break;
}
@@ -736,8 +736,8 @@ int erts_printf_format(fmtfn_t fn, void* arg, char* fmt, va_list ap)
#endif
default: {
unsigned int tval = (unsigned int) va_arg(ap,int);
- ul_val = (unsigned long) tval;
- res = fmt_long(fn,arg,USIGN(tval),ul_val,
+ ul_val = (ErlPfUWord) tval;
+ res = fmt_uword(fn,arg,USIGN(tval),ul_val,
width,precision,fmt,&count);
break;
}
@@ -795,10 +795,10 @@ int erts_printf_format(fmtfn_t fn, void* arg, char* fmt, va_list ap)
case FMTC_p: {
void* addr = va_arg(ap, void*);
- res = fmt_long(fn,
+ res = fmt_uword(fn,
arg,
- USIGN((unsigned long) addr),
- (unsigned long) addr,
+ USIGN((ErlPfUWord) addr),
+ (ErlPfUWord) addr,
width < 0 ? ((int) 2*sizeof(void *)) : width,
(precision < 0
? ((int) 2*sizeof(void *))
@@ -890,8 +890,8 @@ int
erts_printf_pointer(fmtfn_t fn, void *arg, void *ptr)
{
int count = 0;
- int res = fmt_long(fn, arg, USIGN((unsigned long) ptr),
- (unsigned long) ptr, 2*sizeof(void *),
+ int res = fmt_uword(fn, arg, USIGN((ErlPfUWord) ptr),
+ (ErlPfUWord) ptr, 2*sizeof(void *),
2*sizeof(void *), FMTC_x|FMTF_pad|FMTF_alt, &count);
if (res < 0)
return res;
@@ -899,8 +899,8 @@ erts_printf_pointer(fmtfn_t fn, void *arg, void *ptr)
}
int
-erts_printf_ulong(fmtfn_t fn, void *arg, char conv, int pad, int width,
- unsigned long val)
+erts_printf_uword(fmtfn_t fn, void *arg, char conv, int pad, int width,
+ ErlPfUWord val)
{
int count = 0;
int res;
@@ -917,21 +917,21 @@ erts_printf_ulong(fmtfn_t fn, void *arg, char conv, int pad, int width,
}
if (pad)
prec = width;
- res = fmt_long(fn, arg, USIGN(val), val, width, prec, fmt, &count);
+ res = fmt_uword(fn, arg, USIGN(val), val, width, prec, fmt, &count);
if (res < 0)
return res;
return count;
}
-extern int
-erts_printf_slong(fmtfn_t fn, void *arg, char conv, int pad, int width,
- signed long val)
+int
+erts_printf_sword(fmtfn_t fn, void *arg, char conv, int pad, int width,
+ ErlPfSWord val)
{
int count = 0;
int res;
int fmt = 0;
int prec = -1;
- unsigned long ul_val;
+ ErlPfUWord ul_val;
switch (conv) {
case 'd': fmt |= FMTC_d; break;
case 'i': fmt |= FMTC_d; break;
@@ -943,8 +943,8 @@ erts_printf_slong(fmtfn_t fn, void *arg, char conv, int pad, int width,
}
if (pad)
prec = width;
- ul_val = (unsigned long) (val < 0 ? -val : val);
- res = fmt_long(fn, arg, SIGN(val), ul_val, width, prec, fmt, &count);
+ ul_val = (ErlPfUWord) (val < 0 ? -val : val);
+ res = fmt_uword(fn, arg, SIGN(val), ul_val, width, prec, fmt, &count);
if (res < 0)
return res;
return count;