From e52b2ff37a5bcc9a44462baf07720f6e9786bfc8 Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Tue, 31 Oct 2023 15:01:35 -0400 Subject: [PATCH 01/16] Fix: dir /full segfault #2646 This bug was introduced when alternate compression methods were added commit 9829bf64dd7f3b9158f4d98172594fc523e4b746 That code allocated the NCI byte `spare2` to hold the index of the compression method. It assumed that if it was not filled in it would be zero. This turned out not to be the case for some nodes in some trees. This PR adds a DBI that says wether or not to look at this byte. The ** the default value of this DBI is ignore the compression method byte. ** To enable alternate compression methods, which have been seldom used (never?) set the DBI DbiADVANCED_COMPRESSION to true. - open the tree for edit - call TreeSetDbi with DbiADVANCED_COMPRESSION set to 1 - write the tree There will be TCL verbs to set and get this database attribute. The database characteristics (DBI) have been initialized to zero since https://github.com/MDSplus/mdsplus/blame/263cc8bce631b291f17ae2c3e09164c55a067b93/treeshr/TreeOpen.c#L659 Example that sets the flag: ``` int main() { int status; int length; int one = 1; DBI_ITM cmp_itm[2]; const char *tree = "test"; const int shot = 42; cmp_itm[0].buffer_length=1; cmp_itm[0].code = DbiADVANCED_COMPRESSION; cmp_itm[0].pointer = (void *)&zero; cmp_itm[0].return_length_address = &length; cmp_itm[1].code = DbiEND_OF_LIST; status = TreeOpenEdit(tree, shot); if (!(status & 1)) { printf("open - status = %d\n", status); exit(1); } status = TreeSetDbi(cmp_itm); if (!(status & 1)) { printf("SetDBI - status = %d\n", status); exit(1); } status = TreeWriteTree("nb", 196500); if (!(status & 1)) { printf("Write - status = %d\n", status); exit(1); } } ``` --- include/dbidef.h | 33 +++++++++++++++------------------ treeshr/TreeGetDbi.c | 8 +++++++- treeshr/TreeGetNci.c | 7 ++++++- treeshr/TreeSetDbi.c | 7 +++++++ treeshr/treeshrp.h | 13 +++---------- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/include/dbidef.h b/include/dbidef.h index ecf0cecf39..d220081d08 100644 --- a/include/dbidef.h +++ b/include/dbidef.h @@ -9,24 +9,21 @@ Item list codes for TreeGetDbi **********************************/ -#define DbiEND_OF_LIST 0 /* End of list */ -#define DbiNAME 1 /* Experiment name used for open - text string */ -#define DbiSHOTID 2 /* Shot identification - longword */ -#define DbiMODIFIED \ - 3 /* True if tree has been modified during edit - boolean \ - */ -#define DbiOPEN_FOR_EDIT 4 /* True if tree is open for edit - boolean */ -#define DbiINDEX \ - 5 /* Index of tree to use for subsequent information requests */ -#define DbiNUMBER_OPENED 6 /* Number of trees currently open */ -#define DbiMAX_OPEN 7 /* Maximum number of tree allowed open at one time */ -#define DbiDEFAULT 8 /* NID of default node */ -#define DbiOPEN_READONLY 9 /* True if tree has been opened readonly */ -#define DbiVERSIONS_IN_MODEL 10 /* True if using versioning in model */ -#define DbiVERSIONS_IN_PULSE 11 /* True if using versioning in pulse files */ -#define DbiREADONLY 12 /* True if making tree readonly */ -#define DbiDISPATCH_TABLE 13 /* Tree dispatch table */ - +#define DbiEND_OF_LIST 0 /* End of list */ +#define DbiNAME 1 /* Experiment name used for open - text string */ +#define DbiSHOTID 2 /* Shot identification - longword */ +#define DbiMODIFIED 3 /* True if tree has been modified during edit - boolean */ +#define DbiOPEN_FOR_EDIT 4 /* True if tree is open for edit - boolean */ +#define DbiINDEX 5 /* Index of tree to use for subsequent information requests */ +#define DbiNUMBER_OPENED 6 /* Number of trees currently open */ +#define DbiMAX_OPEN 7 /* Maximum number of tree allowed open at one time */ +#define DbiDEFAULT 8 /* NID of default node */ +#define DbiOPEN_READONLY 9 /* True if tree has been opened readonly */ +#define DbiVERSIONS_IN_MODEL 10 /* True if using versioning in model */ +#define DbiVERSIONS_IN_PULSE 11 /* True if using versioning in pulse files */ +#define DbiREADONLY 12 /* True if making tree readonly */ +#define DbiDISPATCH_TABLE 13 /* Tree dispatch table */ +#define DbiADVANCED_COMPRESSION 14 /* Set to true to enable extended compression methods */ typedef struct dbi_itm { short int buffer_length; diff --git a/treeshr/TreeGetDbi.c b/treeshr/TreeGetDbi.c index 506ecb509a..b74dd7e57d 100644 --- a/treeshr/TreeGetDbi.c +++ b/treeshr/TreeGetDbi.c @@ -52,7 +52,7 @@ int TreeGetDbi(struct dbi_itm *itmlst) } #define set_ret_char(val) \ memset(lst->pointer, 0, (size_t)lst->buffer_length); \ - *((char *)lst->pointer) = val + *((char *)lst->pointer) = val; int _TreeGetDbi(void *dbid, struct dbi_itm *itmlst) { @@ -96,6 +96,12 @@ int _TreeGetDbi(void *dbid, struct dbi_itm *itmlst) set_ret_char(db->open_readonly); break; + case DbiADVANCED_COMPRESSION: + + CheckOpen(db); + set_ret_char(db->advanced_compression); + break; + case DbiINDEX: { diff --git a/treeshr/TreeGetNci.c b/treeshr/TreeGetNci.c index fb67e75834..75ff141d34 100644 --- a/treeshr/TreeGetNci.c +++ b/treeshr/TreeGetNci.c @@ -290,7 +290,11 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) break_on_no_node; read_nci; set_retlen(sizeof(nci.compression_method)); - *(unsigned char *)itm->pointer = nci.compression_method; + if (dblist->tree_info->header->advanced_compression) { + *(unsigned char *)itm->pointer = nci.compression_method; + } else { + *(unsigned char *)itm->pointer = 0; + } break; case NciCLASS: break_on_no_node; @@ -697,6 +701,7 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) { break_on_no_node; read_nci; + if (! dblist->tree_info->header->advanced_compression) nci.compression_method = 0; if (nci.compression_method >= NUM_COMPRESSION_METHODS) nci.compression_method = 0; string = strdup(compression_methods[nci.compression_method].name); diff --git a/treeshr/TreeSetDbi.c b/treeshr/TreeSetDbi.c index 2a3deca3de..ca9536433b 100644 --- a/treeshr/TreeSetDbi.c +++ b/treeshr/TreeSetDbi.c @@ -111,6 +111,13 @@ int _TreeSetDbi(void *dbid, DBI_ITM *dbi_itm_ptr) (*(unsigned int *)itm_ptr->pointer) != 0; dblist->modified = 1; break; + case DbiADVANCED_COMPRESSION: + NEED_EDIT + dblist->tree_info->header->advanced_compression = + (*(unsigned int *)itm_ptr->pointer) != 0; + dblist->modified = 1; + break; + default: status = TreeILLEGAL_ITEM; break; diff --git a/treeshr/treeshrp.h b/treeshr/treeshrp.h index 80573017b3..32ca1577d2 100644 --- a/treeshr/treeshrp.h +++ b/treeshr/treeshrp.h @@ -370,21 +370,13 @@ typedef struct tag_info typedef struct tree_header { char version; /* Version of tree file format */ -#ifdef _AIX - unsigned sort_children : 1; - unsigned sort_members : 1; - unsigned versions_in_model : 1; - unsigned versions_in_pulse : 1; - unsigned readonly : 1; - unsigned : 3; -#else unsigned char sort_children : 1; /* Sort children flag */ unsigned char sort_members : 1; /* Sort members flag */ unsigned char versions_in_model : 1; unsigned char versions_in_pulse : 1; unsigned char readonly : 1; - unsigned char : 3; -#endif + unsigned char advanced_compression : 1; + unsigned char : 1; char fill1[6]; int free; /* First node in free node list (connected by PARENT/CHILD indexes */ @@ -640,6 +632,7 @@ typedef struct pino_database unsigned modified : 1; /* Flag indicating tree structure modified */ unsigned setup_info : 1; /* Flag indicating setup info is being added */ unsigned remote : 1; /* Flag indicating tree is on remote system */ + unsigned advanced_compression : 1; int stack_size; timecontext_t timecontext; int delete_list_vm; From b96fcb561e1304e49b952a9ba403dc6712491aae Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Tue, 31 Oct 2023 15:58:35 -0400 Subject: [PATCH 02/16] address PR comments --- include/dbidef.h | 2 +- treeshr/TreeGetDbi.c | 4 ++-- treeshr/TreeGetNci.c | 4 ++-- treeshr/TreeSetDbi.c | 4 ++-- treeshr/treeshrp.h | 7 ++++--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/dbidef.h b/include/dbidef.h index d220081d08..20979b6e25 100644 --- a/include/dbidef.h +++ b/include/dbidef.h @@ -23,7 +23,7 @@ #define DbiVERSIONS_IN_PULSE 11 /* True if using versioning in pulse files */ #define DbiREADONLY 12 /* True if making tree readonly */ #define DbiDISPATCH_TABLE 13 /* Tree dispatch table */ -#define DbiADVANCED_COMPRESSION 14 /* Set to true to enable extended compression methods */ +#define DbiALTERNATE_COMPRESSION 14 /* Set to true to enable extended compression methods */ typedef struct dbi_itm { short int buffer_length; diff --git a/treeshr/TreeGetDbi.c b/treeshr/TreeGetDbi.c index b74dd7e57d..a7b2aaf5e3 100644 --- a/treeshr/TreeGetDbi.c +++ b/treeshr/TreeGetDbi.c @@ -96,10 +96,10 @@ int _TreeGetDbi(void *dbid, struct dbi_itm *itmlst) set_ret_char(db->open_readonly); break; - case DbiADVANCED_COMPRESSION: + case DbiALTERNATE_COMPRESSION: CheckOpen(db); - set_ret_char(db->advanced_compression); + set_ret_char(db->alternate_compression); break; case DbiINDEX: diff --git a/treeshr/TreeGetNci.c b/treeshr/TreeGetNci.c index 75ff141d34..eefe0c29aa 100644 --- a/treeshr/TreeGetNci.c +++ b/treeshr/TreeGetNci.c @@ -290,7 +290,7 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) break_on_no_node; read_nci; set_retlen(sizeof(nci.compression_method)); - if (dblist->tree_info->header->advanced_compression) { + if (dblist->tree_info->header->alternate_compression) { *(unsigned char *)itm->pointer = nci.compression_method; } else { *(unsigned char *)itm->pointer = 0; @@ -701,7 +701,7 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) { break_on_no_node; read_nci; - if (! dblist->tree_info->header->advanced_compression) nci.compression_method = 0; + if (! dblist->tree_info->header->alternate_compression) nci.compression_method = 0; if (nci.compression_method >= NUM_COMPRESSION_METHODS) nci.compression_method = 0; string = strdup(compression_methods[nci.compression_method].name); diff --git a/treeshr/TreeSetDbi.c b/treeshr/TreeSetDbi.c index ca9536433b..19fc03545c 100644 --- a/treeshr/TreeSetDbi.c +++ b/treeshr/TreeSetDbi.c @@ -111,9 +111,9 @@ int _TreeSetDbi(void *dbid, DBI_ITM *dbi_itm_ptr) (*(unsigned int *)itm_ptr->pointer) != 0; dblist->modified = 1; break; - case DbiADVANCED_COMPRESSION: + case DbiALTERNATE_COMPRESSION: NEED_EDIT - dblist->tree_info->header->advanced_compression = + dblist->tree_info->header->alternate_compression = (*(unsigned int *)itm_ptr->pointer) != 0; dblist->modified = 1; break; diff --git a/treeshr/treeshrp.h b/treeshr/treeshrp.h index 32ca1577d2..c979604904 100644 --- a/treeshr/treeshrp.h +++ b/treeshr/treeshrp.h @@ -375,8 +375,8 @@ typedef struct tree_header unsigned char versions_in_model : 1; unsigned char versions_in_pulse : 1; unsigned char readonly : 1; - unsigned char advanced_compression : 1; - unsigned char : 1; + unsigned char alternate_compression : 1; + unsigned char : 2; char fill1[6]; int free; /* First node in free node list (connected by PARENT/CHILD indexes */ @@ -632,7 +632,8 @@ typedef struct pino_database unsigned modified : 1; /* Flag indicating tree structure modified */ unsigned setup_info : 1; /* Flag indicating setup info is being added */ unsigned remote : 1; /* Flag indicating tree is on remote system */ - unsigned advanced_compression : 1; + unsigned alternate_compression : 1; + unsigned char : 1; int stack_size; timecontext_t timecontext; int delete_list_vm; From 7a18efb4d372a01d9a2b92242d74d760512e1010 Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Tue, 31 Oct 2023 17:14:21 -0400 Subject: [PATCH 03/16] make bitfield declarations consistent --- treeshr/treeshrp.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/treeshr/treeshrp.h b/treeshr/treeshrp.h index c979604904..d1d01d34ca 100644 --- a/treeshr/treeshrp.h +++ b/treeshr/treeshrp.h @@ -370,13 +370,13 @@ typedef struct tag_info typedef struct tree_header { char version; /* Version of tree file format */ - unsigned char sort_children : 1; /* Sort children flag */ - unsigned char sort_members : 1; /* Sort members flag */ - unsigned char versions_in_model : 1; - unsigned char versions_in_pulse : 1; - unsigned char readonly : 1; - unsigned char alternate_compression : 1; - unsigned char : 2; + unsigned sort_children : 1; /* Sort children flag */ + unsigned sort_members : 1; /* Sort members flag */ + unsigned versions_in_model : 1; + unsigned versions_in_pulse : 1; + unsigned readonly : 1; + unsigned alternate_compression : 1; + unsigned : 2; char fill1[6]; int free; /* First node in free node list (connected by PARENT/CHILD indexes */ @@ -633,7 +633,7 @@ typedef struct pino_database unsigned setup_info : 1; /* Flag indicating setup info is being added */ unsigned remote : 1; /* Flag indicating tree is on remote system */ unsigned alternate_compression : 1; - unsigned char : 1; + unsigned : 1; int stack_size; timecontext_t timecontext; int delete_list_vm; From 03bd2d42b81ec5d535bd2eb448ef4824e09a1094 Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Tue, 31 Oct 2023 17:46:41 -0400 Subject: [PATCH 04/16] new understanding of bitfields --- treeshr/treeshrp.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/treeshr/treeshrp.h b/treeshr/treeshrp.h index d1d01d34ca..1f6d86ff38 100644 --- a/treeshr/treeshrp.h +++ b/treeshr/treeshrp.h @@ -370,13 +370,13 @@ typedef struct tag_info typedef struct tree_header { char version; /* Version of tree file format */ - unsigned sort_children : 1; /* Sort children flag */ - unsigned sort_members : 1; /* Sort members flag */ - unsigned versions_in_model : 1; - unsigned versions_in_pulse : 1; - unsigned readonly : 1; - unsigned alternate_compression : 1; - unsigned : 2; + unsigned char sort_children : 1; /* Sort children flag */ + unsigned char sort_members : 1; /* Sort members flag */ + unsigned char versions_in_model : 1; + unsigned char versions_in_pulse : 1; + unsigned char readonly : 1; + unsigned char alternate_compression : 1; + unsigned char : 2; char fill1[6]; int free; /* First node in free node list (connected by PARENT/CHILD indexes */ @@ -633,14 +633,15 @@ typedef struct pino_database unsigned setup_info : 1; /* Flag indicating setup info is being added */ unsigned remote : 1; /* Flag indicating tree is on remote system */ unsigned alternate_compression : 1; - unsigned : 1; + unsigned : 25; int stack_size; + unsigned fill; timecontext_t timecontext; int delete_list_vm; unsigned char *delete_list; - void *dispatch_table; /* pointer to dispatch table generated by dispatch/build - */ + void *dispatch_table; /* pointer to dispatch table generated by dispatch/build */ } PINO_DATABASE; +_Static_assert(sizeof(PINO_DATABASE) == 152, "nope"); static inline NODE *nid_to_node(PINO_DATABASE *dbid, NID *nid) { From 79ecd031f701a1d94ac0a041d81157fc3c1bf6ff Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Wed, 1 Nov 2023 09:06:34 -0400 Subject: [PATCH 05/16] add python tree property alternate_compression --- python/MDSplus/tree.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/python/MDSplus/tree.py b/python/MDSplus/tree.py index a8a33fca96..1eb8e3a910 100644 --- a/python/MDSplus/tree.py +++ b/python/MDSplus/tree.py @@ -133,7 +133,7 @@ def _getNodeByAttr(self, name): class Dbi(object): NAME = (1, str, 12) - SHOTID = (2, int, 4) + SHOTID = (2, int, 4) MODIFIED = (3, bool, 4) OPEN_FOR_EDIT = (4, bool, 4) INDEX = (5, int, 4) @@ -144,6 +144,7 @@ class Dbi(object): VERSIONS_IN_MODEL = (10, bool, 4) # settable VERSIONS_IN_PULSE = (11, bool, 4) # settable DISPATCH_TABLE = (13, bool, 4) + ALTERNATE_COMPRESSION = (14, bool, 4) #settable class _dbi_item(_C.Structure): """ Ctype structure class for making calls into _TreeGetDbi() """ @@ -652,6 +653,8 @@ def _setDbi(self, info, value): Dbi.VERSIONS_IN_PULSE, "Support versioning of data in pulse.", True) dispatch_table = Dbi._dbiProp( Dbi.DISPATCH_TABLE, "True if dispatch table is built") + alternate_compression = Dbi._dbiProp( + Dbi.ALTERNATE_COMPRESSION, "Set to True to enable alternate compression methods", False) @property def default(self): @@ -1132,6 +1135,21 @@ def versionsInPulseEnabled(self): """ return self.versions_in_pulse + def setAlternateCompression(self, flag): + """Enable/Disable versions in pulse + @param flag: True or False. True enabled versions + @type flag: bool + @rtype: None + """ + self.alternate_compression = bool(flag) + + def alternateCompressionEnabled(self): + """Check to see if versions in the pulse are enabled + @return: True if versions in pulse is enabled + @rtype: bool + """ + return self.alternate_compression + def write(self): """Write out edited tree. @rtype: None From faefa71a1cc34946003e270a5cc997bc1c62d7d1 Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Wed, 1 Nov 2023 09:45:55 -0400 Subject: [PATCH 06/16] add alternate compression property and regression tests to cpp API --- include/mdsobjects.h | 10 ++++++++++ mdsobjects/cpp/mdstreeobjects.cpp | 10 ++++++++++ mdsobjects/cpp/testing/MdsTreeTest.cpp | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/include/mdsobjects.h b/include/mdsobjects.h index f393295958..f44af2f12f 100644 --- a/include/mdsobjects.h +++ b/include/mdsobjects.h @@ -4142,6 +4142,16 @@ namespace MDSplus /// void setVersionsInPulse(bool enable); + /// This function returns true if the tree allows for alternate compression + /// methods (gzip). \note this can only be changed in edit mode. + /// + bool alternateCompressionEnabled(); + + /// Activates alternate compression methods. See treeshr function \ref + /// TreeGetDbi() called with code DbiALTERNATE_COMPRESSION. + /// + void setAlternateCompression(bool enable); + /// View data stored in tree from given start date when version control is /// enabled. /// diff --git a/mdsobjects/cpp/mdstreeobjects.cpp b/mdsobjects/cpp/mdstreeobjects.cpp index 7c07ae597d..c30e6565d3 100644 --- a/mdsobjects/cpp/mdstreeobjects.cpp +++ b/mdsobjects/cpp/mdstreeobjects.cpp @@ -570,6 +570,11 @@ bool Tree::versionsInModelEnabled() return dbiTest(getCtx(), DbiVERSIONS_IN_MODEL); } +bool Tree::alternateCompressionEnabled() +{ + return dbiTest(getCtx(), DbiALTERNATE_COMPRESSION); +} + bool Tree::isModified() { return dbiTest(getCtx(), DbiMODIFIED); } bool Tree::isOpenForEdit() { return dbiTest(getCtx(), DbiOPEN_FOR_EDIT); } @@ -598,6 +603,11 @@ void Tree::setVersionsInPulse(bool verEnabled) dbiSet(getCtx(), DbiVERSIONS_IN_PULSE, verEnabled); } +void Tree::setAlternateCompression(bool altEnabled) +{ + dbiSet(getCtx(), DbiALTERNATE_COMPRESSION, altEnabled); +} + void Tree::setViewDate(char *date) { int64_t qtime; diff --git a/mdsobjects/cpp/testing/MdsTreeTest.cpp b/mdsobjects/cpp/testing/MdsTreeTest.cpp index f181857d5c..e2310e8508 100644 --- a/mdsobjects/cpp/testing/MdsTreeTest.cpp +++ b/mdsobjects/cpp/testing/MdsTreeTest.cpp @@ -79,11 +79,13 @@ using namespace testing; // TreeNode *getDefault(); // bool versionsInModelEnabled(); // bool versionsInPulseEnabled(); +// bool alternateCompressionEnabled(); // bool isModified(); // bool isOpenForEdit(); // bool isReadOnly(); // void setVersionsInModel(bool enable); // void setVersionsInPulse(bool enable); +// void setAlternateCompression(bool enable); // void setViewDate(char *date); // void setTimeContext(Data *start, Data *end, Data *delta); // void createPulse(int shot); @@ -425,6 +427,17 @@ int main(int argc __attribute__((unused)), tree = new Tree("t_tree", 1, "EDIT"); unique_ptr node = tree->addNode("versioned", "NUMERIC"); tree->setVersionsInPulse(true); + + // alternate compression - default False + TEST0(tree->alternateCompression()); + + // alternate compression - set to True + tree->setAlternateCompression(true); + TEST1(tree->alternateCompression()); + + // set alternate compression back to False + tree->setAlternateCompression(false); + tree->write(); tree = new Tree("t_tree", 1); @@ -446,6 +459,9 @@ int main(int argc __attribute__((unused)), TEST1(node->containsVersions()); + // alternate compression - should be false + TEST0(tree->alternateCompression()); + // TODO: version in model } From e0d427520be2e2d375b8fd6b2813026c01ff4be2 Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Thu, 2 Nov 2023 14:59:56 -0400 Subject: [PATCH 07/16] the assert fails on 32 bit --- treeshr/treeshrp.h | 1 - 1 file changed, 1 deletion(-) diff --git a/treeshr/treeshrp.h b/treeshr/treeshrp.h index 1f6d86ff38..44e278ac23 100644 --- a/treeshr/treeshrp.h +++ b/treeshr/treeshrp.h @@ -641,7 +641,6 @@ typedef struct pino_database unsigned char *delete_list; void *dispatch_table; /* pointer to dispatch table generated by dispatch/build */ } PINO_DATABASE; -_Static_assert(sizeof(PINO_DATABASE) == 152, "nope"); static inline NODE *nid_to_node(PINO_DATABASE *dbid, NID *nid) { From 1ba404427be0c36e9e37c58af7abb785a978dfb9 Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Thu, 2 Nov 2023 15:46:58 -0400 Subject: [PATCH 08/16] wrong method name --- mdsobjects/cpp/testing/MdsTreeTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mdsobjects/cpp/testing/MdsTreeTest.cpp b/mdsobjects/cpp/testing/MdsTreeTest.cpp index e2310e8508..f0c755f368 100644 --- a/mdsobjects/cpp/testing/MdsTreeTest.cpp +++ b/mdsobjects/cpp/testing/MdsTreeTest.cpp @@ -429,11 +429,11 @@ int main(int argc __attribute__((unused)), tree->setVersionsInPulse(true); // alternate compression - default False - TEST0(tree->alternateCompression()); + TEST0(tree->alternateCompressionEnabled()); // alternate compression - set to True tree->setAlternateCompression(true); - TEST1(tree->alternateCompression()); + TEST1(tree->alternateCompressionEnabled()); // set alternate compression back to False tree->setAlternateCompression(false); From b91096e0e213b59b72097bde0225876c9c0b80dd Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Thu, 2 Nov 2023 17:03:59 -0400 Subject: [PATCH 09/16] fix all the instances of wrong method --- mdsobjects/cpp/testing/MdsTreeTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdsobjects/cpp/testing/MdsTreeTest.cpp b/mdsobjects/cpp/testing/MdsTreeTest.cpp index f0c755f368..4abd426003 100644 --- a/mdsobjects/cpp/testing/MdsTreeTest.cpp +++ b/mdsobjects/cpp/testing/MdsTreeTest.cpp @@ -460,7 +460,7 @@ int main(int argc __attribute__((unused)), TEST1(node->containsVersions()); // alternate compression - should be false - TEST0(tree->alternateCompression()); + TEST0(tree->alternateCompressionEnabled()); // TODO: version in model } From 36fcce23c79188b387137c0643c1edfcbb28cfe7 Mon Sep 17 00:00:00 2001 From: Stephen Lane-Walsh Date: Fri, 3 Nov 2023 14:17:49 -0400 Subject: [PATCH 10/16] Fix issue reported by MdsTreeTest.cpp Small fixes for PR comments --- python/MDSplus/tree.py | 12 ++++++------ treeshr/TreeGetDbi.c | 20 +++++++++++++------- treeshr/TreeGetNci.c | 9 ++++++--- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/python/MDSplus/tree.py b/python/MDSplus/tree.py index 1eb8e3a910..524c42fc19 100644 --- a/python/MDSplus/tree.py +++ b/python/MDSplus/tree.py @@ -133,7 +133,7 @@ def _getNodeByAttr(self, name): class Dbi(object): NAME = (1, str, 12) - SHOTID = (2, int, 4) + SHOTID = (2, int, 4) MODIFIED = (3, bool, 4) OPEN_FOR_EDIT = (4, bool, 4) INDEX = (5, int, 4) @@ -1115,7 +1115,7 @@ def setVersionsInModel(self, flag): def setVersionsInPulse(self, flag): """Enable/Disable versions in pulse - @param flag: True or False. True enabled versions + @param flag: True or False. True enables versions @type flag: bool @rtype: None """ @@ -1136,16 +1136,16 @@ def versionsInPulseEnabled(self): return self.versions_in_pulse def setAlternateCompression(self, flag): - """Enable/Disable versions in pulse - @param flag: True or False. True enabled versions + """Enable/Disable alternate compression methods + @param flag: True or False. True enables alternate compression methods @type flag: bool @rtype: None """ self.alternate_compression = bool(flag) def alternateCompressionEnabled(self): - """Check to see if versions in the pulse are enabled - @return: True if versions in pulse is enabled + """Check to see if alternate compression methods are enabled + @return: True if alternate compression methods are enabled @rtype: bool """ return self.alternate_compression diff --git a/treeshr/TreeGetDbi.c b/treeshr/TreeGetDbi.c index a7b2aaf5e3..0476da66f2 100644 --- a/treeshr/TreeGetDbi.c +++ b/treeshr/TreeGetDbi.c @@ -52,7 +52,7 @@ int TreeGetDbi(struct dbi_itm *itmlst) } #define set_ret_char(val) \ memset(lst->pointer, 0, (size_t)lst->buffer_length); \ - *((char *)lst->pointer) = val; + *((char *)lst->pointer) = val int _TreeGetDbi(void *dbid, struct dbi_itm *itmlst) { @@ -96,12 +96,6 @@ int _TreeGetDbi(void *dbid, struct dbi_itm *itmlst) set_ret_char(db->open_readonly); break; - case DbiALTERNATE_COMPRESSION: - - CheckOpen(db); - set_ret_char(db->alternate_compression); - break; - case DbiINDEX: { @@ -186,6 +180,18 @@ int _TreeGetDbi(void *dbid, struct dbi_itm *itmlst) break; } + case DbiALTERNATE_COMPRESSION: + CheckOpen(db); + { + int value = db->tree_info->header->alternate_compression; + memset(lst->pointer, 0, (size_t)lst->buffer_length); + int length = minInt(lst->buffer_length, sizeof(int)); + memcpy(lst->pointer, &value, (size_t)length); + if (lst->return_length_address) + *lst->return_length_address = length; + break; + } + default: status = TreeILLEGAL_ITEM; } diff --git a/treeshr/TreeGetNci.c b/treeshr/TreeGetNci.c index eefe0c29aa..b0becf9c77 100644 --- a/treeshr/TreeGetNci.c +++ b/treeshr/TreeGetNci.c @@ -701,9 +701,12 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) { break_on_no_node; read_nci; - if (! dblist->tree_info->header->alternate_compression) nci.compression_method = 0; - if (nci.compression_method >= NUM_COMPRESSION_METHODS) - nci.compression_method = 0; + if (! dblist->tree_info->header->alternate_compression) { + nci.compression_method = 0; + } + if (nci.compression_method >= NUM_COMPRESSION_METHODS) { + nci.compression_method = 0; + } string = strdup(compression_methods[nci.compression_method].name); break; } From 180906276ca046e90cfc83961d50edd158d70144 Mon Sep 17 00:00:00 2001 From: Fernando Santoro Date: Fri, 3 Nov 2023 17:00:51 -0400 Subject: [PATCH 11/16] Add TCL verbs for alternate compression --- tcl/tcl_setshow_alternate_compression.c | 104 ++++++++++++++++++++++++ xml/tcl_commands.xml | 41 ++++++++++ 2 files changed, 145 insertions(+) create mode 100644 tcl/tcl_setshow_alternate_compression.c diff --git a/tcl/tcl_setshow_alternate_compression.c b/tcl/tcl_setshow_alternate_compression.c new file mode 100644 index 0000000000..cd28f6543d --- /dev/null +++ b/tcl/tcl_setshow_alternate_compression.c @@ -0,0 +1,104 @@ +/* +Copyright (c) 2023, Massachusetts Institute of Technology All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#include +#include + +#include +#include +#include +#include +#include +#include + +/*************************************************************** + * TclSetAlternateCompression: + **************************************************************/ + +EXPORT int TclSetAlternateCompression(void *ctx, char **error, + char **output __attribute__((unused))) +{ + int status = 1; + + char * enabled = 0; + status = cli_get_value(ctx, "ENABLED", &enabled); + if (STATUS_OK) { + size_t length = strlen(enabled); + for (size_t i = 0; i < length; ++i) { + enabled[i] = toupper(enabled[i]); + } + + if (strcmp(enabled, "ON") == 0) { + status = TreeSetDbiItm(DbiALTERNATE_COMPRESSION, 1); + } + else if (strcmp(enabled, "OFF") == 0) { + status = TreeSetDbiItm(DbiALTERNATE_COMPRESSION, 0); + } + else { + status = MdsdclIVQUAL; + } + } + + if (STATUS_NOT_OK) + goto error; + +error: + if (STATUS_NOT_OK) + { + char *msg = MdsGetMsg(status); + *error = malloc(strlen(msg) + 100); + sprintf(*error, + "Error: problem setting alternate compression.\n" + "Error message was: %s\n", + msg); + } + return status; +} + +EXPORT int TclShowAlternateCompression(void *ctx __attribute__((unused)), + char **error __attribute__((unused)), + char **output) +{ + int enable, status; + DBI_ITM itmlst[] = {{4, DbiALTERNATE_COMPRESSION, &enable, 0}, + {0, 0, 0, 0}}; + status = TreeGetDbi(itmlst); + if (STATUS_OK) + { + *output = malloc(500); + sprintf(*output, + " Alternate Compression is %s.\n", + enable ? "enabled" : "disabled"); + } + else + { + char *msg = MdsGetMsg(status); + *error = malloc(strlen(msg) + 100); + sprintf(*error, + "Error: problem querying alternate compression.\n" + "Error message was: %s\n", + msg); + } + return status; +} diff --git a/xml/tcl_commands.xml b/xml/tcl_commands.xml index e6198b4c5f..c66158e6c2 100644 --- a/xml/tcl_commands.xml +++ b/xml/tcl_commands.xml @@ -948,6 +948,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. " " " + " @@ -1237,6 +1238,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + Command: SET ALTERNATE_COMPRESSION + Purpose: Enable or disable alternate compression methods in a tree. + Format: SET ALTERNATE_COMPRESSION [ON|OFF] + Description: + + The SET ALTERNATE_COMPRESSION command is used to enable or disable support + for alternate compression methods (stored in the NCI for a node) across + an entire tree. + + + + + + + Command: SETEVENT @@ -1268,6 +1286,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. " " + " @@ -1462,6 +1481,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + Command: SHOW ALTERNATE_COMPRESSION + Purpose: Show whether or not data alternate compression methods are enabled + for the current tree. + Format: SHOW ALTERNATE_COMPRESSION + + Description: + + The SHOW ALTERNATE_COMPRESSION command is used to display the current + alternate compression settings for the current tree. + + Example: + + TCL> SET TREE main + TCL> SHOW ALTERNATE_COMPRESSION + Alternate Compression is disabled. + + + + +