* 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)
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
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. */
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. */
--- #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>
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
'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
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/_//;
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.");
}
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;
{
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;
}
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);
(*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);
/* 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
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;
/* 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 */
# 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;
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);
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);
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