From 1da6aac1b846455c719473ac7a76e61762b549fd Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Wed, 12 Aug 2020 17:55:08 +0200 Subject: [PATCH] C: patch for failed creation of AVL with errno EEXIST --- src/obidmscolumn.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/obidmscolumn.c b/src/obidmscolumn.c index d9afd08..638abf8 100644 --- a/src/obidmscolumn.c +++ b/src/obidmscolumn.c @@ -1725,16 +1725,32 @@ int obi_close_column(OBIDMS_column_p column) int obi_clone_column_indexer(OBIDMS_column_p column) { char* new_indexer_name; + int i; - new_indexer_name = obi_build_indexer_name((column->header)->name, (column->header)->version); - if (new_indexer_name == NULL) - return -1; - - column->indexer = obi_clone_indexer(column->indexer, new_indexer_name); // TODO Need to lock this somehow? - if (column->indexer == NULL) + i=0; + while (true) // find avl name not already used { - obidebug(1, "\nError cloning a column's indexer to make it writable"); - return -1; + new_indexer_name = obi_build_indexer_name((column->header)->name, ((column->header)->version)+i); + if (new_indexer_name == NULL) + return -1; + + column->indexer = obi_clone_indexer(column->indexer, new_indexer_name); // TODO Need to lock this somehow? + if (column->indexer == NULL) + { + if (errno == EEXIST) + { + free(new_indexer_name); + i++; + } + else + { + free(new_indexer_name); + obidebug(1, "\nError cloning a column's indexer to make it writable"); + return -1; + } + } + else + break; } strcpy((column->header)->indexer_name, new_indexer_name); @@ -2415,16 +2431,20 @@ char* obi_get_formatted_elements_names(OBIDMS_column_p column) } -char* obi_column_formatted_infos(OBIDMS_column_p column) +char* obi_column_formatted_infos(OBIDMS_column_p column, bool detailed) { - char* column_infos; - char* elt_names; - - column_infos = malloc(1024 * sizeof(char)); + char* column_infos = NULL; + char* elt_names = NULL; + char* column_name = NULL; + // should be in view.c because alias exists in the context of view + column_infos = malloc(2048 * sizeof(char)); // TODO elt_names = obi_get_formatted_elements_names(column); +// "column_name, data type: OBI_TYPE, element names: [formatted element names](, all comments)" + + free(elt_names); return column_infos; }