diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2010-12-13 15:15:09 -0800 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2010-12-13 15:15:09 -0800 |
commit | d8ea4f87e3e5a44985f961a2def83612b5c90c9a (patch) | |
tree | 966c0f5d7c1d8c98d83c09c9fb5dcf14afab92ea /src/cstore/cstore.hpp | |
parent | ab2f5d520eb46a6f407c396413523256803814fe (diff) | |
download | vyatta-cfg-d8ea4f87e3e5a44985f961a2def83612b5c90c9a.tar.gz vyatta-cfg-d8ea4f87e3e5a44985f961a2def83612b5c90c9a.zip |
make the library croak when internal error occurs in perl context.
* extend output/assert mechanism and simplify code.
* when handling internal error, automatically detect perl context and croak if the library is used from perl.
Diffstat (limited to 'src/cstore/cstore.hpp')
-rw-r--r-- | src/cstore/cstore.hpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/cstore/cstore.hpp b/src/cstore/cstore.hpp index 872fe1e..9a039af 100644 --- a/src/cstore/cstore.hpp +++ b/src/cstore/cstore.hpp @@ -16,26 +16,27 @@ #ifndef _CSTORE_H_ #define _CSTORE_H_ +#include <cstdarg> #include <vector> #include <string> #include <tr1/unordered_map> #include <cli_cstore.h> -#define exit_internal(fmt, args...) do \ - { \ - output_internal("[%s:%d] " fmt, __FILE__, __LINE__ , ##args); \ - exit(-1); \ - } while (0); +/* declare perl internal functions. just need these two so don't include + * all the perl headers. + */ +extern "C" void Perl_croak_nocontext(const char* pat, ...) + __attribute__((noreturn)) + __attribute__((format(__printf__,1,2))) + __attribute__((nonnull(1))); + +extern "C" void* Perl_get_context(void) + __attribute__((warn_unused_result)); -#define ASSERT_IN_SESSION do \ - { \ - if (!inSession()) { \ - output_user("Internal error: calling %s() without config session\n", \ - __func__); \ - exit_internal("calling %s() without config session\n", __func__); \ - } \ - } while (0); +#define ASSERT_IN_SESSION assert_internal(inSession(), \ + "calling %s() without config session", \ + __func__); /* macros for saving/restoring paths. @@ -300,7 +301,10 @@ public: protected: ////// functions for subclasses void output_user(const char *fmt, ...); + void output_user_err(const char *fmt, ...); void output_internal(const char *fmt, ...); + void exit_internal(const char *fmt, ...); + void assert_internal(bool cond, const char *fmt, ...); private: ////// member class @@ -480,6 +484,11 @@ private: void shell_escape_squotes(string& str); void print_str_vec(const char *pre, const char *post, const vector<string>& vec, const char *quote); + + // output functions + void voutput_user(FILE *out, FILE *dout, const char *fmt, va_list alist); + void voutput_internal(const char *fmt, va_list alist); + void vexit_internal(const char *fmt, va_list alist); }; #endif /* _CSTORE_H_ */ |