From 368b88d2e70eaca680ecd94ca8bf099e8361ecd1 Mon Sep 17 00:00:00 2001 From: Denis Barbier Date: Thu, 5 Dec 2024 10:32:15 +0100 Subject: [PATCH] Allow compatibility in serialization When HMAT_READ_NRCHILD_CHAR environment variable is set, files are read using old format. We always write in new format though in order to ensure that we can get rid of this compatibility layer in a near future. --- src/serialization.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/serialization.cpp b/src/serialization.cpp index 07f2e3c8..f921ef70 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -21,11 +21,13 @@ */ #include "serialization.hpp" -#include #include "compression.hpp" #include "rk_matrix.hpp" #include "common/my_assert.h" +#include +#include + namespace hmat { // TODO decide what to todo with read/write return value @@ -205,7 +207,14 @@ template TR * MatrixStructUnmarshaller::readTree(TR * tree) { tree = readTreeNode(tree); if(tree != NULL) { tree->depth = depth; - int nrChild = readValue(); + // Number of children was initially written as a char, and now as an int. + // When environment variable HMAT_READ_NRCHILD_CHAR is set, read_nrchild_char + // is set to 1 and number of children is read as a char. + static int read_nrchild_char = -1; + if (read_nrchild_char == -1) { + read_nrchild_char = getenv("HMAT_READ_NRCHILD_CHAR") != nullptr; + } + int nrChild = read_nrchild_char == 0 ? readValue() : readValue(); for(int i = 0; i < nrChild; i++) { tree->insertChild(i, readTree(tree)); }