From 92b346efa79fc66eeeed64cf833ef654abe1de21 Mon Sep 17 00:00:00 2001 From: "Fuji, Goro" Date: Thu, 21 Oct 2010 23:26:03 +0900 Subject: [PATCH] perl: clean up --- perl/xs-src/unpack.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/perl/xs-src/unpack.c b/perl/xs-src/unpack.c index 60ffd87a..db7e3949 100644 --- a/perl/xs-src/unpack.c +++ b/perl/xs-src/unpack.c @@ -1,6 +1,5 @@ #define NEED_newRV_noinc #define NEED_sv_2pv_flags -#define NEED_my_snprintf #include "xshelper.h" #define MY_CXT_KEY "Data::MessagePack::_unpack_guts" XS_VERSION @@ -121,7 +120,8 @@ STATIC_INLINE int template_callback_IV(unpack_user* u PERL_UNUSED_DECL, IV const return 0; } -static const char* str_from_uint64(char* buf_end, uint64_t v) +/* workaround win32 problems (my_snprintf(%llu) returns incorrect values ) */ +static char* str_from_uint64(char* buf_end, uint64_t v) { char *p = buf_end; *--p = '\0'; @@ -131,9 +131,8 @@ static const char* str_from_uint64(char* buf_end, uint64_t v) return p; } -static const char* str_from_int64(char* buf_end, int64_t v) -{ - int minus = v < 0; +static const char* str_from_int64(char* buf_end, int64_t const v) { + bool const minus = v < 0; char* p = str_from_uint64(buf_end, minus ? -v : v); if (minus) *--p = '-'; @@ -144,13 +143,8 @@ static int template_callback_uint64(unpack_user* u PERL_UNUSED_DECL, uint64_t co { dTHX; char tbuf[64]; -#if 1 /* workaround for win32-32bit (my_snprintf(%llu) returns are incorrect) */ - char* s = str_from_uint64(tbuf + sizeof(tbuf), d); + const char* const s = str_from_uint64(tbuf + sizeof(tbuf), d); *o = newSVpvn(s, tbuf + sizeof(tbuf) - 1 - s); -#else - STRLEN const len = my_snprintf(tbuf, sizeof(tbuf), "%llu", d); - *o = newSVpvn(tbuf, len); -#endif return 0; } @@ -158,13 +152,8 @@ static int template_callback_int64(unpack_user* u PERL_UNUSED_DECL, int64_t cons { dTHX; char tbuf[64]; -#if 1 /* workaround for win32-32bit (my_snprintf(%lld) returns are incorrect) */ - char* s = str_from_int64(tbuf + sizeof(tbuf), d); + const char* const s = str_from_int64(tbuf + sizeof(tbuf), d); *o = newSVpvn(s, tbuf + sizeof(tbuf) - 1 - s); -#else - STRLEN const len = my_snprintf(tbuf, sizeof(tbuf), "%lld", d); - *o = newSVpvn(tbuf, len); -#endif return 0; }