src/saxdb.h (struct saxdb_context): Declare, do not define.
(saxdb_jmp_buf): Declare new function.
src/saxdb.c (struct saxdb_context): Define.
(saxdb_write_db): Use saxdb_jmp_buf() instead of ctx.jbuf.
(write_database): Likewise.
(saxdb_jmp_buf): Define.
src/modcmd.c (cmd_dump_messages): Use saxdb_jmp_buf().
src/mod-helpserv.c (helpserv_log_request): Likewise.
if (!(ctx = saxdb_open_context(reqlog_f)))
return;
sprintf(key, "%s-%lu-%lu", req->hs->helpserv->nick, (unsigned long)req->opened, req->id);
if (!(ctx = saxdb_open_context(reqlog_f)))
return;
sprintf(key, "%s-%lu-%lu", req->hs->helpserv->nick, (unsigned long)req->opened, req->id);
- if ((res = setjmp(ctx->jbuf)) != 0) {
+ if ((res = setjmp(*saxdb_jmp_buf(ctx))) != 0) {
log_module(HS_LOG, LOG_ERROR, "Unable to log helpserv request: %s.", strerror(res));
} else {
saxdb_start_record(ctx, key, 1);
log_module(HS_LOG, LOG_ERROR, "Unable to log helpserv request: %s.", strerror(res));
} else {
saxdb_start_record(ctx, key, 1);
reply("MSG_INTERNAL_FAILURE");
return 0;
}
reply("MSG_INTERNAL_FAILURE");
return 0;
}
- if ((res = setjmp(ctx->jbuf)) != 0) {
- ctx->complex.used = 0; /* to avoid false assert()s in close */
+ if ((res = setjmp(*saxdb_jmp_buf(ctx))) != 0) {
saxdb_close_context(ctx);
fclose(pf);
reply("MCMSG_MESSAGE_DUMP_FAILED", strerror(res));
saxdb_close_context(ctx);
fclose(pf);
reply("MCMSG_MESSAGE_DUMP_FAILED", strerror(res));
+struct saxdb_context {
+ FILE *output;
+ unsigned int indent;
+ struct int_list complex;
+ jmp_buf jbuf;
+};
+
#define COMPLEX(CTX) ((CTX)->complex.used ? ((CTX)->complex.list[(CTX)->complex.used-1]) : 1)
static struct saxdb *last_db;
#define COMPLEX(CTX) ((CTX)->complex.used ? ((CTX)->complex.list[(CTX)->complex.used-1]) : 1)
static struct saxdb *last_db;
return 1;
}
start = time(NULL);
return 1;
}
start = time(NULL);
- if ((res = setjmp(ctx.jbuf)) || (res2 = db->writer(&ctx))) {
+ if ((res = setjmp(*saxdb_jmp_buf(&ctx))) || (res2 = db->writer(&ctx))) {
if (res) {
log_module(MAIN_LOG, LOG_ERROR, "Error writing to %s: %s", tmp_fname, strerror(res));
} else {
if (res) {
log_module(MAIN_LOG, LOG_ERROR, "Error writing to %s: %s", tmp_fname, strerror(res));
} else {
ctx.output = out;
ctx.indent = 0;
int_list_init(&ctx.complex);
ctx.output = out;
ctx.indent = 0;
int_list_init(&ctx.complex);
- if (!(res = setjmp(ctx.jbuf))) {
+ if (!(res = setjmp(*saxdb_jmp_buf(&ctx)))) {
write_database_helper(&ctx, db);
} else {
log_module(MAIN_LOG, LOG_ERROR, "Exception %d caught while writing to stream", res);
write_database_helper(&ctx, db);
} else {
log_module(MAIN_LOG, LOG_ERROR, "Exception %d caught while writing to stream", res);
+jmp_buf *
+saxdb_jmp_buf(struct saxdb_context *ctx) {
+ return &ctx->jbuf;
+}
+
+
void
saxdb_close_context(struct saxdb_context *ctx) {
assert(ctx->complex.used == 0);
void
saxdb_close_context(struct saxdb_context *ctx) {
assert(ctx->complex.used == 0);
DECLARE_LIST(int_list, int);
struct saxdb;
DECLARE_LIST(int_list, int);
struct saxdb;
-/* This definition should ONLY be used so callers of
- * saxdb_open_context() can initialize jbuf properly. */
-struct saxdb_context {
- FILE *output;
- unsigned int indent;
- struct int_list complex;
- jmp_buf jbuf;
-};
-
#define SAXDB_READER(NAME) int NAME(struct dict *db)
typedef SAXDB_READER(saxdb_reader_func_t);
#define SAXDB_READER(NAME) int NAME(struct dict *db)
typedef SAXDB_READER(saxdb_reader_func_t);
/* For doing db writing by hand */
struct saxdb_context *saxdb_open_context(FILE *f);
/* For doing db writing by hand */
struct saxdb_context *saxdb_open_context(FILE *f);
+jmp_buf *saxdb_jmp_buf(struct saxdb_context *ctx);
void saxdb_close_context(struct saxdb_context *ctx);
#endif /* !defined(DBMGR_H) */
void saxdb_close_context(struct saxdb_context *ctx);
#endif /* !defined(DBMGR_H) */