aboutsummaryrefslogtreecommitdiff
path: root/src/dictionary.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dictionary.c')
-rw-r--r--src/dictionary.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/dictionary.c b/src/dictionary.c
index b7baf05..2b995d4 100644
--- a/src/dictionary.c
+++ b/src/dictionary.c
@@ -39,26 +39,25 @@ static struct dictionary_descr dictionary_tab[] = {
{ "sql", sql_init_dictionary, sql_done_dictionary, sql_free_result,
sql_open, NULL, sql_get_dictionary, sql_lookup_dictionary, sql_quote },
{ "builtin", builtin_init, builtin_done, builtin_free_result,
builtin_open, NULL,
builtin_get,
builtin_lookup },
{ "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
struct dictionary *
dictionary_new (enum dictionary_id id, enum dictionary_type type)
{
- struct dictionary *mp = xmalloc (sizeof mp[0]);
- memset (mp, 0, sizeof mp[0]);
+ struct dictionary *mp = grecs_zalloc (sizeof mp[0]);
mp->id = id;
mp->type = type;
return mp;
}
int
dictionary_init (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
int rc = 0;
if (dict->init_passed++)
@@ -83,24 +82,26 @@ dictionary_open (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
if (!mp->open)
return NULL;
return mp->open (dict);
}
int
dictionary_close (struct dictionary *dict, void *handle)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
+ if (mp->free)
+ mp->free (dict, handle);
if (!mp->close)
return 0;
return mp->close (dict, handle);
}
int
dictionary_done (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
int rc = 0;
if (dict->init_passed == 0)
@@ -177,52 +178,52 @@ dictionary_result (struct dictionary *dict, void *handle,
if (nrow >= dict->nrow || ncol >= dict->ncol
|| mp->get (dict, handle, nrow, ncol))
return NULL;
return dict->result;
}
void
dictionary_copy_result (struct dictionary *dict, const char *res, size_t size)
{
if (dict->result_size < size + 1)
{
dict->result_size = size + 1;
- dict->result = x2realloc (dict->result, &dict->result_size);
+ dict->result = grecs_realloc (dict->result, dict->result_size);
}
memcpy (dict->result, res, size);
dict->result[size] = 0;
}
/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed
quoted string. Return its length. */
int
dictionary_quote_string (struct dictionary *dict, void *handle,
const char *input,
char **poutput, size_t *psize)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
size_t size;
int quote;
char *output;
if (!input)
{
- *poutput = xmalloc (1);
+ *poutput = grecs_malloc (1);
(*poutput)[0] = 0;
*psize = 1;
return 0;
}
if (mp->quote)
return mp->quote (dict, handle, input, poutput, psize);
size = wordsplit_c_quoted_length (input, 0, &quote);
- output = xmalloc (size + 1);
+ output = grecs_malloc (size + 1);
wordsplit_c_quote_copy (output, input, 0);
output[size] = 0;
*poutput = output;
if (psize)
*psize = size;
return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.