Fixed a bug where cloning a column would fail if the data was empty

This commit is contained in:
Celine Mercier
2015-10-08 10:36:02 +02:00
parent c013e6ad33
commit ee4c513fd4
2 changed files with 25 additions and 22 deletions

View File

@ -604,17 +604,17 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
size_t nb_elements_per_line, size_t nb_elements_per_line,
const char* elements_names) const char* elements_names)
{ {
OBIDMS_column_p new_column; OBIDMS_column_p new_column;
OBIDMS_column_directory_p column_directory; OBIDMS_column_directory_p column_directory;
OBIDMS_column_header_p header; OBIDMS_column_header_p header;
size_t file_size; size_t file_size;
obiversion_t version_number; obiversion_t version_number;
char* column_file_name; char* column_file_name;
int column_file_descriptor; int column_file_descriptor;
int column_dir_file_descriptor; int column_dir_file_descriptor;
size_t header_size; size_t header_size;
size_t data_size; size_t data_size;
size_t minimum_line_count; size_t minimum_line_count;
new_column = NULL; new_column = NULL;
@ -1041,8 +1041,8 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
int column_file_descriptor; int column_file_descriptor;
char* column_file_name; char* column_file_name;
// Compute the new line count = the number of lines used rounded to the nearest multiple of page size // Compute the new line count = the number of lines used rounded to the nearest greater multiple of page size greater than 0
multiple = ceil((double) ((column->header)->lines_used * (column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type)) / (double) getpagesize()); multiple = ceil((double) (ONE_IF_ZERO((column->header)->lines_used) * (column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type)) / (double) getpagesize());
new_line_count = (int) multiple * getpagesize(); new_line_count = (int) multiple * getpagesize();
// Check that it is actually greater than the current number of lines allocated in the file, otherwise no need to truncate // Check that it is actually greater than the current number of lines allocated in the file, otherwise no need to truncate
@ -1558,13 +1558,14 @@ size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char
size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column) size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column)
{ {
// TODO check that column is not NULL?
return (column->header)->nb_elements_per_line; return (column->header)->nb_elements_per_line;
} }
char* obi_column_get_formatted_creation_date(OBIDMS_column_p column) char* obi_column_get_formatted_creation_date(OBIDMS_column_p column)
{ {
const char* formatted_time; char* formatted_time;
struct tm* tmp; struct tm* tmp;
formatted_time = (char*) malloc(FORMATTED_TIME_LENGTH*sizeof(char)); formatted_time = (char*) malloc(FORMATTED_TIME_LENGTH*sizeof(char));
@ -1597,7 +1598,7 @@ char* obi_column_get_formatted_creation_date_from_name(OBIDMS_p dms, const char*
int column_dir_file_descriptor; int column_dir_file_descriptor;
size_t header_size; size_t header_size;
obiversion_t version_number; obiversion_t version_number;
const char* formatted_time; char* formatted_time;
struct tm* tmp; struct tm* tmp;
// Get the column directory structure associated to the column // Get the column directory structure associated to the column

View File

@ -27,14 +27,16 @@
#include "obidmscolumndir.h" #include "obidmscolumndir.h"
#define ELEMENTS_NAMES_MAX (2048) /**< The maximum length of the list of elements names. #define ONE_IF_ZERO(x) (((x)==0)?1:(x)) /**< If x is equal to 0, x takes the value 1.
*/ */
#define GROWTH_FACTOR (2) /**< The growth factor when a column is enlarged. #define ELEMENTS_NAMES_MAX (2048) /**< The maximum length of the list of elements names.
*/ */
#define MAXIMUM_LINE_COUNT (1000000) /**< The maximum line count for the data of a column. //TODO #define GROWTH_FACTOR (2) /**< The growth factor when a column is enlarged.
*/ */
#define FORMATTED_TIME_LENGTH (1024) /**< The length allocated for the character string containing a formatted date #define MAXIMUM_LINE_COUNT (1000000) /**< The maximum line count for the data of a column. //TODO
*/ */
#define FORMATTED_TIME_LENGTH (1024) /**< The length allocated for the character string containing a formatted date
*/
typedef int32_t obiversion_t; /**< Used to store the column version number typedef int32_t obiversion_t; /**< Used to store the column version number
*/ */