Revert "Revert "perl: cleanup""

This reverts commit a7a23d3bc8bb7a5c156becb3b8a43e296986f42e.
This commit is contained in:
Fuji, Goro 2010-10-28 16:17:53 +09:00
parent a7a23d3bc8
commit bc8d8ab65a
2 changed files with 57 additions and 32 deletions

View File

@ -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?)" #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) { if (enc->cur + len >= enc->end) {
dTHX; dTHX;
@ -61,7 +62,8 @@ STATIC_INLINE void need(enc_t* const enc, STRLEN const len)
static int s_pref_int = 0; 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)) { if (SvTRUE(sv)) {
s_pref_int = 1; s_pref_int = 1;
} else { } 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; int negative = 0;
const char* pe = p + len; const char* pe = p + len;
uint64_t num = 0; 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; dTHX;
assert(sv); assert(sv);
if (UNLIKELY(depth <= 0)) Perl_croak(aTHX_ ERR_NESTING_EXCEEDED); 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) { STATIC_INLINE
svtype svt; void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth) {
dTHX; dTHX;
assert(sv); assert(sv);
SvGETMAGIC(sv); SvGETMAGIC(sv);
svt = SvTYPE(sv); svtype const svt = SvTYPE(sv);
if (SvOBJECT (sv)) { if (SvOBJECT (sv)) {
HV *stash = gv_stashpv ("Data::MessagePack::Boolean", 1); // TODO: cache? 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); msgpack_pack_false(enc);
} }
} else { } else {
croak ("encountered object '%s', Data::MessagePack doesn't allow the object", croak ("encountered object '%"SVf"', Data::MessagePack doesn't allow the object",
SvPV_nolen(sv_2mortal(newRV_inc(sv)))); sv_2mortal(newRV_inc(sv)));
} }
} else if (svt == SVt_PVHV) { } else if (svt == SVt_PVHV) {
HV* hval = (HV*)sv; 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); msgpack_pack_false(enc);
else { else {
//sv_dump(sv); //sv_dump(sv);
croak("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", croak("cannot encode reference to scalar '%"SVf"' unless the scalar is 0 or 1",
SvPV_nolen (sv_2mortal (newRV_inc (sv)))); sv_2mortal(newRV_inc(sv)));
} }
} else { } else {
croak ("encountered %s, but msgpack can only represent references to arrays or hashes", croak ("encountered %"SVf", but msgpack can only represent references to arrays or hashes",
SvPV_nolen (sv_2mortal (newRV_inc (sv)))); sv_2mortal(newRV_inc(sv)));
} }
} }
@ -266,8 +272,10 @@ XS(xs_pack) {
_msgpack_pack_sv(&enc, val, depth); _msgpack_pack_sv(&enc, val, depth);
SvCUR_set(enc.sv, enc.cur - SvPVX (enc.sv)); 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; ST(0) = enc.sv;
XSRETURN(1); XSRETURN(1);
} }

View File

@ -101,21 +101,24 @@ static SV* template_data(msgpack_unpack_t* u);
static int template_execute(msgpack_unpack_t* u PERL_UNUSED_DECL, static int template_execute(msgpack_unpack_t* u PERL_UNUSED_DECL,
const char* data, size_t len, size_t* off); 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; return NULL;
} }
#if IVSIZE == 4 #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; dTHX;
*o = newSVuv(d); *o = newSVuv(d);
return 0; 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; dTHX;
*o = newSViv(d); *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 ) */ /* 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; char *p = buf_end;
*--p = '\0'; *--p = '\0';
@ -133,7 +137,8 @@ static char* str_from_uint64(char* buf_end, uint64_t v)
return p; 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; bool const minus = v < 0;
char* p = str_from_uint64(buf_end, minus ? -v : v); char* p = str_from_uint64(buf_end, minus ? -v : v);
if (minus) if (minus)
@ -141,7 +146,8 @@ static const char* str_from_int64(char* buf_end, int64_t const v) {
return p; 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; dTHX;
char tbuf[64]; char tbuf[64];
@ -150,7 +156,8 @@ static int template_callback_uint64(unpack_user* u PERL_UNUSED_DECL, uint64_t co
return 0; 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; dTHX;
char tbuf[64]; char tbuf[64];
@ -162,7 +169,8 @@ static int template_callback_int64(unpack_user* u PERL_UNUSED_DECL, int64_t cons
#else /* IVSIZE == 8 */ #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; dTHX;
*o = newSVuv(d); *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 #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; dTHX;
*o = newSVnv(d); *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 */ /* &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; dTHX;
*o = newSV(0); *o = newSV(0);
return 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); *o = get_bool(true);
return 0; 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); *o = get_bool(false);
return 0; 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; dTHX;
AV* const a = newAV(); AV* const a = newAV();
@ -228,7 +241,8 @@ STATIC_INLINE int template_callback_array(unpack_user* u PERL_UNUSED_DECL, unsig
return 0; 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; dTHX;
AV* const a = (AV*)SvRV(*c); 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; 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; dTHX;
HV* const h = newHV(); HV* const h = newHV();
@ -246,7 +261,8 @@ STATIC_INLINE int template_callback_map(unpack_user* u PERL_UNUSED_DECL, unsigne
return 0; 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; dTHX;
HV* const h = (HV*)SvRV(*c); 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; 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; dTHX;
/* newSVpvn(p, l) returns an undef if p == NULL */ /* newSVpvn(p, l) returns an undef if p == NULL */