diff --git a/perl/xs-src/pack.c b/perl/xs-src/pack.c index 862808eb..fe646f1d 100644 --- a/perl/xs-src/pack.c +++ b/perl/xs-src/pack.c @@ -47,7 +47,8 @@ STATIC_INLINE void need(enc_t* const enc, STRLEN const len); #define ERR_NESTING_EXCEEDED "perl structure exceeds maximum nesting level (max_depth set too low?)" -STATIC_INLINE void need(enc_t* const enc, STRLEN const len) +STATIC_INLINE +void need(enc_t* const enc, STRLEN const len) { if (enc->cur + len >= enc->end) { dTHX; @@ -61,7 +62,8 @@ STATIC_INLINE void need(enc_t* const enc, STRLEN const len) static int s_pref_int = 0; -STATIC_INLINE int pref_int_set(pTHX_ SV* sv, MAGIC* mg PERL_UNUSED_DECL) { +STATIC_INLINE +int pref_int_set(pTHX_ SV* sv, MAGIC* mg PERL_UNUSED_DECL) { if (SvTRUE(sv)) { s_pref_int = 1; } else { @@ -90,7 +92,8 @@ void init_Data__MessagePack_pack(pTHX_ bool const cloning) { } -STATIC_INLINE int try_int(enc_t* enc, const char *p, size_t len) { +STATIC_INLINE +int try_int(enc_t* enc, const char *p, size_t len) { int negative = 0; const char* pe = p + len; uint64_t num = 0; @@ -144,9 +147,11 @@ STATIC_INLINE int try_int(enc_t* enc, const char *p, size_t len) { } -STATIC_INLINE void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth); +STATIC_INLINE +void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth); -STATIC_INLINE void _msgpack_pack_sv(enc_t* const enc, SV* const sv, int const depth) { +STATIC_INLINE +void _msgpack_pack_sv(enc_t* const enc, SV* const sv, int const depth) { dTHX; assert(sv); if (UNLIKELY(depth <= 0)) Perl_croak(aTHX_ ERR_NESTING_EXCEEDED); @@ -185,12 +190,13 @@ STATIC_INLINE void _msgpack_pack_sv(enc_t* const enc, SV* const sv, int const de } } -STATIC_INLINE void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth) { - svtype svt; +STATIC_INLINE +void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth) { dTHX; + assert(sv); SvGETMAGIC(sv); - svt = SvTYPE(sv); + svtype const svt = SvTYPE(sv); if (SvOBJECT (sv)) { HV *stash = gv_stashpv ("Data::MessagePack::Boolean", 1); // TODO: cache? @@ -201,8 +207,8 @@ STATIC_INLINE void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth) { msgpack_pack_false(enc); } } else { - croak ("encountered object '%s', Data::MessagePack doesn't allow the object", - SvPV_nolen(sv_2mortal(newRV_inc(sv)))); + croak ("encountered object '%"SVf"', Data::MessagePack doesn't allow the object", + sv_2mortal(newRV_inc(sv))); } } else if (svt == SVt_PVHV) { HV* hval = (HV*)sv; @@ -238,12 +244,12 @@ STATIC_INLINE void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth) { msgpack_pack_false(enc); else { //sv_dump(sv); - croak("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", - SvPV_nolen (sv_2mortal (newRV_inc (sv)))); + croak("cannot encode reference to scalar '%"SVf"' unless the scalar is 0 or 1", + sv_2mortal(newRV_inc(sv))); } } else { - croak ("encountered %s, but msgpack can only represent references to arrays or hashes", - SvPV_nolen (sv_2mortal (newRV_inc (sv)))); + croak ("encountered %"SVf", but msgpack can only represent references to arrays or hashes", + sv_2mortal(newRV_inc(sv))); } } @@ -266,8 +272,10 @@ XS(xs_pack) { _msgpack_pack_sv(&enc, val, depth); SvCUR_set(enc.sv, enc.cur - SvPVX (enc.sv)); - *SvEND (enc.sv) = 0; /* many xs functions expect a trailing 0 for text strings */ + /* many C functions expect a trailing NUL for strings */ + *SvEND(enc.sv) = '\0'; ST(0) = enc.sv; XSRETURN(1); } + diff --git a/perl/xs-src/unpack.c b/perl/xs-src/unpack.c index e3f62c63..2294446e 100644 --- a/perl/xs-src/unpack.c +++ b/perl/xs-src/unpack.c @@ -101,21 +101,24 @@ static SV* template_data(msgpack_unpack_t* u); static int template_execute(msgpack_unpack_t* u PERL_UNUSED_DECL, const char* data, size_t len, size_t* off); -STATIC_INLINE SV* template_callback_root(unpack_user* u PERL_UNUSED_DECL) +STATIC_INLINE +SV* template_callback_root(unpack_user* u PERL_UNUSED_DECL) { return NULL; } #if IVSIZE == 4 -STATIC_INLINE int template_callback_UV(unpack_user* u PERL_UNUSED_DECL, UV const d, SV** o) +STATIC_INLINE +int template_callback_UV(unpack_user* u PERL_UNUSED_DECL, UV const d, SV** o) { dTHX; *o = newSVuv(d); return 0; } -STATIC_INLINE int template_callback_IV(unpack_user* u PERL_UNUSED_DECL, IV const d, SV** o) +STATIC_INLINE +int template_callback_IV(unpack_user* u PERL_UNUSED_DECL, IV const d, SV** o) { dTHX; *o = newSViv(d); @@ -123,7 +126,8 @@ STATIC_INLINE int template_callback_IV(unpack_user* u PERL_UNUSED_DECL, IV const } /* workaround win32 problems (my_snprintf(%llu) returns incorrect values ) */ -static char* str_from_uint64(char* buf_end, uint64_t v) +static +char* str_from_uint64(char* buf_end, uint64_t v) { char *p = buf_end; *--p = '\0'; @@ -133,7 +137,8 @@ static char* str_from_uint64(char* buf_end, uint64_t v) return p; } -static const char* str_from_int64(char* buf_end, int64_t const v) { +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) @@ -141,7 +146,8 @@ static const char* str_from_int64(char* buf_end, int64_t const v) { return p; } -static int template_callback_uint64(unpack_user* u PERL_UNUSED_DECL, uint64_t const d, SV** o) +static +int template_callback_uint64(unpack_user* u PERL_UNUSED_DECL, uint64_t const d, SV** o) { dTHX; char tbuf[64]; @@ -150,7 +156,8 @@ static int template_callback_uint64(unpack_user* u PERL_UNUSED_DECL, uint64_t co return 0; } -static int template_callback_int64(unpack_user* u PERL_UNUSED_DECL, int64_t const d, SV** o) +static +int template_callback_int64(unpack_user* u PERL_UNUSED_DECL, int64_t const d, SV** o) { dTHX; char tbuf[64]; @@ -162,7 +169,8 @@ static int template_callback_int64(unpack_user* u PERL_UNUSED_DECL, int64_t cons #else /* IVSIZE == 8 */ -STATIC_INLINE int template_callback_UV(unpack_user* u PERL_UNUSED_DECL, UV const d, SV** o) +STATIC_INLINE +int template_callback_UV(unpack_user* u PERL_UNUSED_DECL, UV const d, SV** o) { dTHX; *o = newSVuv(d); @@ -192,7 +200,8 @@ STATIC_INLINE int template_callback_IV(unpack_user* u PERL_UNUSED_DECL, IV const #define template_callback_float template_callback_double -STATIC_INLINE int template_callback_double(unpack_user* u PERL_UNUSED_DECL, double d, SV** o) +STATIC_INLINE +int template_callback_double(unpack_user* u PERL_UNUSED_DECL, double d, SV** o) { dTHX; *o = newSVnv(d); @@ -200,26 +209,30 @@ STATIC_INLINE int template_callback_double(unpack_user* u PERL_UNUSED_DECL, doub } /* &PL_sv_undef is not so good. see http://gist.github.com/387743 */ -STATIC_INLINE int template_callback_nil(unpack_user* u PERL_UNUSED_DECL, SV** o) +STATIC_INLINE +int template_callback_nil(unpack_user* u PERL_UNUSED_DECL, SV** o) { dTHX; *o = newSV(0); return 0; } -STATIC_INLINE int template_callback_true(unpack_user* u PERL_UNUSED_DECL, SV** o) +STATIC_INLINE +int template_callback_true(unpack_user* u PERL_UNUSED_DECL, SV** o) { *o = get_bool(true); return 0; } -STATIC_INLINE int template_callback_false(unpack_user* u PERL_UNUSED_DECL, SV** o) +STATIC_INLINE +int template_callback_false(unpack_user* u PERL_UNUSED_DECL, SV** o) { *o = get_bool(false); return 0; } -STATIC_INLINE int template_callback_array(unpack_user* u PERL_UNUSED_DECL, unsigned int n, SV** o) +STATIC_INLINE +int template_callback_array(unpack_user* u PERL_UNUSED_DECL, unsigned int n, SV** o) { dTHX; AV* const a = newAV(); @@ -228,7 +241,8 @@ STATIC_INLINE int template_callback_array(unpack_user* u PERL_UNUSED_DECL, unsig return 0; } -STATIC_INLINE int template_callback_array_item(unpack_user* u PERL_UNUSED_DECL, SV** c, SV* o) +STATIC_INLINE +int template_callback_array_item(unpack_user* u PERL_UNUSED_DECL, SV** c, SV* o) { dTHX; AV* const a = (AV*)SvRV(*c); @@ -237,7 +251,8 @@ STATIC_INLINE int template_callback_array_item(unpack_user* u PERL_UNUSED_DECL, return 0; } -STATIC_INLINE int template_callback_map(unpack_user* u PERL_UNUSED_DECL, unsigned int n, SV** o) +STATIC_INLINE +int template_callback_map(unpack_user* u PERL_UNUSED_DECL, unsigned int n, SV** o) { dTHX; HV* const h = newHV(); @@ -246,7 +261,8 @@ STATIC_INLINE int template_callback_map(unpack_user* u PERL_UNUSED_DECL, unsigne return 0; } -STATIC_INLINE int template_callback_map_item(unpack_user* u PERL_UNUSED_DECL, SV** c, SV* k, SV* v) +STATIC_INLINE +int template_callback_map_item(unpack_user* u PERL_UNUSED_DECL, SV** c, SV* k, SV* v) { dTHX; HV* const h = (HV*)SvRV(*c); @@ -256,7 +272,8 @@ STATIC_INLINE int template_callback_map_item(unpack_user* u PERL_UNUSED_DECL, SV return 0; } -STATIC_INLINE int template_callback_raw(unpack_user* u PERL_UNUSED_DECL, const char* b PERL_UNUSED_DECL, const char* p, unsigned int l, SV** o) +STATIC_INLINE int +template_callback_raw(unpack_user* u PERL_UNUSED_DECL, const char* b PERL_UNUSED_DECL, const char* p, unsigned int l, SV** o) { dTHX; /* newSVpvn(p, l) returns an undef if p == NULL */