Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
librelaxisloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Klemm, Carl Philipp
librelaxisloader
Commits
51f713a0
Commit
51f713a0
authored
Apr 8, 2024
by
Carl Philipp Klemm
Browse files
Options
Downloads
Patches
Plain Diff
Improve error handling and reporting when the relaxis file is invalid
parent
34a1526c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
relaxisloader.c
+48
-20
48 additions, 20 deletions
relaxisloader.c
relaxisloader/relaxisloader.h
+9
-0
9 additions, 0 deletions
relaxisloader/relaxisloader.h
with
57 additions
and
20 deletions
relaxisloader.c
+
48
−
20
View file @
51f713a0
...
@@ -160,10 +160,19 @@ struct rlx_project** rlx_get_projects(struct rlxfile* file, size_t* length)
...
@@ -160,10 +160,19 @@ struct rlx_project** rlx_get_projects(struct rlxfile* file, size_t* length)
return
NULL
;
return
NULL
;
}
}
rows
++
;
rows
++
;
assert
(
cols
==
3
);
if
(
cols
!=
3
)
{
sqlite3_free_table
(
table
);
file
->
error
=
RLX_ERR_FMT
;
return
NULL
;
}
struct
rlx_project
**
projects
=
malloc
(
sizeof
(
*
projects
)
*
(
rows
));
struct
rlx_project
**
projects
=
malloc
(
sizeof
(
*
projects
)
*
(
rows
));
assert
(
projects
);
if
(
!
projects
)
{
sqlite3_free_table
(
table
);
file
->
error
=
RLX_ERR_OOM
;
return
NULL
;
}
if
(
length
)
if
(
length
)
*
length
=
rows
-
1
;
*
length
=
rows
-
1
;
...
@@ -199,10 +208,14 @@ static struct rlx_datapoint* rlx_get_datapoints(struct rlxfile* file, int id, si
...
@@ -199,10 +208,14 @@ static struct rlx_datapoint* rlx_get_datapoints(struct rlxfile* file, int id, si
*
length
=
0
;
*
length
=
0
;
return
NULL
;
return
NULL
;
}
}
assert
(
cols
==
3
);
if
(
cols
!=
3
)
{
file
->
error
=
RLX_ERR_FMT
;
sqlite3_free_table
(
table
);
return
NULL
;
}
if
(
rows
<
2
)
{
if
(
rows
<
2
)
{
file
->
error
=
-
100
;
file
->
error
=
RLX_ERR_NO_ENT
;
sqlite3_free_table
(
table
);
sqlite3_free_table
(
table
);
return
NULL
;
return
NULL
;
}
}
...
@@ -243,12 +256,15 @@ struct rlx_spectra* rlx_get_spectra(struct rlxfile* file, const struct rlx_proje
...
@@ -243,12 +256,15 @@ struct rlx_spectra* rlx_get_spectra(struct rlxfile* file, const struct rlx_proje
}
}
if
(
rows
<
2
)
{
if
(
rows
<
2
)
{
file
->
error
=
-
102
;
file
->
error
=
RLX_ERR_NON_EXIST_SPECTRA
;
sqlite3_free_table
(
table
);
return
NULL
;
}
if
(
cols
!=
6
)
{
file
->
error
=
RLX_ERR_FMT
;
sqlite3_free_table
(
table
);
sqlite3_free_table
(
table
);
return
NULL
;
return
NULL
;
}
}
assert
(
cols
==
6
);
struct
rlx_spectra
*
out
=
malloc
(
sizeof
(
*
out
));
struct
rlx_spectra
*
out
=
malloc
(
sizeof
(
*
out
));
out
->
id
=
id
;
out
->
id
=
id
;
...
@@ -301,10 +317,20 @@ int* rlx_get_spectra_ids(struct rlxfile* file, const struct rlx_project* project
...
@@ -301,10 +317,20 @@ int* rlx_get_spectra_ids(struct rlxfile* file, const struct rlx_project* project
}
}
++
rows
;
++
rows
;
printf
(
"%s: got %dx%d
\n
"
,
__func__
,
rows
,
cols
);
printf
(
"%s: got %dx%d
\n
"
,
__func__
,
rows
,
cols
);
assert
(
cols
==
1
);
if
(
cols
==
0
)
{
file
->
error
=
RLX_ERR_NO_ENT
;
sqlite3_free_table
(
table
);
return
NULL
;
}
else
if
(
cols
!=
1
)
{
file
->
error
=
RLX_ERR_FMT
;
sqlite3_free_table
(
table
);
return
NULL
;
}
if
(
rows
<
2
)
{
if
(
rows
<
2
)
{
file
->
error
=
-
101
;
file
->
error
=
RLX_ERR_NO_ENT
;
sqlite3_free_table
(
table
);
sqlite3_free_table
(
table
);
return
NULL
;
return
NULL
;
}
}
...
@@ -327,15 +353,15 @@ int rlx_get_float_arrays(const struct rlx_spectra *spectra, float **re, float **
...
@@ -327,15 +353,15 @@ int rlx_get_float_arrays(const struct rlx_spectra *spectra, float **re, float **
{
{
*
re
=
malloc
(
sizeof
(
float
)
*
spectra
->
length
);
*
re
=
malloc
(
sizeof
(
float
)
*
spectra
->
length
);
if
(
!*
re
)
if
(
!*
re
)
return
-
103
;
return
RLX_ERR_OOM
;
*
im
=
malloc
(
sizeof
(
float
)
*
spectra
->
length
);
*
im
=
malloc
(
sizeof
(
float
)
*
spectra
->
length
);
if
(
!*
im
)
if
(
!*
im
)
return
-
103
;
return
RLX_ERR_OOM
;
*
omega
=
malloc
(
sizeof
(
float
)
*
spectra
->
length
);
*
omega
=
malloc
(
sizeof
(
float
)
*
spectra
->
length
);
if
(
!*
omega
)
if
(
!*
omega
)
return
-
103
;
return
RLX_ERR_OOM
;
for
(
size_t
i
=
0
;
i
<
spectra
->
length
;
++
i
)
for
(
size_t
i
=
0
;
i
<
spectra
->
length
;
++
i
)
{
{
...
@@ -351,15 +377,15 @@ int rlx_get_double_arrays(const struct rlx_spectra *spectra, double **re, double
...
@@ -351,15 +377,15 @@ int rlx_get_double_arrays(const struct rlx_spectra *spectra, double **re, double
{
{
*
re
=
malloc
(
sizeof
(
double
)
*
spectra
->
length
);
*
re
=
malloc
(
sizeof
(
double
)
*
spectra
->
length
);
if
(
!*
re
)
if
(
!*
re
)
return
-
103
;
return
RLX_ERR_OOM
;
*
im
=
malloc
(
sizeof
(
double
)
*
spectra
->
length
);
*
im
=
malloc
(
sizeof
(
double
)
*
spectra
->
length
);
if
(
!*
im
)
if
(
!*
im
)
return
-
103
;
return
RLX_ERR_OOM
;
*
omega
=
malloc
(
sizeof
(
double
)
*
spectra
->
length
);
*
omega
=
malloc
(
sizeof
(
double
)
*
spectra
->
length
);
if
(
!*
omega
)
if
(
!*
omega
)
return
-
103
;
return
RLX_ERR_OOM
;
for
(
size_t
i
=
0
;
i
<
spectra
->
length
;
++
i
)
for
(
size_t
i
=
0
;
i
<
spectra
->
length
;
++
i
)
{
{
...
@@ -432,18 +458,20 @@ int rlx_get_errnum(const struct rlxfile* file)
...
@@ -432,18 +458,20 @@ int rlx_get_errnum(const struct rlxfile* file)
const
char
*
rlx_get_errnum_str
(
int
errnum
)
const
char
*
rlx_get_errnum_str
(
int
errnum
)
{
{
if
(
errnum
==
0
)
if
(
errnum
==
RLX_ERR_SUCESS
)
return
"Success"
;
return
"Success"
;
if
(
errnum
>
0
)
if
(
errnum
>
0
)
return
sqlite3_errstr
(
errnum
);
return
sqlite3_errstr
(
errnum
);
if
(
errnum
==
-
100
)
if
(
errnum
==
RLX_ERR_NO_ENT
)
return
"No sutch entry"
;
return
"No sutch entry"
;
if
(
errnum
==
-
101
)
if
(
errnum
==
RLX_ERR_NO_SPECTRA
)
return
"Project contains no spectra"
;
return
"Project contains no spectra"
;
if
(
errnum
==
-
102
)
if
(
errnum
==
RLX_ERR_NON_EXIST_SPECTRA
)
return
"Tried to load non existing spectra"
;
return
"Tried to load non existing spectra"
;
if
(
errnum
==
-
103
)
if
(
errnum
==
RLX_ERR_OOM
)
return
"Out of memory"
;
return
"Out of memory"
;
if
(
errnum
==
RLX_ERR_FMT
)
return
"Relaxis file is invalid"
;
return
"Unkown error"
;
return
"Unkown error"
;
}
}
This diff is collapsed.
Click to expand it.
relaxisloader/relaxisloader.h
+
9
−
0
View file @
51f713a0
...
@@ -31,6 +31,15 @@ API for use by librelaxisloader users.
...
@@ -31,6 +31,15 @@ API for use by librelaxisloader users.
* @{
* @{
*/
*/
enum
{
RLX_ERR_SUCESS
=
0
,
RLX_ERR_NO_ENT
=
-
100
,
RLX_ERR_NO_SPECTRA
=
-
101
,
RLX_ERR_NON_EXIST_SPECTRA
=
-
102
,
RLX_ERR_OOM
=
-
103
,
RLX_ERR_FMT
=
-
104
,
};
struct
rlxfile
;
struct
rlxfile
;
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment