mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 13:02:13 +01:00
oops. 0.21 breakes ithreads support!
This commit is contained in:
parent
1e6262f24f
commit
a41f7ce3bd
1
perl/.gitignore
vendored
1
perl/.gitignore
vendored
@ -12,3 +12,4 @@ unpack.o
|
||||
MANIFEST
|
||||
ppport.h
|
||||
.testenv/
|
||||
xshelper.h
|
||||
|
@ -18,7 +18,7 @@ if ( $] >= 5.008005 and want_xs() ) {
|
||||
my $has_c99 = c99_available(); # msgpack C library requires C99.
|
||||
|
||||
if ( $has_c99 ) {
|
||||
use_ppport 3.19;
|
||||
use_xshelper();
|
||||
cc_src_paths('xs-src');
|
||||
if ($ENV{DEBUG}) {
|
||||
cc_append_to_ccflags '-g';
|
||||
|
@ -2,7 +2,7 @@
|
||||
* code is written by tokuhirom.
|
||||
* buffer alocation technique is taken from JSON::XS. thanks to mlehmann.
|
||||
*/
|
||||
#include "perlxs.h"
|
||||
#include "xshelper.h"
|
||||
|
||||
#include "msgpack/pack_define.h"
|
||||
|
||||
@ -45,6 +45,7 @@ static void need(enc_t *enc, STRLEN len);
|
||||
|
||||
STATIC_INLINE void need(enc_t *enc, STRLEN len)
|
||||
{
|
||||
dTHX;
|
||||
if (enc->cur + len >= enc->end) {
|
||||
STRLEN cur = enc->cur - (char *)SvPVX (enc->sv);
|
||||
SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1);
|
||||
@ -79,6 +80,7 @@ MGVTBL pref_int_vtbl = {
|
||||
};
|
||||
|
||||
void boot_Data__MessagePack_pack(void) {
|
||||
dTHX;
|
||||
SV* var = get_sv("Data::MessagePack::PreferInteger", 0);
|
||||
sv_magicext(var, NULL, PERL_MAGIC_ext, &pref_int_vtbl, NULL, 0);
|
||||
SvSETMAGIC(var);
|
||||
@ -142,6 +144,7 @@ STATIC_INLINE int try_int(enc_t* enc, const char *p, size_t len) {
|
||||
static void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth);
|
||||
|
||||
STATIC_INLINE void _msgpack_pack_sv(enc_t *enc, SV* sv, int depth) {
|
||||
dTHX;
|
||||
if (depth <= 0) Perl_croak(aTHX_ ERR_NESTING_EXCEEDED);
|
||||
SvGETMAGIC(sv);
|
||||
|
||||
@ -178,6 +181,7 @@ STATIC_INLINE void _msgpack_pack_sv(enc_t *enc, SV* sv, int depth) {
|
||||
|
||||
STATIC_INLINE void _msgpack_pack_rv(enc_t *enc, SV* sv, int depth) {
|
||||
svtype svt;
|
||||
dTHX;
|
||||
if (depth <= 0) Perl_croak(aTHX_ ERR_NESTING_EXCEEDED);
|
||||
SvGETMAGIC(sv);
|
||||
svt = SvTYPE(sv);
|
||||
|
@ -4,7 +4,7 @@ extern "C" {
|
||||
|
||||
#define NEED_newRV_noinc
|
||||
#define NEED_sv_2pv_flags
|
||||
#include "perlxs.h"
|
||||
#include "xshelper.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
@ -36,6 +36,7 @@ typedef struct {
|
||||
|
||||
STATIC_INLINE SV *
|
||||
get_bool (const char *name) {
|
||||
dTHX;
|
||||
SV * sv = sv_mortalcopy(get_sv( name, 1 ));
|
||||
|
||||
SvREADONLY_on(sv);
|
||||
@ -57,19 +58,20 @@ static int template_execute(msgpack_unpack_t* u,
|
||||
const char* data, size_t len, size_t* off);
|
||||
|
||||
STATIC_INLINE SV* template_callback_root(unpack_user* u)
|
||||
{ return &PL_sv_undef; }
|
||||
{ dTHX; return &PL_sv_undef; }
|
||||
|
||||
STATIC_INLINE int template_callback_uint8(unpack_user* u, uint8_t d, SV** o)
|
||||
{ *o = sv_2mortal(newSVuv(d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSVuv(d)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_uint16(unpack_user* u, uint16_t d, SV** o)
|
||||
{ *o = sv_2mortal(newSVuv(d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSVuv(d)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_uint32(unpack_user* u, uint32_t d, SV** o)
|
||||
{ *o = sv_2mortal(newSVuv(d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSVuv(d)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_uint64(unpack_user* u, uint64_t d, SV** o)
|
||||
{
|
||||
dTHX;
|
||||
#if IVSIZE==4
|
||||
*o = sv_2mortal(newSVnv(d));
|
||||
#else
|
||||
@ -79,47 +81,47 @@ STATIC_INLINE int template_callback_uint64(unpack_user* u, uint64_t d, SV** o)
|
||||
}
|
||||
|
||||
STATIC_INLINE int template_callback_int8(unpack_user* u, int8_t d, SV** o)
|
||||
{ *o = sv_2mortal(newSViv((long)d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSViv((long)d)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_int16(unpack_user* u, int16_t d, SV** o)
|
||||
{ *o = sv_2mortal(newSViv((long)d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSViv((long)d)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_int32(unpack_user* u, int32_t d, SV** o)
|
||||
{ *o = sv_2mortal(newSViv((long)d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSViv((long)d)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_int64(unpack_user* u, int64_t d, SV** o)
|
||||
{ *o = sv_2mortal(newSViv(d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSViv(d)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_float(unpack_user* u, float d, SV** o)
|
||||
{ *o = sv_2mortal(newSVnv(d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSVnv(d)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_double(unpack_user* u, double d, SV** o)
|
||||
{ *o = sv_2mortal(newSVnv(d)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal(newSVnv(d)); return 0; }
|
||||
|
||||
/* &PL_sv_undef is not so good. see http://gist.github.com/387743 */
|
||||
STATIC_INLINE int template_callback_nil(unpack_user* u, SV** o)
|
||||
{ *o = sv_newmortal(); return 0; }
|
||||
{ dTHX; *o = sv_newmortal(); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_true(unpack_user* u, SV** o)
|
||||
{ *o = get_bool("Data::MessagePack::true") ; return 0; }
|
||||
{ dTHX; *o = get_bool("Data::MessagePack::true") ; return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_false(unpack_user* u, SV** o)
|
||||
{ *o = get_bool("Data::MessagePack::false") ; return 0; }
|
||||
{ dTHX; *o = get_bool("Data::MessagePack::false") ; return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_array(unpack_user* u, unsigned int n, SV** o)
|
||||
{ AV* a = (AV*)sv_2mortal((SV*)newAV()); *o = sv_2mortal((SV*)newRV_inc((SV*)a)); av_extend(a, n); return 0; }
|
||||
{ dTHX; AV* a = (AV*)sv_2mortal((SV*)newAV()); *o = sv_2mortal((SV*)newRV_inc((SV*)a)); av_extend(a, n); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_array_item(unpack_user* u, SV** c, SV* o)
|
||||
{ av_push((AV*)SvRV(*c), o); SvREFCNT_inc(o); return 0; } /* FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++] */
|
||||
{ dTHX; av_push((AV*)SvRV(*c), o); SvREFCNT_inc(o); return 0; } /* FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++] */
|
||||
|
||||
STATIC_INLINE int template_callback_map(unpack_user* u, unsigned int n, SV** o)
|
||||
{ HV * h = (HV*)sv_2mortal((SV*)newHV()); *o = sv_2mortal(newRV_inc((SV*)h)); return 0; }
|
||||
{ dTHX; HV * h = (HV*)sv_2mortal((SV*)newHV()); *o = sv_2mortal(newRV_inc((SV*)h)); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_map_item(unpack_user* u, SV** c, SV* k, SV* v)
|
||||
{ hv_store_ent((HV*)SvRV(*c), k, v, 0); SvREFCNT_inc(v); return 0; }
|
||||
{ dTHX; hv_store_ent((HV*)SvRV(*c), k, v, 0); SvREFCNT_inc(v); return 0; }
|
||||
|
||||
STATIC_INLINE int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, SV** o)
|
||||
{ *o = sv_2mortal((l==0) ? newSVpv("", 0) : newSVpv(p, l)); return 0; }
|
||||
{ dTHX; *o = sv_2mortal((l==0) ? newSVpv("", 0) : newSVpv(p, l)); return 0; }
|
||||
/* { *o = newSVpvn_flags(p, l, SVs_TEMP); return 0; } <= this does not works. */
|
||||
|
||||
#define UNPACKER(from, name) \
|
||||
@ -133,6 +135,7 @@ STATIC_INLINE int template_callback_raw(unpack_user* u, const char* b, const cha
|
||||
|
||||
STATIC_INLINE SV* _msgpack_unpack(SV* data, int limit) {
|
||||
msgpack_unpack_t mp;
|
||||
dTHX;
|
||||
unpack_user u = {0, &PL_sv_undef};
|
||||
int ret;
|
||||
size_t from = 0;
|
||||
@ -195,6 +198,7 @@ XS(xs_unpack) {
|
||||
/* http://twitter.com/frsyuki/status/13249304748 */
|
||||
|
||||
STATIC_INLINE void _reset(SV* self) {
|
||||
dTHX;
|
||||
unpack_user u = {0, &PL_sv_undef, 0};
|
||||
|
||||
UNPACKER(self, mp);
|
||||
@ -221,6 +225,7 @@ XS(xs_unpacker_new) {
|
||||
}
|
||||
|
||||
STATIC_INLINE SV* _execute_impl(SV* self, SV* data, UV off, I32 limit) {
|
||||
dTHX;
|
||||
UNPACKER(self, mp);
|
||||
|
||||
size_t from = off;
|
||||
|
Loading…
x
Reference in New Issue
Block a user