From 57655a83448c29fbb9820c293553eae25ac02a2d Mon Sep 17 00:00:00 2001 From: q-posev Date: Thu, 6 May 2021 17:44:31 +0200 Subject: [PATCH] add error message for an attempt to overwrite dimensioning variables --- src/templates_front/templator_front.org | 35 ++++++++++++++----------- src/templates_hdf5/templator_hdf5.org | 5 ++-- tests/test.c | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index dc32cce..124dff7 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -114,22 +114,23 @@ typedef int32_t trexio_exit_code; ** Error handling #+NAME: table-exit-codes - | Macro | Code | Description | - |----------------------------+------+----------------------| - | ~TREXIO_FAILURE~ | -1 | 'Unknown failure' | - | ~TREXIO_SUCCESS~ | 0 | 'Success' | - | ~TREXIO_INVALID_ARG_1~ | 1 | 'Invalid argument 1' | - | ~TREXIO_INVALID_ARG_2~ | 2 | 'Invalid argument 2' | - | ~TREXIO_INVALID_ARG_3~ | 3 | 'Invalid argument 3' | - | ~TREXIO_INVALID_ARG_4~ | 4 | 'Invalid argument 4' | - | ~TREXIO_INVALID_ARG_5~ | 5 | 'Invalid argument 5' | - | ~TREXIO_END~ | 6 | 'End of file' | - | ~TREXIO_READONLY~ | 7 | 'Read-only file' | - | ~TREXIO_ERRNO~ | 8 | strerror(errno) | - | ~TREXIO_INVALID_ID~ | 9 | 'Invalid ID' | - | ~TREXIO_ALLOCATION_FAILED~ | 10 | 'Allocation failed' | - | ~TREXIO_HAS_NOT~ | 11 | 'Element absent' | - | ~TREXIO_INVALID_NUM~ | 12 | 'Invalid exit code' | + | Macro | Code | Description | + |-----------------------------+------+--------------------------------| + | ~TREXIO_FAILURE~ | -1 | 'Unknown failure' | + | ~TREXIO_SUCCESS~ | 0 | 'Success' | + | ~TREXIO_INVALID_ARG_1~ | 1 | 'Invalid argument 1' | + | ~TREXIO_INVALID_ARG_2~ | 2 | 'Invalid argument 2' | + | ~TREXIO_INVALID_ARG_3~ | 3 | 'Invalid argument 3' | + | ~TREXIO_INVALID_ARG_4~ | 4 | 'Invalid argument 4' | + | ~TREXIO_INVALID_ARG_5~ | 5 | 'Invalid argument 5' | + | ~TREXIO_END~ | 6 | 'End of file' | + | ~TREXIO_READONLY~ | 7 | 'Read-only file' | + | ~TREXIO_ERRNO~ | 8 | strerror(errno) | + | ~TREXIO_INVALID_ID~ | 9 | 'Invalid ID' | + | ~TREXIO_ALLOCATION_FAILED~ | 10 | 'Allocation failed' | + | ~TREXIO_HAS_NOT~ | 11 | 'Element absent' | + | ~TREXIO_INVALID_NUM~ | 12 | 'Invalid exit code' | + | ~TREXIO_NUM_ALREADY_EXISTS~ | 13 | 'This variable already exists' | # We need to force Emacs not to indent the Python code: # -*- org-src-preserve-indentation: t @@ -175,6 +176,7 @@ return '\n'.join(result) #define TREXIO_ALLOCATION_FAILED ((trexio_exit_code) 10) #define TREXIO_HAS_NOT ((trexio_exit_code) 11) #define TREXIO_INVALID_NUM ((trexio_exit_code) 12) + #define TREXIO_NUM_ALREADY_EXISTS ((trexio_exit_code) 13) #+end_src #+begin_src f90 :tangle prefix_fortran.f90 :exports none @@ -192,6 +194,7 @@ return '\n'.join(result) integer(trexio_exit_code), parameter :: TREXIO_ALLOCATION_FAILED = 10 integer(trexio_exit_code), parameter :: TREXIO_HAS_NOT = 11 integer(trexio_exit_code), parameter :: TREXIO_INVALID_NUM = 12 + integer(trexio_exit_code), parameter :: TREXIO_NUM_ALREADY_EXISTS = 13 #+end_src :end: diff --git a/src/templates_hdf5/templator_hdf5.org b/src/templates_hdf5/templator_hdf5.org index d843450..7cfa148 100644 --- a/src/templates_hdf5/templator_hdf5.org +++ b/src/templates_hdf5/templator_hdf5.org @@ -235,9 +235,8 @@ trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num) if (infile_num != num) { if (infile_num != 0) { - printf("%lu -> %lu %s \n", num, infile_num, - "This variable already exists. Overwriting it is not supported"); - return TREXIO_FAILURE; + + return TREXIO_NUM_ALREADY_EXISTS; } else { diff --git a/tests/test.c b/tests/test.c index 60cf46a..9dc4c86 100644 --- a/tests/test.c +++ b/tests/test.c @@ -77,7 +77,7 @@ int test_h5write() { // should not work: try to overwrite the nucleus_num rc = trexio_write_nucleus_num(file,25); - assert (rc != TREXIO_SUCCESS); + assert (rc == TREXIO_NUM_ALREADY_EXISTS); // close current session rc = trexio_close(file);