obi arrays that don't work because of cython bug passing wrong pointers
This commit is contained in:
@ -16,6 +16,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
@ -28,6 +29,7 @@
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obilittlebigman.h"
|
||||
#include "obiarray.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
@ -151,35 +153,35 @@ static size_t get_line_count_per_page(OBIType_t data_type, size_t nb_elements_pe
|
||||
************************************************************************/
|
||||
|
||||
|
||||
static char *build_column_file_name(const char *column_name, obiversion_t version_number)
|
||||
static char* build_column_file_name(const char* column_name, obiversion_t version_number)
|
||||
{
|
||||
char *filename;
|
||||
char* file_name;
|
||||
|
||||
// Build the database directory name
|
||||
if (asprintf(&filename,"%s@%d.odc", column_name, version_number) < 0)
|
||||
// Build the file name
|
||||
if (asprintf(&file_name,"%s@%d.odc", column_name, version_number) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_MEMORY_ERROR);
|
||||
obidebug(1, "\nError building a column file name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return filename;
|
||||
return file_name;
|
||||
}
|
||||
|
||||
|
||||
static char *build_version_file_name(const char *column_name)
|
||||
static char* build_version_file_name(const char* column_name)
|
||||
{
|
||||
char *filename;
|
||||
char* file_name;
|
||||
|
||||
// Build the database directory name
|
||||
if (asprintf(&filename,"%s.odv", column_name) < 0)
|
||||
// Build the file name
|
||||
if (asprintf(&file_name,"%s.odv", column_name) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_MEMORY_ERROR);
|
||||
obidebug(1, "\nError building a version file name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return filename;
|
||||
return file_name;
|
||||
}
|
||||
|
||||
|
||||
@ -602,11 +604,13 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
OBIType_t data_type,
|
||||
size_t nb_lines,
|
||||
size_t nb_elements_per_line,
|
||||
const char* elements_names)
|
||||
const char* elements_names,
|
||||
const char* array_name)
|
||||
{
|
||||
OBIDMS_column_p new_column;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
OBIDMS_column_header_p header;
|
||||
OBIDMS_array_p array;
|
||||
size_t file_size;
|
||||
obiversion_t version_number;
|
||||
char* column_file_name;
|
||||
@ -629,17 +633,23 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
obidebug(1, "\nCan't create column because of empty column name");
|
||||
return NULL;
|
||||
}
|
||||
if ((data_type < 1) || (data_type > 4))
|
||||
if ((data_type < 1) || (data_type > 5))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of invalid data type");
|
||||
return NULL;
|
||||
}
|
||||
if ((data_type == 5) && (array_name == NULL))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of empty array name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// The initial line count should be between the minimum (corresponding to the page size) and the maximum allowed
|
||||
minimum_line_count = get_line_count_per_page(data_type, nb_elements_per_line);
|
||||
if (nb_lines > MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of line count greater than the maximum allowed (%ld)", MAXIMUM_LINE_COUNT);
|
||||
obidebug(1, "\nCan't create column because of line count greater than the maximum allowed (%d)", MAXIMUM_LINE_COUNT);
|
||||
return NULL;
|
||||
}
|
||||
else if (nb_lines < minimum_line_count)
|
||||
@ -800,6 +810,23 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
|
||||
strncpy(header->name, column_name, OBIDMS_COLUMN_MAX_NAME);
|
||||
|
||||
// If the data type is OBI_IDX, the associated obi_array is opened or created
|
||||
if (data_type == 5)
|
||||
{
|
||||
array = obi_array(dms, array_name);
|
||||
if (array == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening or creating the array associated with a column");
|
||||
munmap(new_column->header, header_size);
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
free(new_column);
|
||||
return NULL;
|
||||
}
|
||||
new_column->array = array;
|
||||
strncpy(header->array_name, array_name, ARRAY_MAX_NAME);
|
||||
}
|
||||
|
||||
// Fill the data with NA values
|
||||
obi_ini_to_NA_values(new_column, 0, nb_lines);
|
||||
|
||||
@ -816,6 +843,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
{
|
||||
OBIDMS_column_p column;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
OBIDMS_array_p array;
|
||||
char* column_file_name;
|
||||
int column_file_descriptor;
|
||||
int column_dir_file_descriptor;
|
||||
@ -931,6 +959,22 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
|
||||
column->writable = false;
|
||||
|
||||
// If the data type is OBI_IDX, the associated obi_array is opened or created
|
||||
if ((column->header)->data_type == 5)
|
||||
{
|
||||
array = obi_array(dms, (column->header)->array_name);
|
||||
if (array == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening the array associated with a column");
|
||||
munmap(column->header, header_size);
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
free(column);
|
||||
return NULL;
|
||||
}
|
||||
column->array = array;
|
||||
}
|
||||
|
||||
free(column_file_name);
|
||||
close(column_file_descriptor);
|
||||
|
||||
@ -972,7 +1016,8 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
data_type,
|
||||
nb_lines,
|
||||
nb_elements_per_line,
|
||||
(column_to_clone->header)->elements_names);
|
||||
(column_to_clone->header)->elements_names,
|
||||
(column_to_clone->header)->array_name);
|
||||
|
||||
if (new_column == NULL)
|
||||
{
|
||||
@ -1170,7 +1215,7 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
|
||||
// Calculate the new file size
|
||||
old_line_count = (column->header)->line_count;
|
||||
new_line_count = old_line_count * GROWTH_FACTOR;
|
||||
new_line_count = old_line_count * COLUMN_GROWTH_FACTOR;
|
||||
|
||||
if (new_line_count > MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
@ -1181,7 +1226,7 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
return -1;
|
||||
}
|
||||
old_data_size = obi_array_sizeof((column->header)->data_type, old_line_count, (column->header)->nb_elements_per_line);
|
||||
new_data_size = old_data_size * GROWTH_FACTOR;
|
||||
new_data_size = old_data_size * COLUMN_GROWTH_FACTOR;
|
||||
header_size = (column->header)->header_size;
|
||||
file_size = header_size + new_data_size;
|
||||
|
||||
|
Reference in New Issue
Block a user