From b0a43579277c2c66d0b755cf5d476a75c7e59707 Mon Sep 17 00:00:00 2001 From: Alexandre Mestiashvili Date: Wed, 19 Mar 2014 17:11:00 +0100 Subject: [PATCH] Imported Upstream version 2.06 --- Changes | 7 +++++++ Encoder.xs | 6 +++--- META.yml | 4 ++-- Makefile.PL | 2 +- lib/Sereal/Encoder.pm | 2 +- srl_encoder.c | 19 ++++++++++++++++--- srl_encoder.h | 11 ++++++++--- t/130_freezethaw.t | 8 +------- t/400_evil.t | 10 +--------- 9 files changed, 40 insertions(+), 29 deletions(-) diff --git a/Changes b/Changes index 929482d..3638636 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,13 @@ Revision history for Perl extension Sereal-Encoder * of the decoder before upgrading to version 2 of the * encoder! +2.06 Sun Mar 0 11:40 2014 (AMS time) + - Only minor changes. + +2.05 Fri Mar 7 10:30 2014 (AMS time) + - Fix rt.cpan.org #93560 - Encoder object wasn't re-entrant from + FREEZE calls. + 2.04 Wed Mar 5 18:15 2014 (AMS time) - Fix rt.cpan.org #93484 - fencepost error in Encoder.xs (Zefram) diff --git a/Encoder.xs b/Encoder.xs index bb3b32f..91c1f1d 100644 --- a/Encoder.xs +++ b/Encoder.xs @@ -44,7 +44,7 @@ encode(enc, src, ...) assert(enc != NULL); if (items > 2 && SvOK(ST(2))) hdr_user_data_src = ST(2); - srl_dump_data_structure(aTHX_ enc, src, hdr_user_data_src); + enc = srl_dump_data_structure(aTHX_ enc, src, hdr_user_data_src); assert(enc->buf.pos > enc->buf.start); /* We always copy the string since we might reuse the string buffer. That means * we already have to do a malloc and we might as well use the opportunity to @@ -61,7 +61,7 @@ encode_sereal(src, opt = NULL) PPCODE: enc = srl_build_encoder_struct(aTHX_ opt); assert(enc != NULL); - srl_dump_data_structure(aTHX_ enc, src, NULL); + enc = srl_dump_data_structure(aTHX_ enc, src, NULL); /* Avoid copy by stealing string buffer if it is not too large. * This makes sense in the functional interface since the string * buffer isn't ever going to be reused. */ @@ -94,7 +94,7 @@ encode_sereal_with_header_data(src, hdr_user_data_src, opt = NULL) hdr_user_data_src = NULL; enc = srl_build_encoder_struct(aTHX_ opt); assert(enc != NULL); - srl_dump_data_structure(aTHX_ enc, src, hdr_user_data_src); + enc = srl_dump_data_structure(aTHX_ enc, src, hdr_user_data_src); /* Avoid copy by stealing string buffer if it is not too large. * This makes sense in the functional interface since the string * buffer isn't ever going to be reused. */ diff --git a/META.yml b/META.yml index e6386ea..6a3c4b3 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: Sereal-Encoder -version: 2.04 +version: 2.06 abstract: Fast, compact, powerful binary serialization author: - Steffen Mueller , Yves Orton @@ -15,7 +15,7 @@ build_requires: File::Path: 0 File::Spec: 0 Scalar::Util: 0 - Sereal::Decoder: 2.03 + Sereal::Decoder: 2.06 Test::LongString: 0 Test::More: 0.88 Test::Warn: 0 diff --git a/Makefile.PL b/Makefile.PL index 0c8aa9e..1eb1eb4 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -67,7 +67,7 @@ WriteMakefile1( 'Test::LongString' => '0', 'Data::Dumper' => '0', 'Test::Warn' => '0', - 'Sereal::Decoder' => '2.03', + 'Sereal::Decoder' => '2.06', }, NAME => $module, VERSION_FROM => 'lib/Sereal/Encoder.pm', # finds $VERSION diff --git a/lib/Sereal/Encoder.pm b/lib/Sereal/Encoder.pm index 906007a..4849100 100644 --- a/lib/Sereal/Encoder.pm +++ b/lib/Sereal/Encoder.pm @@ -5,7 +5,7 @@ use warnings; use Carp qw/croak/; use XSLoader; -our $VERSION = '2.04'; # Don't forget to update the TestCompat set for testing against installed decoders! +our $VERSION = '2.06'; # Don't forget to update the TestCompat set for testing against installed decoders! # not for public consumption, just for testing. (my $num_version = $VERSION) =~ s/_//; diff --git a/srl_encoder.c b/srl_encoder.c index 7c54964..2069ecd 100644 --- a/srl_encoder.c +++ b/srl_encoder.c @@ -188,6 +188,7 @@ srl_clear_seen_hashes(pTHX_ srl_encoder_t *enc) void srl_clear_encoder(pTHX_ srl_encoder_t *enc) { + /* TODO I think this could just be made an assert. */ if (!SRL_ENC_HAVE_OPER_FLAG(enc, SRL_OF_ENCODER_DIRTY)) { warn("Sereal Encoder being cleared but in virgin state. That is unexpected."); } @@ -257,9 +258,10 @@ srl_empty_encoder_struct(pTHX) enc->weak_seenhash = NULL; enc->str_seenhash = NULL; enc->ref_seenhash = NULL; - enc->freezeobj_svhash = NULL; enc->snappy_workmem = NULL; enc->string_deduper_hv = NULL; + + enc->freezeobj_svhash = NULL; enc->sereal_string_sv = NULL; return enc; @@ -383,7 +385,15 @@ srl_build_encoder_struct_alike(pTHX_ srl_encoder_t *proto) { srl_encoder_t *enc; enc = srl_empty_encoder_struct(aTHX); + + /* Copy the configuration-type, non-ephemeral attributes */ enc->flags = proto->flags; + enc->max_recursion_depth = proto->max_recursion_depth; + enc->snappy_threshold = proto->snappy_threshold; + if (expect_false(SRL_ENC_HAVE_OPTION(enc, SRL_F_ENABLE_FREEZE_SUPPORT))) { + enc->sereal_string_sv = newSVpvs("Sereal"); + } + DEBUG_ASSERT_BUF_SANE(enc); return enc; } @@ -702,7 +712,9 @@ SRL_STATIC_INLINE srl_encoder_t * srl_prepare_encoder(pTHX_ srl_encoder_t *enc) { /* Check whether encoder is in use and create a new one on the - * fly if necessary. Should only happen in bizarre edge cases... hopefully. */ + * fly if necessary. Should only happen in edge cases such as + * FREEZE hooks that serialize things using the same encoder + * object. */ if (SRL_ENC_HAVE_OPER_FLAG(enc, SRL_OF_ENCODER_DIRTY)) { srl_encoder_t * const proto = enc; enc = srl_build_encoder_struct_alike(aTHX_ proto); @@ -759,7 +771,7 @@ srl_reset_snappy_header_flag(srl_encoder_t *enc) (*flags_and_version_byte & SRL_PROTOCOL_VERSION_MASK); } -void +srl_encoder_t * srl_dump_data_structure(pTHX_ srl_encoder_t *enc, SV *src, SV *user_header_src) { enc = srl_prepare_encoder(aTHX_ enc); @@ -847,6 +859,7 @@ srl_dump_data_structure(pTHX_ srl_encoder_t *enc, SV *src, SV *user_header_src) /* NOT doing a * SRL_ENC_RESET_OPER_FLAG(enc, SRL_OF_ENCODER_DIRTY); * here because we're relying on the SAVEDESTRUCTOR_X call. */ + return enc; } SRL_STATIC_INLINE void diff --git a/srl_encoder.h b/srl_encoder.h index 9fde69a..6f0bd01 100644 --- a/srl_encoder.h +++ b/srl_encoder.h @@ -32,8 +32,7 @@ typedef struct { void *snappy_workmem; /* lazily allocated if and only if using Snappy */ IV snappy_threshold; /* do not compress things smaller than this even if Snappy enabled */ - /*HV *freeze_cb_cache;*/ /* cache of callbacks for FREEZE methods: classname => CV*. - * only used if SRL_F_ENABLE_FREEZE_SUPPORT is set. */ + /* only used if SRL_F_ENABLE_FREEZE_SUPPORT is set. */ SV *sereal_string_sv; /* SV that says "Sereal" for FREEZE support */ } srl_encoder_t; @@ -50,7 +49,13 @@ void srl_destroy_encoder(pTHX_ srl_encoder_t *enc); /* Write Sereal packet header to output buffer */ void srl_write_header(pTHX_ srl_encoder_t *enc, SV *user_header_src); /* Start dumping a top-level SV */ -void srl_dump_data_structure(pTHX_ srl_encoder_t *enc, SV *src, SV *user_header_src); +/* Note: This returns an encoder struct pointer because it will + * clone the current encoder struct if it's dirty. That in + * turn means in order to access the output buffer, you need + * to inspect the returned encoder struct. If necessary, it + * will be cleaned up automatically by Perl, so don't bother + * freeing it. */ +srl_encoder_t *srl_dump_data_structure(pTHX_ srl_encoder_t *enc, SV *src, SV *user_header_src); /* define option bits in srl_encoder_t's flags member */ diff --git a/t/130_freezethaw.t b/t/130_freezethaw.t index bc88d5a..e3bd9e9 100644 --- a/t/130_freezethaw.t +++ b/t/130_freezethaw.t @@ -4,6 +4,7 @@ use warnings; # most be loaded before Sereal::TestSet use Sereal::Encoder qw(encode_sereal); use Sereal::Encoder::Constants qw(:all); +use Sereal::Decoder qw(:all); use File::Spec; use Test::More; use Data::Dumper; @@ -57,13 +58,6 @@ my $srl = $enc->encode(Foo->new()); ok($freeze_called, "FREEZE was invoked"); -my $run_decoder_tests = have_encoder_and_decoder(); -if (not $run_decoder_tests) { - done_testing(); - exit; -} - - # Simple round-trip test my $dec = Sereal::Decoder->new; my $obj = $dec->decode($srl); diff --git a/t/400_evil.t b/t/400_evil.t index d2adf05..7560a46 100644 --- a/t/400_evil.t +++ b/t/400_evil.t @@ -2,6 +2,7 @@ use strict; use warnings; use Sereal::Encoder qw(:all); +use Sereal::Decoder qw(:all); use Data::Dumper; use File::Spec; use Scalar::Util qw(blessed); @@ -18,15 +19,6 @@ BEGIN { use Sereal::TestSet qw(:all); use Test::More; -if (not have_encoder_and_decoder()) { - plan skip_all => 'Did not find right version of decoder'; -} -else { - require Sereal::Decoder; - Sereal::Decoder->import(":all"); -} - - # First, test tied hashes. Expected behaviour: We don't segfault, we don't # throw exceptions (unless the tied hash is not iterable repeatedly), # we serialize the tied hash as if it was a normal hash - so no trace of -- 2.30.2