Imported Upstream version 2.06
authorAlexandre Mestiashvili <alex@biotec.tu-dresden.de>
Wed, 19 Mar 2014 16:11:00 +0000 (17:11 +0100)
committerAlexandre Mestiashvili <alex@biotec.tu-dresden.de>
Wed, 19 Mar 2014 16:11:00 +0000 (17:11 +0100)
Changes
Encoder.xs
META.yml
Makefile.PL
lib/Sereal/Encoder.pm
srl_encoder.c
srl_encoder.h
t/130_freezethaw.t
t/400_evil.t

diff --git a/Changes b/Changes
index 929482d5f158c5eea3f32a805e19c0e5d5dfe56a..36386361a173db96d7c18c6660c9fa041f10642c 100644 (file)
--- 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)
 
index bb3b32f87c732da446d6eb95cf1d7d316ff7a7eb..91c1f1d00f0c9af830c535796b861759dba8f208 100644 (file)
@@ -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. */
index e6386eadd376105a3bc6ec6e8215ad2a945cd9c2..6a3c4b3e45366d78342a76542c01d38ad505cd31 100644 (file)
--- 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 <smueller@cpan.org>, Yves Orton <yves@cpan.org>
@@ -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
index 0c8aa9ebfeb88361f992c4c4faa8eb9b00d9b348..1eb1eb40bd1ae39d1a7411c04c6bd36c8646d827 100644 (file)
@@ -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
index 906007ab861cd608798b2aeac31de3fea693ba4b..4849100b878f2295de7d6b829e4c47678119a4ea 100644 (file)
@@ -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/_//;
index 7c549643e89a2585e64a72dd85420d9781507a3c..2069ecde86a83dd97478f008c11160280418b53a 100644 (file)
@@ -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
index 9fde69a2562bfacd664ccfaef64a75d62186b5a7..6f0bd0176e6a8457518e9f1e06edacaba1db1b9d 100644 (file)
@@ -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 */
index bc88d5a26721da9f8d127426c03457a371780d0e..e3bd9e9bdb94b1ea1e27504e938d39a58e2da591 100644 (file)
@@ -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);
index d2adf0549ebc6b508c1020e12f43986d4f1702f9..7560a465dce39cbc87fb05ecaf72105e0f9348a2 100644 (file)
@@ -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