Added the lists of opened columns and arrays in the OBIDMS structure,
and a counter in the OBIDMS column structure; fixed some bugs and created tests for referring columns that are bound to disappear anyway.
This commit is contained in:
@ -732,9 +732,8 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
if (comments != NULL)
|
||||
strncpy(header->comments, comments, COMMENTS_MAX_LENGTH);
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, and the column is not referring another,
|
||||
// the associated obi_array is opened or created
|
||||
if ((stored_data_type == OBI_STR) || (stored_data_type == OBI_SEQ))
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated obi_array is opened or created
|
||||
if ((returned_data_type == OBI_STR) || (returned_data_type == OBI_SEQ))
|
||||
{
|
||||
array = obi_array(dms, array_name);
|
||||
if (array == NULL)
|
||||
@ -754,6 +753,11 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
|
||||
close(column_file_descriptor);
|
||||
|
||||
// Add in the list of opened columns
|
||||
*(((dms->opened_columns)->columns)+((dms->opened_columns)->nb_opened_columns)) = new_column;
|
||||
((dms->opened_columns)->nb_opened_columns)++;
|
||||
new_column->counter = 1;
|
||||
|
||||
return new_column;
|
||||
}
|
||||
|
||||
@ -768,6 +772,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
char* column_file_name;
|
||||
int column_file_descriptor;
|
||||
size_t header_size;
|
||||
size_t i;
|
||||
|
||||
column = NULL;
|
||||
|
||||
@ -790,6 +795,17 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the column is already in the list of opened columns
|
||||
for (i=0; i < ((dms->opened_columns)->nb_opened_columns); i++)
|
||||
{
|
||||
if (!strcmp(((*(((dms->opened_columns)->columns)+i))->header)->name, column_name)
|
||||
&& (((*(((dms->opened_columns)->columns)+i))->header)->version == version_number))
|
||||
{ // Found the column already opened, increase its counter and return the column
|
||||
((*(((dms->opened_columns)->columns)+i))->counter)++;
|
||||
return *(((dms->opened_columns)->columns)+i);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the column file name
|
||||
column_file_name = build_column_file_name(column_name, version_number);
|
||||
if (column_file_name == NULL)
|
||||
@ -870,9 +886,8 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
|
||||
column->writable = false;
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, and the column is not referring,
|
||||
// the associated obi_array is opened
|
||||
if (((column->header)->stored_data_type == OBI_STR) || ((column->header)->stored_data_type == OBI_SEQ))
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated obi_array is opened
|
||||
if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
{
|
||||
array = obi_array(dms, (column->header)->array_name);
|
||||
if (array == NULL)
|
||||
@ -900,6 +915,11 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
|
||||
close(column_file_descriptor);
|
||||
|
||||
// Add in the list of opened columns and set column counter to 1
|
||||
*(((dms->opened_columns)->columns)+((dms->opened_columns)->nb_opened_columns)) = column;
|
||||
((dms->opened_columns)->nb_opened_columns)++;
|
||||
column->counter = 1;
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
@ -924,6 +944,14 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// A referring column can't be cloned
|
||||
if ((column_to_clone->header)->referring)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError: can't clone a referring column");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data_type = (column_to_clone->header)->returned_data_type;
|
||||
|
||||
nb_elements_per_line = (column_to_clone->header)->returned_nb_elements_per_line;
|
||||
@ -990,29 +1018,69 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
|
||||
int obi_close_column(OBIDMS_column_p column)
|
||||
{
|
||||
if ((column->header)->referring)
|
||||
obi_close_column(column->referred_column);
|
||||
size_t i;
|
||||
bool close_dir;
|
||||
Opened_columns_list_p columns_list;
|
||||
|
||||
// Munmap data
|
||||
if (munmap(column->data, (column->header)->data_size) < 0)
|
||||
columns_list = (column->dms)->opened_columns;
|
||||
|
||||
(column->counter)--;
|
||||
|
||||
if (column->counter == 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping column data");
|
||||
return -1;
|
||||
// Delete from the list of opened columns
|
||||
for (i=0; i < (columns_list)->nb_opened_columns; i++)
|
||||
{
|
||||
if (!strcmp(((*((columns_list->columns)+i))->header)->name, (column->header)->name)
|
||||
&& (((*((columns_list->columns)+i))->header)->version == (column->header)->version))
|
||||
{ // Found the column. Rearrange list
|
||||
(columns_list->nb_opened_columns)--;
|
||||
(columns_list->columns)[i] = (columns_list->columns)[columns_list->nb_opened_columns];
|
||||
}
|
||||
}
|
||||
|
||||
// Close column directory if it was the last column opened from that directory
|
||||
close_dir = 1;
|
||||
for (i=0; i < (columns_list->nb_opened_columns); i++)
|
||||
{
|
||||
if (!strcmp(((*((columns_list->columns)+i))->header)->name, (column->header)->name))
|
||||
{ // Not the last column from that directory
|
||||
close_dir = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((column->header)->referring)
|
||||
obi_close_column(column->referred_column);
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated obi_array is closed
|
||||
if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
{
|
||||
if (obi_close_array(column->array) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Munmap data
|
||||
if (munmap(column->data, (column->header)->data_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping column data");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Munmap header
|
||||
if (munmap(column->header, (column->header)->header_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping a column header");
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(column);
|
||||
|
||||
if (close_dir)
|
||||
obi_close_column_directory(column->column_directory);
|
||||
}
|
||||
|
||||
// Munmap header
|
||||
if (munmap(column->header, (column->header)->header_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping a column header");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//obi_close_column_directory(column->column_directory); // TODO or not
|
||||
|
||||
free(column);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1409,7 +1477,7 @@ char* obi_column_format_date(time_t date)
|
||||
}
|
||||
|
||||
|
||||
// TODO put in separate file and needs to lock the dependency with the referred column but...
|
||||
// TODO put in separate file ?
|
||||
// warning for the dependency and for the fact that it's always added at the next line (or not cuz might not be a good idea?)
|
||||
int obi_grep_line(OBIDMS_column_p referring_column, index_t line_to_grep)
|
||||
{
|
||||
|
Reference in New Issue
Block a user