Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OBITools3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OBITools
OBITools3
Commits
05e3956a
Commit
05e3956a
authored
Nov 09, 2015
by
Celine Mercier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor changes in code to improve readability (freeing some character
strings earlier)
parent
9b066f43
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
53 deletions
+23
-53
src/obiarray.c
src/obiarray.c
+1
-1
src/obidms.c
src/obidms.c
+3
-3
src/obidmscolumn.c
src/obidmscolumn.c
+17
-49
src/obidmscolumn.h
src/obidmscolumn.h
+2
-0
No files found.
src/obiarray.c
View file @
05e3956a
...
...
@@ -988,7 +988,7 @@ OBIDMS_array_p obi_open_array(OBIDMS_p dms, const char* array_name)
}
int
obi_close_array
(
OBIDMS_array_p
array
)
int
obi_close_array
(
OBIDMS_array_p
array
)
// TODO when do we call it? (as multiple threads can be using the same array)
{
int
ret_val
=
0
;
...
...
src/obidms.c
View file @
05e3956a
...
...
@@ -145,12 +145,14 @@ OBIDMS_p obi_create_dms(const char* dms_name)
free
(
directory_name
);
return
NULL
;
}
free
(
directory_name
);
dms_file_descriptor
=
dirfd
(
dms_dir
);
if
(
dms_file_descriptor
<
0
)
{
obi_set_errno
(
OBIDMS_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Problem getting the file descriptor of a newly created OBIDMS directory"
);
free
(
directory_name
);
return
NULL
;
}
...
...
@@ -159,11 +161,9 @@ OBIDMS_p obi_create_dms(const char* dms_name)
{
obi_set_errno
(
OBI_ARRAY_ERROR
);
obidebug
(
1
,
"
\n
Problem creating an arrays directory"
);
free
(
directory_name
);
return
NULL
;
}
free
(
directory_name
);
return
obi_open_dms
(
dms_name
);
}
...
...
src/obidmscolumn.c
View file @
05e3956a
...
...
@@ -234,13 +234,14 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
}
}
free
(
version_file_name
);
// Test if the version file size is ok
if
(
lseek
(
version_file_descriptor
,
0
,
SEEK_END
)
<
loc_size
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error testing if a version file size is ok"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -250,7 +251,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error preparing a version file for locking"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -260,7 +260,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error locking a version file"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -270,7 +269,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error reading the endianness of a version file"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -280,7 +278,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_BAD_ENDIAN_ERROR
);
obidebug
(
1
,
"
\n
Endianness of a version file is incorrect"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -290,7 +287,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error reading a version file"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -302,7 +298,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error writing a new version number in a version file"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -311,7 +306,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error writing a new version number in a version file"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -321,7 +315,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error preparing the unlocking of a version file"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
...
...
@@ -331,12 +324,10 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error unlocking a version file"
);
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
-
1
;
}
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
new_version_number
;
}
...
...
@@ -378,12 +369,13 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
return
-
1
;
}
free
(
version_file_name
);
// Lock the file
if
(
lockf
(
version_file_descriptor
,
F_LOCK
,
loc_size
)
<
0
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error locking a version file"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -393,7 +385,6 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error truncating a version file"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -403,7 +394,6 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error changing offset of a version file"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -415,7 +405,6 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error writing endianness of a version file"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -425,7 +414,6 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error writing version number in a version file"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -435,7 +423,6 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error preparing a version file for unlocking"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -445,13 +432,11 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error unlocking a version file"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
close
(
version_file_descriptor
);
free
(
version_file_name
);
return
version_number
;
}
...
...
@@ -511,12 +496,13 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
return
-
1
;
}
free
(
version_file_name
);
// Check that the version file size is ok
if
(
lseek
(
version_file_descriptor
,
0
,
SEEK_END
)
<
loc_size
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error testing if a version file size is ok"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -526,7 +512,6 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error setting the offset of a version file to 0"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -536,7 +521,6 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error reading the endianness of a version file"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -546,7 +530,6 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
{
obi_set_errno
(
OBICOL_BAD_ENDIAN_ERROR
);
obidebug
(
1
,
"
\n
Endianness of a version file is incorrect"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
...
...
@@ -556,12 +539,10 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error reading the latest version number in a version file"
);
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
-
1
;
}
free
(
version_file_name
);
close
(
version_file_descriptor
);
return
latest_version_number
;
...
...
@@ -731,13 +712,14 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
return
NULL
;
}
free
(
column_file_name
);
// Truncate the column file to the right size
if
(
ftruncate
(
column_file_descriptor
,
file_size
)
<
0
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error truncating a column file to the right size"
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
return
NULL
;
}
...
...
@@ -748,7 +730,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error allocating the memory for the column structure"
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
return
NULL
;
}
...
...
@@ -768,7 +749,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error mmapping the header of a column"
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
free
(
new_column
);
return
NULL
;
}
...
...
@@ -787,7 +767,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
obidebug
(
1
,
"
\n
Error mmapping the data of a column"
);
munmap
(
new_column
->
header
,
header_size
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
free
(
new_column
);
return
NULL
;
}
...
...
@@ -819,7 +798,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
obidebug
(
1
,
"
\n
Error 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
;
}
...
...
@@ -830,7 +808,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
// Fill the data with NA values
obi_ini_to_NA_values
(
new_column
,
0
,
nb_lines
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
new_column
;
...
...
@@ -900,6 +877,8 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
return
NULL
;
}
free
(
column_file_name
);
// Allocate the memory for the column structure
column
=
(
OBIDMS_column_p
)
malloc
(
sizeof
(
OBIDMS_column_t
));
if
(
column
==
NULL
)
...
...
@@ -907,7 +886,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error allocating the memory for a column structure"
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
return
NULL
;
}
...
...
@@ -927,7 +905,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error mmapping the header of a column"
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
free
(
column
);
return
NULL
;
}
...
...
@@ -952,7 +929,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
obidebug
(
1
,
"
\n
Error mmapping the data of a column"
);
munmap
(
column
->
header
,
header_size
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
free
(
column
);
return
NULL
;
}
...
...
@@ -968,14 +944,12 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
obidebug
(
1
,
"
\n
Error 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
);
return
column
;
...
...
@@ -989,7 +963,7 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
{
OBIDMS_column_p
column_to_clone
;
OBIDMS_column_p
new_column
;
index_t
nb_lines
;
index_t
nb_lines
;
index_t
nb_elements_per_line
;
size_t
data_size
;
OBIType_t
data_type
;
...
...
@@ -1123,13 +1097,14 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
return
-
1
;
}
free
(
column_file_name
);
// Unmap the data before truncating the file
data_size
=
obi_array_sizeof
((
column
->
header
)
->
data_type
,
(
column
->
header
)
->
line_count
,
(
column
->
header
)
->
nb_elements_per_line
);
if
(
munmap
(
column
->
data
,
data_size
)
<
0
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error munmapping the data of a column before truncating"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
...
...
@@ -1141,7 +1116,6 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error truncating a column file at the number of lines used"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
...
...
@@ -1159,7 +1133,6 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error re-mmapping the data of a column after truncating"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
...
...
@@ -1167,7 +1140,6 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
// Set line_count to the new line count
(
column
->
header
)
->
line_count
=
new_line_count
;
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
0
;
...
...
@@ -1213,6 +1185,8 @@ int obi_enlarge_column(OBIDMS_column_p column)
return
-
1
;
}
free
(
column_file_name
);
// Calculate the new file size
old_line_count
=
(
column
->
header
)
->
line_count
;
new_line_count
=
old_line_count
*
COLUMN_GROWTH_FACTOR
;
...
...
@@ -1221,7 +1195,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error enlarging a column file: new line count greater than the maximum allowed"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
...
...
@@ -1235,7 +1208,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error enlarging a column file"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
...
...
@@ -1255,7 +1227,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error re-mmapping the data of a column after enlarging the file"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
...
...
@@ -1268,7 +1239,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error munmapping the data of a column before enlarging"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
...
...
@@ -1285,7 +1255,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error re-mmapping the data of a column after enlarging the file"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
...
...
@@ -1297,7 +1266,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
// Initialize new data lines to NA
obi_ini_to_NA_values
(
column
,
old_line_count
,
new_line_count
-
old_line_count
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
0
;
...
...
@@ -1418,6 +1386,8 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
return
NULL
;
}
free
(
column_file_name
);
// Fill the header structure
header
=
mmap
(
NULL
,
header_size
,
...
...
@@ -1432,13 +1402,11 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error mmapping the header of a column"
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
return
NULL
;
}
// TODO Check endianness?
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
header
;
...
...
src/obidmscolumn.h
View file @
05e3956a
...
...
@@ -341,6 +341,8 @@ index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const cha
/**
* @brief Formats a date in a way that is easy to read.
*
* @warning The pointer returned must be freed by the caller.
*
* @param date A date.
*
* @returns The date formatted in a way that is easy to read.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment