aboutsummaryrefslogtreecommitdiffstats
path: root/common/logging.h
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-12-22 11:55:32 +0000
committerWerner Koch <[email protected]>2017-12-22 11:55:46 +0000
commitf3ba66781a07af2e32f5887e6e15acdd4822a431 (patch)
tree06d8e033bdf2298f0822727ebcc43690fb1d2a2a /common/logging.h
parentcommon: Use larger buffer for homedir in case of 64 bit UIDs. (diff)
downloadgnupg-f3ba66781a07af2e32f5887e6e15acdd4822a431.tar.gz
gnupg-f3ba66781a07af2e32f5887e6e15acdd4822a431.zip
kbx: Simplify by removing custom memory functions.
* kbx/keybox-util.c (keybox_set_malloc_hooks): Remove. (_keybox_malloc, _keybox_calloc, keybox_realloc) (_keybox_free): Remove. (keybox_file_rename): Remove. Was not used. * sm/gpgsm.c (main): Remove call to keybox_set_malloc_hooks. * kbx/kbxutil.c (main): Ditto. * kbx/keybox-defs.h: Remove all separate includes. Include util.h. remove convenience macros. * common/logging.h (return_if_fail): New. Originally from keybox-defs.h but now using log_debug. (return_null_if_fail): Ditto. (return_val_if_fail): Ditto. (never_reached): Ditto. -- Originally the KBX code was written to allow standalone use. However this required lot of ugliness like separate memory allocators and such. It also precludes the use of some standard functions from common due to their use of the common gnupg malloc functions. Dropping all that makes things easier. Minor disadvantages: the kbx call done for gpg will now use gcry malloc fucntions and not the standard malloc functions. This might be a bit slower but removing them even fixes a possible bug in keybox_tmp_names which is used in gpg and uses gpg's xfree which is actually gcry_free. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/logging.h')
-rw-r--r--common/logging.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/common/logging.h b/common/logging.h
index e1bf56b17..2225100cb 100644
--- a/common/logging.h
+++ b/common/logging.h
@@ -112,4 +112,30 @@ void log_printhex (const char *text, const void *buffer, size_t length);
void log_clock (const char *string);
+/* Some handy assertion macros which don't abort. */
+
+#define return_if_fail(expr) do { \
+ if (!(expr)) { \
+ log_debug ("%s:%d: assertion '%s' failed\n", \
+ __FILE__, __LINE__, #expr ); \
+ return; \
+ } } while (0)
+#define return_null_if_fail(expr) do { \
+ if (!(expr)) { \
+ log_debug ("%s:%d: assertion '%s' failed\n", \
+ __FILE__, __LINE__, #expr ); \
+ return NULL; \
+ } } while (0)
+#define return_val_if_fail(expr,val) do { \
+ if (!(expr)) { \
+ log_debug ("%s:%d: assertion '%s' failed\n", \
+ __FILE__, __LINE__, #expr ); \
+ return (val); \
+ } } while (0)
+#define never_reached() do { \
+ log_debug ("%s:%d: oops - should never get here\n", \
+ __FILE__, __LINE__ ); \
+ } while (0)
+
+
#endif /*GNUPG_COMMON_LOGGING_H*/