2021-03-09 01:16:23 +01:00
|
|
|
#+TITLE: Error handling
|
|
|
|
#+SETUPFILE: ../docs/theme.setup
|
|
|
|
|
2021-03-10 12:58:38 +01:00
|
|
|
* Headers :noexport:
|
2021-03-09 01:16:23 +01:00
|
|
|
|
|
|
|
#+NAME: filename
|
|
|
|
#+begin_src elisp tangle: no
|
|
|
|
(file-name-nondirectory (substring buffer-file-name 0 -4))
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
#+begin_src c :tangle (eval c)
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "qmckl_error.h"
|
|
|
|
#+end_src
|
2021-03-05 03:45:30 +01:00
|
|
|
|
2021-03-09 01:16:23 +01:00
|
|
|
#+begin_src c :tangle (eval c_test) :noweb yes
|
2021-03-05 03:45:30 +01:00
|
|
|
#include "qmckl.h"
|
|
|
|
#include "munit.h"
|
2021-03-09 01:16:23 +01:00
|
|
|
MunitResult test_<<filename()>>() {
|
|
|
|
#+end_src
|
2021-03-05 03:45:30 +01:00
|
|
|
|
2021-03-18 18:02:06 +01:00
|
|
|
#+begin_src c :comments org :tangle (eval h)
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#+end_src
|
2021-03-10 12:58:38 +01:00
|
|
|
*
|
|
|
|
:PROPERTIES:
|
|
|
|
:UNNUMBERED: t
|
|
|
|
:END:
|
2021-03-05 03:45:30 +01:00
|
|
|
|
2021-03-09 01:16:23 +01:00
|
|
|
The library should never make the calling programs abort, nor
|
|
|
|
perform any input/output operations. This decision has to be taken
|
|
|
|
by the developer of the code calling the library.
|
2021-03-05 03:45:30 +01:00
|
|
|
|
2021-03-09 01:16:23 +01:00
|
|
|
All the functions return with an <<<exit code>>>, defined as
|
|
|
|
#+NAME: type-exit-code
|
|
|
|
#+begin_src c :comments org :tangle (eval h)
|
2021-03-05 03:45:30 +01:00
|
|
|
typedef int32_t qmckl_exit_code;
|
2021-03-09 01:16:23 +01:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
The exit code returns the completion status of the function to the
|
2021-03-10 12:58:38 +01:00
|
|
|
calling program. When a function call completed successfully,
|
|
|
|
~QMCKL_SUCCESS~ is returned. If one of the functions of
|
2021-03-09 01:16:23 +01:00
|
|
|
the library fails to complete the requested task, an appropriate
|
|
|
|
error code is returned to the program.
|
|
|
|
|
|
|
|
Here is the complete list of exit codes.
|
|
|
|
|
|
|
|
#+NAME: table-exit-codes
|
|
|
|
| ~QMCKL_SUCCESS~ | 0 |
|
|
|
|
| ~QMCKL_INVALID_ARG_1~ | 1 |
|
|
|
|
| ~QMCKL_INVALID_ARG_2~ | 2 |
|
|
|
|
| ~QMCKL_INVALID_ARG_3~ | 3 |
|
|
|
|
| ~QMCKL_INVALID_ARG_4~ | 4 |
|
|
|
|
| ~QMCKL_INVALID_ARG_5~ | 5 |
|
|
|
|
| ~QMCKL_INVALID_ARG_6~ | 6 |
|
|
|
|
| ~QMCKL_INVALID_ARG_7~ | 7 |
|
|
|
|
| ~QMCKL_INVALID_ARG_8~ | 8 |
|
|
|
|
| ~QMCKL_INVALID_ARG_9~ | 9 |
|
|
|
|
| ~QMCKL_INVALID_ARG_10~ | 10 |
|
2021-03-10 12:58:38 +01:00
|
|
|
| ~QMCKL_FAILURE~ | 101 |
|
|
|
|
| ~QMCKL_ERRNO~ | 102 |
|
|
|
|
| ~QMCKL_INVALID_CONTEXT~ | 103 |
|
|
|
|
| ~QMCKL_ALLOCATION_FAILED~ | 104 |
|
|
|
|
| ~QMCKL_INVALID_EXIT_CODE~ | 105 |
|
2021-03-09 01:16:23 +01:00
|
|
|
|
|
|
|
# We need to force Emacs not to indent the Python code:
|
|
|
|
# -*- org-src-preserve-indentation: t
|
2021-03-10 12:58:38 +01:00
|
|
|
|
|
|
|
#+begin_src python :var table=table-exit-codes :results drawer :exports none
|
2021-03-05 03:45:30 +01:00
|
|
|
""" This script generates the C and Fortran constants for the error
|
|
|
|
codes from the org-mode table.
|
|
|
|
"""
|
|
|
|
|
2021-03-10 12:58:38 +01:00
|
|
|
result = [ "#+begin_src c :comments org :tangle (eval h) :exports none" ]
|
2021-03-05 03:45:30 +01:00
|
|
|
for (text, code) in table:
|
|
|
|
text=text.replace("~","")
|
|
|
|
result += [ f"#define {text:30s} {code:d}" ]
|
2021-03-09 01:16:23 +01:00
|
|
|
result += [ "#+end_src" ]
|
2021-03-05 03:45:30 +01:00
|
|
|
|
|
|
|
result += [ "" ]
|
|
|
|
|
2021-03-10 12:58:38 +01:00
|
|
|
result += [ "#+begin_src f90 :comments org :tangle (eval fh) :exports none" ]
|
2021-03-05 03:45:30 +01:00
|
|
|
for (text, code) in table:
|
|
|
|
text=text.replace("~","")
|
|
|
|
result += [ f" integer, parameter :: {text:30s} = {code:d}" ]
|
2021-03-09 01:16:23 +01:00
|
|
|
result += [ "#+end_src" ]
|
2021-03-05 03:45:30 +01:00
|
|
|
|
|
|
|
return '\n'.join(result)
|
|
|
|
|
2021-03-09 01:16:23 +01:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
:results:
|
2021-03-10 12:58:38 +01:00
|
|
|
#+begin_src c :comments org :tangle (eval h) :exports none
|
2021-03-09 01:16:23 +01:00
|
|
|
#define QMCKL_SUCCESS 0
|
|
|
|
#define QMCKL_INVALID_ARG_1 1
|
|
|
|
#define QMCKL_INVALID_ARG_2 2
|
|
|
|
#define QMCKL_INVALID_ARG_3 3
|
|
|
|
#define QMCKL_INVALID_ARG_4 4
|
|
|
|
#define QMCKL_INVALID_ARG_5 5
|
|
|
|
#define QMCKL_INVALID_ARG_6 6
|
|
|
|
#define QMCKL_INVALID_ARG_7 7
|
|
|
|
#define QMCKL_INVALID_ARG_8 8
|
|
|
|
#define QMCKL_INVALID_ARG_9 9
|
|
|
|
#define QMCKL_INVALID_ARG_10 10
|
2021-03-10 12:58:38 +01:00
|
|
|
#define QMCKL_FAILURE 101
|
|
|
|
#define QMCKL_ERRNO 102
|
|
|
|
#define QMCKL_INVALID_CONTEXT 103
|
|
|
|
#define QMCKL_ALLOCATION_FAILED 104
|
|
|
|
#define QMCKL_INVALID_EXIT_CODE 105
|
2021-03-09 01:16:23 +01:00
|
|
|
#+end_src
|
|
|
|
|
2021-03-10 12:58:38 +01:00
|
|
|
#+begin_src f90 :comments org :tangle (eval fh) :exports none
|
2021-03-09 01:16:23 +01:00
|
|
|
integer, parameter :: QMCKL_SUCCESS = 0
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_1 = 1
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_2 = 2
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_3 = 3
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_4 = 4
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_5 = 5
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_6 = 6
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_7 = 7
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_8 = 8
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_9 = 9
|
|
|
|
integer, parameter :: QMCKL_INVALID_ARG_10 = 10
|
2021-03-10 12:58:38 +01:00
|
|
|
integer, parameter :: QMCKL_FAILURE = 101
|
|
|
|
integer, parameter :: QMCKL_ERRNO = 102
|
|
|
|
integer, parameter :: QMCKL_INVALID_CONTEXT = 103
|
|
|
|
integer, parameter :: QMCKL_ALLOCATION_FAILED = 104
|
|
|
|
integer, parameter :: QMCKL_INVALID_EXIT_CODE = 105
|
2021-03-09 01:16:23 +01:00
|
|
|
#+end_src
|
|
|
|
:end:
|
2021-03-05 03:45:30 +01:00
|
|
|
|
2021-03-10 12:58:38 +01:00
|
|
|
* End of files :noexport:
|
2021-03-05 03:45:30 +01:00
|
|
|
|
2021-03-10 12:58:38 +01:00
|
|
|
** Test
|
2021-03-09 01:16:23 +01:00
|
|
|
#+begin_src c :comments link :tangle (eval c_test)
|
2021-03-05 03:45:30 +01:00
|
|
|
return MUNIT_OK;
|
|
|
|
}
|
2021-03-09 01:16:23 +01:00
|
|
|
#+end_src
|
2021-03-05 03:45:30 +01:00
|
|
|
|
2021-03-09 01:16:23 +01:00
|
|
|
# -*- mode: org -*-
|
|
|
|
# vim: syntax=c
|
2021-03-05 03:45:30 +01:00
|
|
|
|
|
|
|
|