Fix json blob selection bug 87/4387/1
authorE. Scott Daniels <daniels@research.att.com>
Tue, 14 Jul 2020 17:38:27 +0000 (13:38 -0400)
committerE. Scott Daniels <daniels@research.att.com>
Tue, 14 Jul 2020 17:38:27 +0000 (13:38 -0400)
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 <daniels@research.att.com>
Change-Id: I8e7c4b731c15bc98654a8fb9bd052d43bd10adca

CMakeLists.txt
src/json/jhash.cpp
src/json/jhash.hpp
test/jhash_test.cpp

index 9ae759e..fc913fa 100644 (file)
@@ -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" )
index 7f4a446..ad0bd9c 100644 (file)
@@ -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 ---------------------------------------
index 3ff6498..2963610 100644 (file)
@@ -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
index 58d283f..972e6e6 100644 (file)
@@ -239,6 +239,11 @@ int main( int argc, char** argv ) {
        fprintf( stderr, "<INFO> 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