From: Michael Beck Date: Thu, 6 Jan 2011 01:48:42 +0000 (+0000) Subject: Enable lc_printf and friends handling of j, t, and z length modifier. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=662bc34895ef0a6803c91aa6b9fcabc5d70b3d60;p=libfirm Enable lc_printf and friends handling of j, t, and z length modifier. Add a work-around for non-C99 MSCRT. Use ir_printf now instead of printf. [r28212] --- diff --git a/ir/libcore/lc_printf.c b/ir/libcore/lc_printf.c index e740c0347..bfe0355e9 100644 --- a/ir/libcore/lc_printf.c +++ b/ir/libcore/lc_printf.c @@ -172,6 +172,39 @@ static char *make_fmt(char *buf, size_t len, const lc_arg_occ_t *occ) strncpy(mod, occ->modifier, sizeof(mod) - 1); mod[LC_MIN(sizeof(mod) - 1, occ->modifier_length)] = '\0'; +#ifdef _MSC_VER + /* work-around for buggy mscrt not supporting z, j, and t modifier */ + if (occ->modifier_length == 1) { + if (mod[0] == 'z') { + if (sizeof(size_t) == sizeof(int)) + mod[0] = '\0'; + if (sizeof(size_t) == sizeof(__int64)) { + mod[0] = 'I'; + mod[1] = '6'; + mod[2] = '4'; + mod[3] = '\0'; + } + } else if (mod[0] == 't') { + if (sizeof(ptrdiff_t) == sizeof(int)) + mod[0] = '\0'; + if (sizeof(ptrdiff_t) == sizeof(__int64)) { + mod[0] = 'I'; + mod[1] = '6'; + mod[2] = '4'; + mod[3] = '\0'; + } + } else if (mod[0] == 'j') { + if (sizeof(intmax_t) == sizeof(int)) + mod[0] = '\0'; + if (sizeof(intmax_t) == sizeof(__int64)) { + mod[0] = 'I'; + mod[1] = '6'; + mod[2] = '4'; + mod[3] = '\0'; + } + } + } +#endif snprintf(buf, len, "%%%s%s%s%s%s%s%s%s%c", occ->flag_space ? "#" : "", occ->flag_hash ? "#" : "", @@ -198,11 +231,9 @@ static int std_get_lc_arg_type(const lc_arg_occ_t *occ) case 'l': return modlen > 1 && mod[1] == 'l' ? lc_arg_type_long_long : lc_arg_type_long; #define TYPE_CASE(letter,type) case letter: return lc_arg_type_ ## type; -#if 0 TYPE_CASE('j', intmax_t); TYPE_CASE('z', size_t); TYPE_CASE('t', ptrdiff_t); -#endif TYPE_CASE('L', long_double); #undef TYPE_CASE } diff --git a/ir/libcore/lc_printf.h b/ir/libcore/lc_printf.h index c3d049781..0d48e73c1 100644 --- a/ir/libcore/lc_printf.h +++ b/ir/libcore/lc_printf.h @@ -25,12 +25,13 @@ * @date 3.1.2005 */ -#ifndef _LIBCORE_XPRINTF_H -#define _LIBCORE_XPRINTF_H +#ifndef _LIBCORE_LC_PRINTF_H +#define _LIBCORE_LC_PRINTF_H #include #include #include +#include #include diff --git a/ir/libcore/lc_printf_arg_types.def b/ir/libcore/lc_printf_arg_types.def index db9b383c8..254d3e944 100644 --- a/ir/libcore/lc_printf_arg_types.def +++ b/ir/libcore/lc_printf_arg_types.def @@ -4,3 +4,6 @@ LC_ARG_TYPE(LC_LONGLONG, long_long) LC_ARG_TYPE(double, double) LC_ARG_TYPE(LC_LONGDOUBLE, long_double) LC_ARG_TYPE(void *, ptr) +LC_ARG_TYPE(intmax_t, intmax_t) +LC_ARG_TYPE(ptrdiff_t, ptrdiff_t) +LC_ARG_TYPE(size_t, size_t)