Wietse Venema:
Hallvard Breien Furuseth:
wietse@porcupine.org writes:
Hallvard Breien Furuseth:
I suppose we could s/assert(foo)/mdb_assert(mc, foo)/ when that compiles so it can report env, txn, dbi. Howard, should I do that?
That was my idea. Allow me to code up an example, it is simpler than arguing in the abstract.
By all means, but I expect we understand each other. I just needed to know how muchimpact this needs to have on the lmdb's code. The answer is it must walk all over it. And now that I think of it, it'll likely introduce merge conflicts in every outstanding branch of any size. So my preference is not to do this just yet.
I am settling for less, and come with a few-line change, so that LMDB might still end up in this month's stable Postfix release.
Hang on for a few more minutes.
Below is my "least painful" patch for both parties. What do you think?
Wietse
*** ./work/mdb-mdb/libraries/liblmdb/mdb.c- Tue Nov 12 11:10:33 2013 --- ./work/mdb-mdb/libraries/liblmdb/mdb.c Thu Jan 2 16:30:47 2014 *************** *** 65,71 **** #include <fcntl.h> #endif
- #include <assert.h> #include <errno.h> #include <limits.h> #include <stddef.h> --- 65,70 ---- *************** *** 146,151 **** --- 145,155 ---- # error "Two's complement, reasonably sized integer types, please" #endif
+ /* assert(3) clone. Move this to the project-correct location. */ + static void mdb_assert(const char *, const char *, int, const char *); + #define assert(e) ((e) ? (void) 0 : mdb_assert(__func__, __FILE__, \ + __LINE__, #e)) + /** @defgroup internal MDB Internals * @{ */ *************** *** 3288,3293 **** --- 3292,3311 ---- return MDB_SUCCESS; }
+ void + (*mdb_assert_cb)(const char *,...); + + static void + mdb_assert(const char *func, const char *file, int line, const char *text) + { + if (mdb_assert_cb != 0) + mdb_assert_cb("Assertion failed: file %s, line %d, function %s: %s", + file, line, func, text); + fprintf(stderr, "Assertion failed: file %s, line %d, function %s: %s\n", + file, line, func, text); + abort(); + } + static int mdb_env_map(MDB_env *env, void *addr, int newsize) { *** ./work/mdb-mdb/libraries/liblmdb/lmdb.h- Tue Nov 12 11:10:33 2013 --- ./work/mdb-mdb/libraries/liblmdb/lmdb.h Thu Jan 2 16:01:37 2014 *************** *** 1429,1434 **** --- 1429,1441 ---- * @return 0 on success, non-zero on failure. */ int mdb_reader_check(MDB_env *env, int *dead); + + /** @brief Notify application of assertion failure. + * This should become obsolete as lmdb's error handling matures. + * @param[in] fmt The assertion message, not including newline. + */ + extern void (*mdb_assert_cb)(const char *fmt, ...); + /** @} */
#ifdef __cplusplus