diff --git a/doc/src/Library_utility.rst b/doc/src/Library_utility.rst index e555b79c0b..b9cd568da9 100644 --- a/doc/src/Library_utility.rst +++ b/doc/src/Library_utility.rst @@ -20,6 +20,7 @@ functions. They do not directly call the LAMMPS library. - :cpp:func:`lammps_force_timeout` - :cpp:func:`lammps_has_error` - :cpp:func:`lammps_get_last_error_message` +- :cpp:func:`lammps_set_show_error` - :cpp:func:`lammps_python_api_version` The :cpp:func:`lammps_free` function is a clean-up function to free @@ -110,6 +111,11 @@ where such memory buffers were allocated that require the use of ----------------------- +.. doxygenfunction:: lammps_set_show_error + :project: progguide + +----------------------- + .. doxygenfunction:: lammps_python_api_version :project: progguide diff --git a/python/lammps/core.py b/python/lammps/core.py index 92e73adc1c..537472d636 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -348,6 +348,7 @@ class lammps(object): self.lib.lammps_get_last_error_message.argtypes = [c_void_p, c_char_p, c_int] self.lib.lammps_get_last_error_message.restype = c_int self.lib.lammps_set_show_error.argtypes = [c_void_p, c_int] + self.lib.lammps_set_show_error.restype = c_int self.lib.lammps_extract_global.argtypes = [c_void_p, c_char_p] self.lib.lammps_extract_global_datatype.argtypes = [c_void_p, c_char_p] @@ -2139,6 +2140,8 @@ class lammps(object): :param flag: enable (1) or disable (0) printing of error message :type flag: int + :return: previous setting of the flag + :rtype: int """ self.lib.lammps_set_show_error(self.lmp, flag) diff --git a/src/error.cpp b/src/error.cpp index 25a172a07e..3e17fec2e8 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -315,9 +315,12 @@ void Error::set_last_error(const char *msg, ErrorType type) /* ---------------------------------------------------------------------- enable or disable printing error messages. for use with library interface. if flag = 0 only last error message and type are updated. + returns the previous setting. ------------------------------------------------------------------------- */ -void Error::set_show_error(const int flag) +int Error::set_show_error(const int flag) { + int oldflag = show_error showerror = flag; + return oldflag; } diff --git a/src/error.h b/src/error.h index 668cdce2dd..5f5b349bc8 100644 --- a/src/error.h +++ b/src/error.h @@ -98,7 +98,7 @@ class Error : protected Pointers { std::string get_last_error() const; ErrorType get_last_error_type() const; void set_last_error(const char *msg, ErrorType type = ERROR_NORMAL); - void set_show_error(const int flag); + int set_show_error(const int flag); private: std::string last_error_message; diff --git a/src/library.cpp b/src/library.cpp index c1d47022a0..23da26cb03 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -7342,17 +7342,21 @@ This function can be used to stop LAMMPS from printing error messages it may be left to the code calling the library interface whether to check for them, and retrieve and print error messages using the library interface functions :cpp:func:`lammps_has_error` and -:cpp:func:`lammps_get_last_error_message`. +:cpp:func:`lammps_get_last_error_message`. The function returns the +previous setting so that one can easily override the setting +temporarily and restore it afterwards. \endverbatim * * \param handle pointer to a previously created LAMMPS instance cast to ``void *`` or NULL * \param flag enable (not 0) or disable (0) printing error messages before throwing exception + * \return previous setting of the flag */ -void lammps_set_show_error(void *handle, const int flag) +int lammps_set_show_error(void *handle, const int flag) { LAMMPS *lmp = (LAMMPS *) handle; - if (lmp && lmp->error) lmp->error->set_show_error(flag); + if (lmp && lmp->error) return lmp->error->set_show_error(flag); + return 1; // default value } /* ---------------------------------------------------------------------- */ diff --git a/src/library.h b/src/library.h index 89a9624280..1744d99fcf 100644 --- a/src/library.h +++ b/src/library.h @@ -312,7 +312,7 @@ void lammps_force_timeout(void *handle); int lammps_has_error(void *handle); int lammps_get_last_error_message(void *handle, char *buffer, int buf_size); -void lammps_set_show_error(void *handle, const int flag); +int lammps_set_show_error(void *handle, const int flag); int lammps_python_api_version();