From: E. Scott Daniels Date: Tue, 14 Jul 2020 17:38:27 +0000 (-0400) Subject: Fix json blob selection bug X-Git-Tag: 2.0.0~1 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=8ec1e3c2dec6ba4fa83fe63e4207d47b4b0f3b3f;p=ric-plt%2Fxapp-frame-cpp.git Fix json blob selection bug The first selection of a blob in the json was ok, but all subsequent selections failed. Issue-ID: RIC-596 Signed-off-by: E. Scott Daniels Change-Id: I8e7c4b731c15bc98654a8fb9bd052d43bd10adca --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ae759e..fc913fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ cmake_minimum_required( VERSION 3.5 ) set( major_version "1" ) # should be automatically populated from git tag later, but until CI process sets a tag we use this set( minor_version "2" ) -set( patch_level "0" ) +set( patch_level "1" ) set( install_root "${CMAKE_INSTALL_PREFIX}" ) set( install_inc "include/ricxfcpp" ) diff --git a/src/json/jhash.cpp b/src/json/jhash.cpp index 7f4a446..ad0bd9c 100644 --- a/src/json/jhash.cpp +++ b/src/json/jhash.cpp @@ -49,8 +49,32 @@ Jhash::Jhash( const char* jbuf ) : st( jw_new( jbuf ) ) { /* empty body */ } -//Jhash::Jhash( Jhash&& soi ); // mover -//Jhash::Jhash& operator=( Jhash&& soi ); // move operator + +/* + Move constructor. +*/ +Jhash::Jhash( Jhash&& soi ) { + master_st = soi.master_st; + st = soi.st; + + soi.st = NULL; // prevent closing of RMR stuff on soi destroy + soi.master_st = NULL; +} + +/* + Move Operator. +*/ +Jhash& Jhash::operator=( Jhash&& soi ) { + if( this != &soi ) { // cannot do self assignment + master_st = soi.master_st; + st = soi.st; + + soi.st = NULL; // prevent closing of RMR stuff on soi destroy + soi.master_st = NULL; + } + + return *this; +} /* Blow it away. @@ -86,7 +110,7 @@ bool Jhash::Set_blob( const char* name ) { void* bst; // blob symbol table if( master_st == NULL ) { // must capture master - master_st == st; + master_st = st; } if( (bst = jw_blob( st, name )) != NULL ) { @@ -104,11 +128,6 @@ void Jhash::Unset_blob( ) { if( master_st != NULL ) { st = master_st; } -/* - else { -fprintf( stderr, "bad unset pointer%p %p\n", master_st, st ); -} -*/ } // ---------------- debugging and sanity checks --------------------------------------- diff --git a/src/json/jhash.hpp b/src/json/jhash.hpp index 3ff6498..2963610 100644 --- a/src/json/jhash.hpp +++ b/src/json/jhash.hpp @@ -47,8 +47,8 @@ class Jhash { public: Jhash( const char* jblob ); // builder - //Jhash( Message&& soi ); // mover - //Jhash& operator=( Message&& soi ); // move operator + Jhash( Jhash&& soi ); // mover + Jhash& operator=( Jhash&& soi ); // move operator ~Jhash(); // destruction bool Set_blob( const char* name ); // blob/root selection diff --git a/test/jhash_test.cpp b/test/jhash_test.cpp index 58d283f..972e6e6 100644 --- a/test/jhash_test.cpp +++ b/test/jhash_test.cpp @@ -239,6 +239,11 @@ int main( int argc, char** argv ) { fprintf( stderr, " timestamp: %.10f\n", val ); + // ----- jhashes can be moved, drive that logic for coverage + Jhash j2( "{}" ); + + Jhash j1 = std::move( *jh ); // drives move constructor function + j2 = std::move( j1 ); // drives move operator function