Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libloc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
libloc
Commits
8fcb5bc7
Commit
8fcb5bc7
authored
Aug 23, 2022
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
database: country: Return better error codes
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
21dfa79e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
src/database.c
src/database.c
+7
-1
src/python/database.c
src/python/database.c
+17
-2
No files found.
src/database.c
View file @
8fcb5bc7
...
...
@@ -954,6 +954,12 @@ LOC_EXPORT int loc_database_get_country(struct loc_database* db,
off_t
lo
=
0
;
off_t
hi
=
db
->
country_objects
.
count
-
1
;
// Check if the country code is valid
if
(
!
loc_country_code_is_valid
(
code
))
{
errno
=
EINVAL
;
return
1
;
}
#ifdef ENABLE_DEBUG
// Save start time
clock_t
start
=
clock
();
...
...
@@ -996,7 +1002,7 @@ LOC_EXPORT int loc_database_get_country(struct loc_database* db,
// Nothing found
*
country
=
NULL
;
return
1
;
return
0
;
}
// Enumerator
...
...
src/python/database.c
View file @
8fcb5bc7
...
...
@@ -166,17 +166,32 @@ static PyObject* Database_get_as(DatabaseObject* self, PyObject* args) {
}
static
PyObject
*
Database_get_country
(
DatabaseObject
*
self
,
PyObject
*
args
)
{
struct
loc_country
*
country
=
NULL
;
const
char
*
country_code
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"s"
,
&
country_code
))
return
NULL
;
struct
loc_country
*
country
;
// Fetch the country
int
r
=
loc_database_get_country
(
self
->
db
,
&
country
,
country_code
);
if
(
r
)
{
Py_RETURN_NONE
;
switch
(
errno
)
{
case
EINVAL
:
PyErr_SetString
(
PyExc_ValueError
,
"Invalid country code"
);
break
;
default:
PyErr_SetFromErrno
(
PyExc_OSError
);
break
;
}
return
NULL
;
}
// No result
if
(
!
country
)
Py_RETURN_NONE
;
PyObject
*
obj
=
new_country
(
&
CountryType
,
country
);
loc_country_unref
(
country
);
...
...
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