aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-09-15 19:20:17 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-09-15 19:20:17 +0300
commitb785e98d2a06eb1f74f71337431e38f896f397a2 (patch)
tree74b303f36f573f4b2acdd9224bafd1ddc4f37c2f
parenta7be650dc0b3528f1ca75bcb03fc4a94c2d65c49 (diff)
downloaddico-b785e98d2a06eb1f74f71337431e38f896f397a2.tar.gz
dico-b785e98d2a06eb1f74f71337431e38f896f397a2.tar.bz2
Uniform error reporting.
-rw-r--r--include/dico/diag.h9
-rw-r--r--modules/dict.org/dictorg.c42
-rw-r--r--modules/gcide/gcide.c22
-rw-r--r--modules/gcide/idx.c14
-rw-r--r--modules/gcide/idxgcide.l8
-rw-r--r--modules/gcide/tests/degcide.c2
-rw-r--r--modules/ldap/ldap.c2
-rw-r--r--modules/metaphone2/metaphone2.c2
-rw-r--r--modules/nprefix/nprefix.c2
-rw-r--r--modules/python/python.c2
-rw-r--r--modules/python/python2.c2
-rw-r--r--modules/wordnet/wordnet.c34
12 files changed, 68 insertions, 73 deletions
diff --git a/include/dico/diag.h b/include/dico/diag.h
index 226a724..e5091ee 100644
--- a/include/dico/diag.h
+++ b/include/dico/diag.h
@@ -60,5 +60,12 @@ dico_stream_t dico_dbg_stream_create(void);
dico_stream_ioctl(str, DICO_DBG_CTL_SET_FILE, __FILE__); \
dico_stream_ioctl(str, DICO_DBG_CTL_SET_LINE, &n); \
} while (0)
-
+
+#define DICO_LOG_ERRNO() \
+ dico_log(L_ERR, errno, "%s:%d:%s", \
+ __FILE__, __LINE__, __func__)
+#define DICO_LOG_MEMERR() \
+ dico_log(L_ERR, ENOMEM, "%s:%d:%s", \
+ __FILE__, __LINE__, __func__)
+
#endif
diff --git a/modules/dict.org/dictorg.c b/modules/dict.org/dictorg.c
index c0c3919..fbaec48 100644
--- a/modules/dict.org/dictorg.c
+++ b/modules/dict.org/dictorg.c
@@ -22,18 +22,6 @@ static int sort_index;
static int trim_ws;
static int show_dictorg_entries;
-#if __STDC_VERSION__ < 199901L
-# if __GNUC__ >= 2
-# define __func__ __FUNCTION__
-# else
-# define __func__ "<unknown>"
-# endif
-#endif
-
-#define MEMERR() \
- dico_log(L_ERR, 0, _("%s:%d:%s: not enough memory"), \
- __FILE__, __LINE__, __func__)
-
typedef int (*COMPARATOR) (const void *, const void *, void *closure);
static int get_db_flag(struct dictdb *db, const char *name);
@@ -203,7 +191,7 @@ parse_index_entry(const char *filename, size_t line,
idx.word = malloc(len + 1);
if (!idx.word) {
- MEMERR();
+ DICO_LOG_MEMERR();
return 1;
}
@@ -214,7 +202,7 @@ parse_index_entry(const char *filename, size_t line,
} else if (nfield == 3) {
idx.orig = malloc(len + 1);
if (!idx.orig) {
- MEMERR();
+ DICO_LOG_MEMERR();
return 1;
}
memcpy(idx.orig, start, len);
@@ -244,7 +232,7 @@ parse_index_entry(const char *filename, size_t line,
} else {
ep = malloc(sizeof(*ep));
if (!ep) {
- MEMERR();
+ DICO_LOG_MEMERR();
rc = 1;
}
}
@@ -303,7 +291,7 @@ read_index(struct dictdb *db, const char *idxname, int tws)
list = dico_list_create();
if (!list) {
- MEMERR();
+ DICO_LOG_MEMERR();
rc = 1;
} else {
dico_iterator_t itr;
@@ -353,7 +341,7 @@ open_index(struct dictdb *db, int tws)
int rc;
if (!idxname) {
- MEMERR();
+ DICO_LOG_MEMERR();
return 1;
}
@@ -451,14 +439,14 @@ mod_init_db(const char *dbname, int argc, char **argv)
filename = strdup(filename);
if (!filename) {
- MEMERR();
+ DICO_LOG_MEMERR();
return NULL;
}
db = calloc(1, sizeof(*db));
if (!db) {
free(filename);
- MEMERR();
+ DICO_LOG_MEMERR();
return NULL;
}
@@ -703,7 +691,7 @@ common_match(struct dictdb *db, const char *word,
res->db = db;
res->list = dico_list_create();
if (!res->list) {
- MEMERR();
+ DICO_LOG_MEMERR();
return 0;
}
res->itr = NULL;
@@ -766,14 +754,14 @@ suffix_match(struct dictdb *db, const char *word, struct result *res)
int rc;
if (init_suffix_index(db)) {
- MEMERR();
+ DICO_LOG_MEMERR();
return 1;
}
ent.length = strlen(word);
x.word = malloc(ent.length + 1);
if (!x.word) {
- MEMERR();
+ DICO_LOG_MEMERR();
return 1;
}
ent.wordlen = utf8_strlen(word);
@@ -798,7 +786,7 @@ suffix_match(struct dictdb *db, const char *word, struct result *res)
tmp = calloc(count, sizeof(*tmp));
if (!tmp) {
- MEMERR();
+ DICO_LOG_MEMERR();
free(x.word);
return 1;
}
@@ -813,7 +801,7 @@ suffix_match(struct dictdb *db, const char *word, struct result *res)
list = dico_list_create();
if (!list) {
- MEMERR();
+ DICO_LOG_MEMERR();
free(x.word);
free(tmp);
return 1;
@@ -853,7 +841,7 @@ find_db_entry(struct dictdb *db, const char *name)
return NULL;
buf = malloc(ep->size + 1);
if (!buf) {
- MEMERR();
+ DICO_LOG_MEMERR();
return NULL;
}
dico_stream_seek(db->stream, ep->offset, DICO_SEEK_SET);
@@ -945,7 +933,7 @@ _match_all(struct dictdb *db, dico_strategy_t strat, const char *word)
list = dico_list_create();
if (!list) {
- MEMERR();
+ DICO_LOG_MEMERR();
return NULL;
}
@@ -1015,7 +1003,7 @@ mod_define(dico_handle_t hp, const char *word)
return NULL;
rp = malloc(sizeof(*rp));
if (!rp) {
- MEMERR();
+ DICO_LOG_MEMERR();
dico_list_destroy(&res.list);
return NULL;
}
diff --git a/modules/gcide/gcide.c b/modules/gcide/gcide.c
index 419ea9c..91a08ea 100644
--- a/modules/gcide/gcide.c
+++ b/modules/gcide/gcide.c
@@ -204,7 +204,7 @@ gcide_open_idx(struct gcide_db *db)
idxname = dico_full_file_name(db->idx_dir, "GCIDE.IDX");
if (!idxname) {
- dico_log(L_ERR, errno, "gcide_open_idx");
+ DICO_LOG_MEMERR();
return 1;
}
@@ -254,7 +254,7 @@ gcide_init_db(const char *dbname, int argc, char **argv)
if (!idx_dir) {
idx_dir = strdup(db_dir);
if (!idx_dir) {
- dico_log(L_ERR, errno, "gcide_init_db");
+ DICO_LOG_ERRNO();
free(db_dir);
return NULL;
}
@@ -262,9 +262,9 @@ gcide_init_db(const char *dbname, int argc, char **argv)
db = calloc(1, sizeof(*db));
if (!db) {
+ DICO_LOG_ERRNO();
free(db_dir);
free(idx_dir);
- dico_log(L_ERR, ENOMEM, "gcide_init_db");
return NULL;
}
db->db_dir = db_dir;
@@ -457,7 +457,7 @@ gcide_create_result_list(int unique)
list = dico_list_create();
if (!list) {
- dico_log(L_ERR, ENOMEM, "gcide_create_result_list");
+ DICO_LOG_ERRNO();
return NULL;
}
if (unique) {
@@ -473,14 +473,14 @@ gcide_result_list_append(dico_list_t list, struct gcide_ref *ref)
{
struct gcide_ref *copy = calloc(1,sizeof(*copy));
if (!copy) {
- dico_log(L_ERR, errno, "gcide_result_list_append");
+ DICO_LOG_ERRNO();
return -1;
}
*copy = *ref;
copy->ref_headword = strdup(ref->ref_headword);
if (!copy->ref_headword ||
(dico_list_append(list, copy) && errno == ENOMEM)) {
- dico_log(L_ERR, errno, "gcide_result_list_append");
+ DICO_LOG_ERRNO();
free(copy);
return -1;
}
@@ -517,7 +517,7 @@ gcide_match_all(struct gcide_db *db, const dico_strategy_t strat,
return NULL;
if (dico_key_init(&clos.key, strat, word)) {
- dico_log(L_ERR, 0, _("gcide_match_all: key initialization failed"));
+ dico_log(L_ERR, 0, _("%s: key initialization failed"), __func__);
dico_list_destroy(&clos.list);
return NULL;
}
@@ -534,7 +534,7 @@ gcide_match_all(struct gcide_db *db, const dico_strategy_t strat,
res = calloc(1, sizeof(*res));
if (!res) {
- dico_log(L_ERR, errno, "gcide_match_all");
+ DICO_LOG_ERRNO();
dico_list_destroy(&clos.list);
} else {
res->type = result_match;
@@ -560,7 +560,7 @@ gcide_match(dico_handle_t hp, const dico_strategy_t strat, const char *word)
if (itr) {
res = calloc(1, sizeof(*res));
if (!res) {
- dico_log(L_ERR, errno, "gcide_match");
+ DICO_LOG_ERRNO();
gcide_iterator_free(itr);
return NULL;
}
@@ -594,7 +594,7 @@ gcide_define(dico_handle_t hp, const char *word)
if (itr) {
res = calloc(1, sizeof(*res));
if (!res) {
- dico_log(L_ERR, errno, "gcide_define");
+ DICO_LOG_ERRNO();
gcide_iterator_free(itr);
return NULL;
}
@@ -750,7 +750,7 @@ output_def(dico_stream_t str, struct gcide_db *db, struct gcide_ref *ref)
buffer = malloc(ref->ref_size);
if (!buffer) {
- dico_log(L_ERR, errno, "output_def");
+ DICO_LOG_ERRNO();
return 1;
}
diff --git a/modules/gcide/idx.c b/modules/gcide/idx.c
index 815b249..44ef46f 100644
--- a/modules/gcide/idx.c
+++ b/modules/gcide/idx.c
@@ -116,12 +116,12 @@ gcide_idx_file_open(const char *name, size_t cachesize)
file = calloc(1, sizeof(*file));
if (!file) {
- dico_log(L_ERR, errno, "gcide_idx_file_open");
+ DICO_LOG_ERRNO();
return NULL;
}
file->name = strdup(name);
if (!file->name) {
- dico_log(L_ERR, errno, "gcide_idx_file_open");
+ DICO_LOG_ERRNO();
free(file);
return NULL;
}
@@ -168,7 +168,7 @@ _cache_alloc(struct gcide_idx_file *file)
if (!file->cache) {
file->cache = calloc(file->cache_size, sizeof(file->cache[0]));
if (!file->cache) {
- dico_log(L_ERR, ENOMEM, "gcide _cache_alloc");
+ DICO_LOG_ERRNO();
return NULL;
}
}
@@ -178,12 +178,12 @@ _cache_alloc(struct gcide_idx_file *file)
return file->cache[file->cache_used - 1];
cp = calloc(1, sizeof(*cp));
if (!cp) {
- dico_log(L_ERR, ENOMEM, "gcide _cache_alloc");
+ DICO_LOG_ERRNO();
return NULL;
}
cp->page = malloc(file->header.ihdr_pagesize);
if (!cp->page) {
- dico_log(L_ERR, ENOMEM, "gcide _cache_alloc");
+ DICO_LOG_ERRNO();
free(cp);
return NULL;
}
@@ -413,7 +413,7 @@ gcide_idx_locate(struct gcide_idx_file *file, char *headword, size_t hwlen)
itr = malloc(sizeof(*itr));
if (!itr) {
- dico_log(L_ERR, errno, "gcide_idx_locate");
+ DICO_LOG_ERRNO();
return NULL;
}
if (hwlen) {
@@ -424,7 +424,7 @@ gcide_idx_locate(struct gcide_idx_file *file, char *headword, size_t hwlen)
itr->headword = strdup(headword);
if (!itr->headword) {
- dico_log(L_ERR, errno, "gcide_idx_locate");
+ DICO_LOG_ERRNO();
free(itr);
return NULL;
}
diff --git a/modules/gcide/idxgcide.l b/modules/gcide/idxgcide.l
index 280eb91..f026d9d 100644
--- a/modules/gcide/idxgcide.l
+++ b/modules/gcide/idxgcide.l
@@ -66,7 +66,7 @@ static void
full_write(void *data, size_t size)
{
if (fwrite(data, size, 1, idxfile) != 1) {
- dico_log(L_ERR, errno, _("write error"));
+ DICO_LOG_ERRNO();
exit(EX_UNAVAILABLE);
}
}
@@ -292,7 +292,7 @@ main(int argc, char **argv)
idx_page = malloc(idx_header.ihdr_pagesize);
if (!idx_page) {
- dico_log(L_ERR, 0, _("not enough memory"));
+ DICO_LOG_ERRNO();
exit(EX_UNAVAILABLE);
}
idx_page->ipg_header.hdr.phdr_numentries = 0;
@@ -318,7 +318,7 @@ main(int argc, char **argv)
infile = dico_full_file_name(dictdir, "CIDE.A");
if (!infile) {
- dico_log(L_ERR, 0, _("not enough memory"));
+ DICO_LOG_MEMERR();
exit(EX_UNAVAILABLE);
}
suf = infile + strlen(infile) - 1;
@@ -328,7 +328,7 @@ main(int argc, char **argv)
else
idxname = dico_full_file_name(idxdir, "GCIDE.IDX");
if (!idxname) {
- dico_log(L_ERR, 0, _("not enough memory"));
+ DICO_LOG_MEMERR();
exit(EX_UNAVAILABLE);
}
diff --git a/modules/gcide/tests/degcide.c b/modules/gcide/tests/degcide.c
index 6327f97..f02d3f8 100644
--- a/modules/gcide/tests/degcide.c
+++ b/modules/gcide/tests/degcide.c
@@ -208,7 +208,7 @@ main(int argc, char **argv)
textbuf = malloc(size);
if (!textbuf) {
- dico_log(L_ERR, 0, "not enough memory");
+ DICO_LOG_ERRNO();
exit(EX_UNAVAILABLE);
}
diff --git a/modules/ldap/ldap.c b/modules/ldap/ldap.c
index 6c72c1b..7f6321b 100644
--- a/modules/ldap/ldap.c
+++ b/modules/ldap/ldap.c
@@ -281,7 +281,7 @@ _dico_ldap_search(struct _dico_ldap_handle *lp, const char *filter_pat,
if (filter_pat) {
filter = _dico_ldap_expand_user(filter_pat, user);
if (!filter) {
- dico_log(L_ERR, ENOMEM, "_dico_ldap_expand_user");
+ DICO_LOG_MEMERR();
return NULL;
}
} else
diff --git a/modules/metaphone2/metaphone2.c b/modules/metaphone2/metaphone2.c
index 1b9d8c0..cd3f77c 100644
--- a/modules/metaphone2/metaphone2.c
+++ b/modules/metaphone2/metaphone2.c
@@ -224,7 +224,7 @@ double_metaphone_add(double_metaphone_code code,
if (!code[1]) {
code[1] = metaph_code_dup(code[0]);
if (!code[1]) {
- dico_log(L_ERR, 0, _("%s: not enough memory"), __func__);
+ DICO_LOG_MEMERR();
return -1;
}
}
diff --git a/modules/nprefix/nprefix.c b/modules/nprefix/nprefix.c
index 0f1949b..284a05a 100644
--- a/modules/nprefix/nprefix.c
+++ b/modules/nprefix/nprefix.c
@@ -54,7 +54,7 @@ nprefix_sel(int cmd, dico_key_t key, const char *dict_word)
np = calloc(1, sizeof(np[0]));
if (!np) {
- dico_log(L_ERR, errno, "nprefix_sel");
+ DICO_LOG_MEMERR();
return 1;
}
np->prefix = (char*)key_word;
diff --git a/modules/python/python.c b/modules/python/python.c
index fa2b009..898c405 100644
--- a/modules/python/python.c
+++ b/modules/python/python.c
@@ -499,7 +499,7 @@ mod_init_db (const char *dbname, int argc, char **argv)
db = malloc (sizeof (*db));
if (!db) {
- dico_log (L_ERR, 0, _("%s: not enough memory"), "mod_init_db");
+ DICO_LOG_ERRNO();
return NULL;
}
db->dbname = dbname;
diff --git a/modules/python/python2.c b/modules/python/python2.c
index f44cfd8..b9acfb2 100644
--- a/modules/python/python2.c
+++ b/modules/python/python2.c
@@ -431,7 +431,7 @@ mod_init_db (const char *dbname, int argc, char **argv)
db = malloc (sizeof (*db));
if (!db) {
- dico_log (L_ERR, 0, _("%s: not enough memory"), "mod_init_db");
+ DICO_LOG_ERRNO();
return NULL;
}
db->dbname = dbname;
diff --git a/modules/wordnet/wordnet.c b/modules/wordnet/wordnet.c
index d39b911..e37f19b 100644
--- a/modules/wordnet/wordnet.c
+++ b/modules/wordnet/wordnet.c
@@ -221,7 +221,7 @@ wn_init_db(const char *dbname, int argc, char **argv)
optc = argc + 1;
optv = calloc(optc, sizeof(optv[0]));
if (!optv) {
- dico_log(L_ERR, ENOMEM, "wn_init_db");
+ DICO_LOG_ERRNO();
return NULL;
}
@@ -247,13 +247,13 @@ wn_init_db(const char *dbname, int argc, char **argv)
wndb = calloc(1, sizeof(*wndb));
if (!wndb) {
- dico_log(L_ERR, ENOMEM, "wn_init_db");
+ DICO_LOG_ERRNO();
free(optv);
return NULL;
}
wndb->dbname = strdup(dbname);
if (!wndb->dbname) {
- dico_log(L_ERR, ENOMEM, "wn_init_db");
+ DICO_LOG_ERRNO();
free(wndb);
return NULL;
}
@@ -307,7 +307,7 @@ wordbuf_expand(struct wordbuf *wb, size_t len)
size_t size = ((len + WORDBUFINC - 1) / WORDBUFINC ) * WORDBUFINC;
char *newword = realloc(wb->word, size);
if (!newword) {
- dico_log(L_ERR, ENOMEM, "wordbuf_expand");
+ DICO_LOG_ERRNO();
return 1;
}
wb->word = newword;
@@ -407,14 +407,14 @@ wn_create_match_result(struct wndb *wndb)
res = calloc(1, sizeof(*res));
if (!res) {
- dico_log(L_ERR, ENOMEM, "wn_create_match_result");
+ DICO_LOG_ERRNO();
return NULL;
}
res->type = result_match;
res->wndb = wndb;
res->list = dico_list_create();
if (!res) {
- dico_log(L_ERR, ENOMEM, "wn_create_match_result");
+ DICO_LOG_ERRNO();
free(res);
return NULL;
}
@@ -431,14 +431,14 @@ wn_create_define_result(struct wndb *wndb, const char *searchword)
res = calloc(1, sizeof(*res));
if (!res) {
- dico_log(L_ERR, ENOMEM, "wn_create_define_result");
+ DICO_LOG_ERRNO();
return NULL;
}
res->type = result_define;
res->wndb = wndb;
res->list = dico_list_create();
if (!res) {
- dico_log(L_ERR, ENOMEM, "wn_create_match_result");
+ DICO_LOG_ERRNO();
free(res);
return NULL;
}
@@ -446,13 +446,13 @@ wn_create_define_result(struct wndb *wndb, const char *searchword)
res->searchword = strdup(searchword);
if (!res->searchword) {
- dico_log(L_ERR, ENOMEM, "wn_create_match_result");
+ DICO_LOG_ERRNO();
wn_free_result((dico_result_t) res);
}
res->rootlist = dico_list_create();
if (!res->rootlist) {
- dico_log(L_ERR, ENOMEM, "wn_create_match_result");
+ DICO_LOG_ERRNO();
wn_free_result((dico_result_t) res);
}
dico_list_set_free_item(res->rootlist, free_root_synset, NULL);
@@ -467,14 +467,14 @@ wn_match_result_add(struct result *res, const char *hw)
char *s = strdup(hw);
if (!s) {
- dico_log(L_ERR, ENOMEM, "wn_result_add_key");
+ DICO_LOG_ERRNO();
return -1;
}
rc = dico_list_insert_sorted(res->list, s);
if (rc) {
free(s);
if (rc != EEXIST) {
- dico_log(L_ERR, ENOMEM, "wn_foreach_db");
+ DICO_LOG_MEMERR();
return -1;
}
}
@@ -610,13 +610,13 @@ wn_foreach(struct wndb *wndb, const dico_strategy_t strat, const char *word)
strtolower(strsubst(searchword, ' ', '_'));
if (!searchword) {
- dico_log(L_ERR, ENOMEM, "wn_foreach");
+ DICO_LOG_MEMERR();
wn_free_result((dico_result_t) res);
return NULL;
}
if (dico_key_init(&key, strat, word)) {
- dico_log(L_ERR, 0, _("wn_foreach: key initialization failed"));
+ dico_log(L_ERR, 0, _("%s: key initialization failed"), __func__);
wn_free_result((dico_result_t) res);
free(searchword);
return NULL;
@@ -780,7 +780,7 @@ nornmalize_search_word(const char *word)
copy = malloc(strlen(word) + 1);
if (!copy) {
- dico_log(L_ERR, ENOMEM, "nornmalize_search_word");
+ DICO_LOG_ERRNO();
return NULL;
}
for (p = copy, q = word; *q; ) {
@@ -815,12 +815,12 @@ create_defn(struct wndb *wndb, int pos)
{
struct defn *p = malloc(sizeof(*p));
if (!p) {
- dico_log(L_ERR, ENOMEM, "create_defn");
+ DICO_LOG_ERRNO();
return NULL;
}
p->synset = calloc(wndb->optc, sizeof(p->synset[0]));
if (!p->synset) {
- dico_log(L_ERR, ENOMEM, "create_defn");
+ DICO_LOG_ERRNO();
free(p);
return NULL;
}

Return to:

Send suggestions and report system problems to the System administrator.