From 721352cb898c464de2cc7ba7fdfc029897f6ef1f Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 11 Aug 2021 16:01:36 +0300 Subject: [PATCH] add missing support for reading single string attributes --- src/pytrexio.i | 6 ++++++ src/templates_front/templator_front.org | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pytrexio.i b/src/pytrexio.i index f19cb6d..df460a7 100644 --- a/src/pytrexio.i +++ b/src/pytrexio.i @@ -34,13 +34,19 @@ */ %apply int *OUTPUT { int32_t* const num}; %apply int *OUTPUT { int64_t* const num}; + /* Does not work for arrays (SIGSEGV) */ /* This enables access to trexio_[...]_read_dset_str_low set of functions in order to return one long string with TREXIO_DELIM delimeter as 2-nd argument of output tuple */ %include +/* This enables read of long strings with TREXIO_DELIM delimeters that can be further converted into an array of string */ %cstring_bounded_output(char* dset_out, 4096); +/* This enables read of single string attributes with pre-defined max_str_len + for Python we pre-define max_str_len = PYTREXIO_MAX_STR_LENGTH everywhere for simplicity +*/ +%cstring_output_maxsize(char* const str_out, const uint32_t max_str_len); /* [WIP] TREXIO back ends and exit codes can be redefined in the SWIG target language using %ignore and further #define statements (instead of disabling the type cast in the trexio.h file) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 7cbf128..e9a2ef9 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -2289,27 +2289,27 @@ def read_$group_dset$(trexio_file): #+begin_src c :tangle hrw_attr_str_front.h :exports none trexio_exit_code trexio_has_$group_str$(trexio_t* const file); -trexio_exit_code trexio_read_$group_str$(trexio_t* const file, char* const str, const uint32_t max_str_len); +trexio_exit_code trexio_read_$group_str$(trexio_t* const file, char* const str_out, const uint32_t max_str_len); trexio_exit_code trexio_write_$group_str$(trexio_t* const file, const char* str, const uint32_t max_str_len); #+end_src #+begin_src c :tangle read_attr_str_front.c trexio_exit_code -trexio_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t max_str_len) +trexio_read_$group_str$ (trexio_t* const file, char* const str_out, const uint32_t max_str_len) { if (file == NULL) return TREXIO_INVALID_ARG_1; - if (str == NULL) return TREXIO_INVALID_ARG_2; + if (str_out == NULL) return TREXIO_INVALID_ARG_2; if (max_str_len <= 0) return TREXIO_INVALID_ARG_3; switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_read_$group_str$(file, str, max_str_len); + return trexio_text_read_$group_str$(file, str_out, max_str_len); break; case TREXIO_HDF5: - return trexio_hdf5_read_$group_str$(file, str, max_str_len); + return trexio_hdf5_read_$group_str$(file, str_out, max_str_len); break; /* case TREXIO_JSON: