From 09c8f9700f78c3938a5fc17f9ee2bac4256cc74d Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 29 Mar 2021 01:39:12 +0200 Subject: [PATCH] Fixed const in munit and tests --- src/qmckl_context.org | 6 +----- src/qmckl_error.org | 14 ++++++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/qmckl_context.org b/src/qmckl_context.org index 65bfb48..e195336 100644 --- a/src/qmckl_context.org +++ b/src/qmckl_context.org @@ -586,11 +586,7 @@ qmckl_exit_code qmckl_context_remove_memory(qmckl_context context, qmckl_unlock(context); - if (alloc != NULL) { - return QMCKL_SUCCESS; - } else { - return QMCKL_DEALLOCATION_FAILED; - } + return QMCKL_SUCCESS; } #+end_src diff --git a/src/qmckl_error.org b/src/qmckl_error.org index 1c9f3de..4f52854 100644 --- a/src/qmckl_error.org +++ b/src/qmckl_error.org @@ -145,7 +145,8 @@ return '\n'.join(result) : 128 #+begin_src c :comments org :tangle (eval h) :exports none :noweb yes -void qmckl_string_of_error(qmckl_exit_code error, char string[<>]); +const char* qmckl_string_of_error(const qmckl_exit_code error); +void qmckl_string_of_error_f(const qmckl_exit_code error, char result[<>]); #+end_src The text strings are extracted from the previous table. @@ -161,7 +162,7 @@ for (text, code, message) in table: text = text.replace("~","") message = message.replace("'",'"') result += [ f"""case {text}: - strncpy(string,{message},<>); + return {message}; break;""" ] return '\n'.join(result) @@ -169,17 +170,22 @@ return '\n'.join(result) # Source #+begin_src c :comments org :tangle (eval c) :noweb yes -void qmckl_string_of_error(qmckl_exit_code error, char string[<>]) { +const char* qmckl_string_of_error(const qmckl_exit_code error) { switch (error) { <> } + return "Unknown error"; +} + +void qmckl_string_of_error_f(const qmckl_exit_code error, char result[<>]) { + strncpy(result, qmckl_string_of_error(error), <>); } #+end_src # Fortran interface #+begin_src f90 :tangle (eval fh) :noexport :noweb yes interface - subroutine qmckl_string_of_error (error, string) bind(C) + subroutine qmckl_string_of_error (error, string) bind(C, name='qmckl_string_of_error_f') use, intrinsic :: iso_c_binding integer (c_int32_t), intent(in), value :: error character, intent(out) :: string(<>)