Merge remote-tracking branch 'origin/topic/johanna/remove-serializer'

* origin/topic/johanna/remove-serializer:
  Fix memory leak introduced by removing opaque of ocsp_resp.
  Change return value of OpaqueVal::DoSerialize.
  Add missing ShallowClone implementation for SetType
  Remove opaque of ocsp_resp.
  Remove remnants of event serializer.
  Fix cardinalitycounter deserialization.
  Smaller compile fixes for the new opaque serialization.
  Reimplement serialization infrastructure for OpaqueVals.
  Couple of compile fixes.
  Remove const from ShallowClone.
  Remove test-case for removed functionality
  Implement a Shallow Clone operation for types.
  Remove value serialization.

Various changes I made:

- Fix memory leak in type-checker for opaque vals wrapped in broker::data

- Noticed the two "copy-all" leak tests weren't actually checking for
  memory leaks because the heap checker isn't active until after zeek_init()
  is evaluated.

- Change OpaqueVal::DoClone to use the clone caching mechanism

- Improve copy elision for broker::expected return types in the various
  OpaqueVal serialize methods

  - Not all compilers end up properly treating the return of
    local/automatic variable as an rvalue that can be moved, and ends up
    copying it instead.

  - Particularly, until GCC 8, this pattern ends up copying instead of
    moving, and we still support platforms whose default compiler
    pre-dates that version.

  - Generally seems it's something that wasn't addressed until C++14.
    See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1579

- Change OpaqueVal::SerializeType to return broker::expected

- Change probabilistic DoSerialize methods to return broker::expected
This commit is contained in:
Jon Siwek 2019-06-20 13:23:22 -07:00
commit 399496efa8
102 changed files with 1574 additions and 9140 deletions

View file

@ -6,7 +6,6 @@
#include "CardinalityCounter.h"
#include "Reporter.h"
#include "Serializer.h"
using namespace probabilistic;
@ -197,49 +196,48 @@ uint64_t CardinalityCounter::GetM() const
return m;
}
bool CardinalityCounter::Serialize(SerialInfo* info) const
broker::expected<broker::data> CardinalityCounter::Serialize() const
{
bool valid = true;
broker::vector v = {m, V, alpha_m};
v.reserve(3 + m);
valid &= SERIALIZE(m);
valid &= SERIALIZE(V);
valid &= SERIALIZE(alpha_m);
for ( size_t i = 0; i < m; ++i )
v.emplace_back(static_cast<uint64>(buckets[i]));
for ( unsigned int i = 0; i < m; i++ )
valid &= SERIALIZE((char)buckets[i]);
return valid;
return {std::move(v)};
}
CardinalityCounter* CardinalityCounter::Unserialize(UnserialInfo* info)
std::unique_ptr<CardinalityCounter> CardinalityCounter::Unserialize(const broker::data& data)
{
uint64_t m;
uint64_t V;
double alpha_m;
auto v = caf::get_if<broker::vector>(&data);
if ( ! (v && v->size() >= 3) )
return nullptr;
bool valid = true;
valid &= UNSERIALIZE(&m);
valid &= UNSERIALIZE(&V);
valid &= UNSERIALIZE(&alpha_m);
auto m = caf::get_if<uint64>(&(*v)[0]);
auto V = caf::get_if<uint64>(&(*v)[1]);
auto alpha_m = caf::get_if<double>(&(*v)[2]);
CardinalityCounter* c = new CardinalityCounter(m, V, alpha_m);
if ( ! (m && V && alpha_m) )
return nullptr;
if ( v->size() != 3 + *m )
return nullptr;
vector<uint8_t>& buckets = c->buckets;
auto cc = std::unique_ptr<CardinalityCounter>(new CardinalityCounter(*m, *V, *alpha_m));
if ( *m != cc->m )
return nullptr;
if ( cc->buckets.size() != * m )
return nullptr;
for ( unsigned int i = 0; i < m; i++ )
for ( size_t i = 0; i < *m; ++i )
{
char c;
valid &= UNSERIALIZE(&c);
buckets[i] = (uint8_t)c;
auto x = caf::get_if<uint64>(&(*v)[3 + i]);
if ( ! x )
return nullptr;
cc->buckets[i] = *x;
}
if ( ! valid )
{
delete c;
c = 0;
}
return c;
return cc;
}
/**