[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Use GLib's allocation functions consistently in src/server/*.c.
From: |
Christopher Brannon |
Subject: |
[PATCH] Use GLib's allocation functions consistently in src/server/*.c. |
Date: |
Mon, 20 Sep 2010 10:27:06 -0500 |
The GLib documentation discourages mixing memory allocation strategies.
We now use g_malloc, g_free, g_strdup, etc., for memory management
in src/server/*.c.
---
src/server/alloc.c | 92 ++++----------
src/server/alloc.h | 15 ---
src/server/configuration.c | 61 +++++-----
src/server/history.c | 40 +++---
src/server/index_marking.c | 2 +-
src/server/module.c | 20 ++--
src/server/options.c | 6 +-
src/server/output.c | 32 +++---
src/server/parse.c | 298 ++++++++++++++++++++++----------------------
src/server/server.c | 16 ++--
src/server/set.c | 33 +++---
src/server/speaking.c | 24 ++--
src/server/speechd.c | 52 ++++----
13 files changed, 316 insertions(+), 375 deletions(-)
diff --git a/src/server/alloc.c b/src/server/alloc.c
index 7828208..640a1e9 100644
--- a/src/server/alloc.c
+++ b/src/server/alloc.c
@@ -5,54 +5,12 @@
#include "alloc.h"
-void*
-spd_malloc(size_t bytes)
-{
- void *mem;
-
- mem = malloc(bytes);
- if(mem == NULL) FATAL("Can't allocate memmory.\n");
-
- return mem;
-}
-
-void*
-spd_realloc(void *ptr, size_t bytes)
-{
- void *mem;
-
- mem = realloc(ptr, bytes);
- if(mem == NULL) FATAL("Can't allocate memmory.\n");
-
- return mem;
-}
-
-void
-spd_free(void* data)
-{
- if (data != NULL) free(data);
-}
-
-char*
-spd_strdup(char* string)
-{
- char *newstr;
-
- if (string == NULL) return NULL;
-
- newstr = strdup(string);
- if (newstr == NULL)
- FATAL("Can't duplicate a string of characters, not enough memmory");
-
- return newstr;
-}
-
TSpeechDQueue*
speechd_queue_alloc()
{
TSpeechDQueue *new;
- new = spd_malloc(sizeof(TSpeechDQueue));
+ new = g_malloc(sizeof(TSpeechDQueue));
/* Initialize all the queues to be empty */
new->p1 = NULL;
@@ -70,16 +28,16 @@ spd_fdset_copy(TFDSetElement old)
TFDSetElement new;
new = old;
- new.language = spd_strdup(old.language);
- new.synthesis_voice = spd_strdup(old.synthesis_voice);
- new.client_name = spd_strdup(old.client_name);
- new.output_module = spd_strdup(old.output_module);
- new.index_mark = spd_strdup(old.index_mark);
- new.audio_output_method = spd_strdup(old.audio_output_method);
- new.audio_oss_device = spd_strdup(old.audio_oss_device);
- new.audio_alsa_device = spd_strdup(old.audio_alsa_device);
- new.audio_nas_server = spd_strdup(old.audio_nas_server);
- new.audio_pulse_server = spd_strdup(old.audio_pulse_server);
+ new.language = g_strdup(old.language);
+ new.synthesis_voice = g_strdup(old.synthesis_voice);
+ new.client_name = g_strdup(old.client_name);
+ new.output_module = g_strdup(old.output_module);
+ new.index_mark = g_strdup(old.index_mark);
+ new.audio_output_method = g_strdup(old.audio_output_method);
+ new.audio_oss_device = g_strdup(old.audio_oss_device);
+ new.audio_alsa_device = g_strdup(old.audio_alsa_device);
+ new.audio_nas_server = g_strdup(old.audio_nas_server);
+ new.audio_pulse_server = g_strdup(old.audio_pulse_server);
return new;
@@ -93,10 +51,10 @@ spd_message_copy(TSpeechDMessage *old)
if (old == NULL) return NULL;
- new = (TSpeechDMessage *) spd_malloc(sizeof(TSpeechDMessage));
+ new = (TSpeechDMessage *) g_malloc(sizeof(TSpeechDMessage));
*new = *old;
- new->buf = spd_malloc((old->bytes+1) * sizeof(char));
+ new->buf = g_malloc((old->bytes+1) * sizeof(char));
memcpy(new->buf, old->buf, old->bytes);
new->buf[new->bytes] = 0;
new->settings = spd_fdset_copy(old->settings);
@@ -109,25 +67,25 @@ mem_free_fdset(TFDSetElement *fdset)
{
/* Don't forget that only these items are filled in
in a TSpeechDMessage */
- spd_free(fdset->client_name);
- spd_free(fdset->language);
- spd_free(fdset->synthesis_voice);
- spd_free(fdset->output_module);
- spd_free(fdset->index_mark);
- spd_free(fdset->audio_output_method);
- spd_free(fdset->audio_oss_device);
- spd_free(fdset->audio_alsa_device);
- spd_free(fdset->audio_nas_server);
- spd_free(fdset->audio_pulse_server);
+ g_free(fdset->client_name);
+ g_free(fdset->language);
+ g_free(fdset->synthesis_voice);
+ g_free(fdset->output_module);
+ g_free(fdset->index_mark);
+ g_free(fdset->audio_output_method);
+ g_free(fdset->audio_oss_device);
+ g_free(fdset->audio_alsa_device);
+ g_free(fdset->audio_nas_server);
+ g_free(fdset->audio_pulse_server);
}
void
mem_free_message(TSpeechDMessage *msg)
{
if (msg == NULL) return;
- spd_free(msg->buf);
+ g_free(msg->buf);
mem_free_fdset(&(msg->settings));
- spd_free(msg);
+ g_free(msg);
}
diff --git a/src/server/alloc.h b/src/server/alloc.h
index 52b7517..788578d 100644
--- a/src/server/alloc.h
+++ b/src/server/alloc.h
@@ -4,21 +4,6 @@
#ifndef ALLOC_H
#define ALLOC_H
-/* Like malloc(), but execute FATAL() if it can't allocate
- the memmory. It never returns NULL. */
-void* spd_malloc(size_t bytes);
-
-/* Like realloc(), but execute FATAL() if it can't allocate
- the memmory. It never returns NULL. */
-void* spd_realloc(void* ptr, size_t bytes);
-
-/* Like free(), but don't try to free NULL data. After freeing
- the data, fill the pointer with NULL. */
-void spd_free(void *data);
-
-/* Like strdup(), but copies also the empty "NULL" strings. */
-char* spd_strdup(char* string);
-
TSpeechDQueue* speechd_queue_alloc();
/* Copy a message */
diff --git a/src/server/configuration.c b/src/server/configuration.c
index 20af89c..abd5e90 100644
--- a/src/server/configuration.c
+++ b/src/server/configuration.c
@@ -35,7 +35,6 @@
static TFDSetClientSpecific *cl_spec_section;
/* So that gcc doesn't comply about casts to char* */
-extern char* spd_strdup(char* string);
/* == CONFIGURATION MANAGEMENT FUNCTIONS */
@@ -48,8 +47,8 @@ add_config_option(configoption_t *options, int
*num_config_options, char *name,
configoption_t *opts;
(*num_config_options)++;
- opts = (configoption_t*) realloc(options, (*num_config_options) *
sizeof(configoption_t));
- opts[*num_config_options-1].name = strdup(name);
+ opts = (configoption_t*) g_realloc(options, (*num_config_options) *
sizeof(configoption_t));
+ opts[*num_config_options-1].name = g_strdup(name);
opts[*num_config_options-1].type = type;
opts[*num_config_options-1].callback = callback;
opts[*num_config_options-1].info = info;
@@ -66,9 +65,9 @@ free_config_options(configoption_t *opts, int *num)
if (opts == NULL) return;
for(i=0; i<=(*num)-1; i++){
- spd_free((char*) opts[i].name);
+ g_free((char*) opts[i].name);
}
- spd_free(opts);
+ g_free(opts);
*num = 0;
opts = NULL;
}
@@ -81,9 +80,9 @@ free_config_options(configoption_t *opts, int *num)
{ \
assert(cmd->data.str != NULL); \
if (!cl_spec_section) \
- GlobalFDSet.arg = strdup(cmd->data.str); \
+ GlobalFDSet.arg = g_strdup(cmd->data.str); \
else \
- cl_spec_section->val.arg = strdup(cmd->data.str); \
+ cl_spec_section->val.arg = g_strdup(cmd->data.str); \
return NULL; \
}
@@ -107,7 +106,7 @@ free_config_options(configoption_t *opts, int *num)
val_str = g_ascii_strdown(cmd->data.str, strlen(cmd->data.str)); \
if (val_str == NULL) FATAL("Invalid parameter in configuration"); \
val = fconv(val_str); \
- spd_free(val_str); \
+ g_free(val_str); \
if (val == -1) FATAL("Invalid parameter in configuration."); \
if (!cl_spec_section) \
GlobalFDSet.arg = val; \
@@ -121,7 +120,7 @@ free_config_options(configoption_t *opts, int *num)
{ \
if (cl_spec_section) \
FATAL("This command isn't allowed in a client specific section!"); \
- if (!SpeechdOptions.arg ## _set) SpeechdOptions.arg =
spd_strdup(cmd->data.str); \
+ if (!SpeechdOptions.arg ## _set) SpeechdOptions.arg =
g_strdup(cmd->data.str); \
return NULL; \
}
@@ -141,7 +140,7 @@ free_config_options(configoption_t *opts, int *num)
{ \
if (cl_spec_section) \
FATAL("This command isn't allowed in a client specific section!"); \
- SpeechdOptions.arg = spd_strdup(cmd->data.str); \
+ SpeechdOptions.arg = g_strdup(cmd->data.str); \
return NULL; \
}
@@ -208,8 +207,8 @@ DOTCONF_CB(cb_LanguageDefaultModule)
if(cmd->data.list[0] == NULL) FATAL("No language specified for
LanguageDefaultModule");
if(cmd->data.list[0] == NULL) FATAL("No module specified for
LanguageDefaultModule");
- key = strdup(cmd->data.list[0]);
- value = strdup(cmd->data.list[1]);
+ key = g_strdup(cmd->data.list[0]);
+ value = g_strdup(cmd->data.list[1]);
g_hash_table_insert(language_default_modules, key, value);
@@ -235,7 +234,7 @@ DOTCONF_CB(cb_LogDir)
if (strcmp(cmd->data.str, "default")){
// cmd->data.str different from "default"
- SpeechdOptions.log_dir = strdup(cmd->data.str);
+ SpeechdOptions.log_dir = g_strdup(cmd->data.str);
}
logging_init();
return NULL;
@@ -249,9 +248,9 @@ DOTCONF_CB(cb_CustomLogFile)
if(cmd->data.list[0] == NULL) FATAL("No log kind specified in
CustomLogFile");
if(cmd->data.list[1] == NULL) FATAL("No log file specified in
CustomLogFile");
- kind = strdup(cmd->data.list[0]);
+ kind = g_strdup(cmd->data.list[0]);
assert(kind != NULL);
- file = strdup(cmd->data.list[1]);
+ file = g_strdup(cmd->data.list[1]);
assert(file != NULL);
custom_log_kind = kind;
@@ -282,7 +281,7 @@ DOTCONF_CB(cb_AddModule)
OutputModule *cur_mod;
- if (cmd->data.list[0] != NULL) module_name = strdup(cmd->data.list[0]);
+ if (cmd->data.list[0] != NULL) module_name = g_strdup(cmd->data.list[0]);
else FATAL("No output module name specified in configuration under
AddModule");
module_prgname = cmd->data.list[1];
@@ -300,10 +299,10 @@ DOTCONF_CB(cb_AddModule)
MSG(5,"Module name=%s being inserted into hash table", cur_mod->name);
assert(cur_mod->name != NULL);
- g_hash_table_insert(output_modules, strdup(module_name), cur_mod);
- output_modules_list=g_list_append(output_modules_list,
strdup(module_name));
+ g_hash_table_insert(output_modules, g_strdup(module_name), cur_mod);
+ output_modules_list=g_list_append(output_modules_list,
g_strdup(module_name));
- spd_free(module_name);
+ g_free(module_name);
return NULL;
}
@@ -323,8 +322,8 @@ DOTCONF_CB(cb_BeginClient)
if (cmd->data.str == NULL)
FATAL("Configuration: You must specify some client's name for
BeginClient");
- cl_spec = (TFDSetClientSpecific*) spd_malloc(sizeof(TFDSetClientSpecific));
- cl_spec->pattern = spd_strdup(cmd->data.str);
+ cl_spec = (TFDSetClientSpecific*) g_malloc(sizeof(TFDSetClientSpecific));
+ cl_spec->pattern = g_strdup(cmd->data.str);
cl_spec_section = cl_spec;
MSG(4, "Reading configuration for pattern %s", cl_spec->pattern);
@@ -444,8 +443,8 @@ load_default_global_set_options()
GlobalFDSet.rate = 0;
GlobalFDSet.pitch = 0;
GlobalFDSet.volume = 0;
- GlobalFDSet.client_name = strdup("unknown:unknown:unknown");
- GlobalFDSet.language = strdup("en");
+ GlobalFDSet.client_name = g_strdup("unknown:unknown:unknown");
+ GlobalFDSet.language = g_strdup("en");
GlobalFDSet.output_module = NULL;
GlobalFDSet.voice = MALE1;
GlobalFDSet.cap_let_recogn = 0;
@@ -456,14 +455,14 @@ load_default_global_set_options()
#ifdef __SUNPRO_C
/* Added by Willie Walker - default to OSS for Solaris */
- GlobalFDSet.audio_output_method = strdup("oss");
+ GlobalFDSet.audio_output_method = g_strdup("oss");
#else
- GlobalFDSet.audio_output_method = strdup("pulse");
+ GlobalFDSet.audio_output_method = g_strdup("pulse");
#endif /* __SUNPRO_C */
- GlobalFDSet.audio_oss_device = strdup("/dev/dsp");
- GlobalFDSet.audio_alsa_device = strdup("default");
- GlobalFDSet.audio_nas_server = strdup("tcp/localhost:5450");
- GlobalFDSet.audio_pulse_server = strdup("default");
+ GlobalFDSet.audio_oss_device = g_strdup("/dev/dsp");
+ GlobalFDSet.audio_alsa_device = g_strdup("default");
+ GlobalFDSet.audio_nas_server = g_strdup("tcp/localhost:5450");
+ GlobalFDSet.audio_pulse_server = g_strdup("default");
GlobalFDSet.audio_pulse_min_length = 100;
SpeechdOptions.max_history_messages = 10000;
@@ -474,9 +473,9 @@ load_default_global_set_options()
if (!SpeechdOptions.log_level_set)
SpeechdOptions.log_level = 3;
if (!SpeechdOptions.communication_method_set)
- SpeechdOptions.communication_method = strdup("unix_socket");
+ SpeechdOptions.communication_method = g_strdup("unix_socket");
if (!SpeechdOptions.socket_path_set)
- SpeechdOptions.socket_path = strdup("default");
+ SpeechdOptions.socket_path = g_strdup("default");
if (!SpeechdOptions.port_set)
SpeechdOptions.port = SPEECHD_DEFAULT_PORT;
if (!SpeechdOptions.localhost_access_only_set)
SpeechdOptions.localhost_access_only = 1;
diff --git a/src/server/history.c b/src/server/history.c
index 9591841..715411e 100644
--- a/src/server/history.c
+++ b/src/server/history.c
@@ -78,7 +78,7 @@ history_get_client_id(int fd)
cid = g_string_new("");
uid = get_client_uid_by_fd(fd);
- if (uid == 0) return strdup(ERR_INTERNAL);
+ if (uid == 0) return g_strdup(ERR_INTERNAL);
g_string_append_printf(cid, C_OK_CLIENT_ID"-%d\r\n", uid);
g_string_append_printf(cid, OK_CLIENT_ID_SENT);
@@ -101,8 +101,8 @@ history_get_message(int uid)
mtext = g_string_new("");
gl = g_list_find_custom(message_history, &uid, compare_message_uid);
- if (gl == NULL) return strdup(ERR_ID_NOT_EXIST);
- if (gl->data == NULL) return strdup(ERR_INTERNAL);
+ if (gl == NULL) return g_strdup(ERR_ID_NOT_EXIST);
+ if (gl->data == NULL) return g_strdup(ERR_INTERNAL);
msg = (TSpeechDMessage*) gl->data;
i = 0;
@@ -122,7 +122,7 @@ history_get_message(int uid)
#endif
- return strdup(ERR_NOT_IMPLEMENTED);
+ return g_strdup(ERR_NOT_IMPLEMENTED);
}
@@ -141,7 +141,7 @@ history_get_message_list(guint client_id, int from, int num)
mlist = g_string_new("");
client_settings = get_client_settings_by_uid(client_id);
- if (client_settings == NULL) return strdup(ERR_NO_SUCH_CLIENT);
+ if (client_settings == NULL) return g_strdup(ERR_NO_SUCH_CLIENT);
client_msgs = get_messages_by_client(client_id);
@@ -155,7 +155,7 @@ history_get_message_list(guint client_id, int from, int num)
if (message == NULL){
if(SPEECHD_DEBUG) FATAL("Internal error.\n");
- return strdup(ERR_INTERNAL);
+ return g_strdup(ERR_INTERNAL);
}
g_string_append_printf(mlist, C_OK_MSGS"-");
@@ -176,7 +176,7 @@ history_get_last(int fd)
lastm = g_string_new("");
gl = g_list_last(message_history);
- if (gl == NULL) return strdup(ERR_NO_MESSAGE);
+ if (gl == NULL) return g_strdup(ERR_NO_MESSAGE);
message = gl->data;
g_string_append_printf(lastm, C_OK_LAST_MSG"-%d\r\n",
@@ -198,7 +198,7 @@ history_cursor_set_last(int fd, guint client_id)
settings->hist_cur_pos = g_list_length(client_msgs) - 1;
settings->hist_cur_uid = client_id;
- return strdup(OK_CUR_SET_LAST);
+ return g_strdup(OK_CUR_SET_LAST);
}
char*
@@ -211,7 +211,7 @@ history_cursor_set_first(int fd, guint client_id)
settings->hist_cur_pos = 0;
settings->hist_cur_uid = client_id;
- return strdup(OK_CUR_SET_FIRST);
+ return g_strdup(OK_CUR_SET_FIRST);
}
char*
@@ -220,10 +220,10 @@ history_cursor_set_pos(int fd, guint client_id, int pos)
TFDSetElement *settings;
GList *client_msgs;
- if (pos < 0) return strdup(ERR_POS_LOW);
+ if (pos < 0) return g_strdup(ERR_POS_LOW);
client_msgs = get_messages_by_client(client_id);
- if (pos > g_list_length(client_msgs)-1) return strdup(ERR_POS_HIGH);
+ if (pos > g_list_length(client_msgs)-1) return g_strdup(ERR_POS_HIGH);
settings = get_client_settings_by_fd(fd);
if (settings == NULL) FATAL("Couldn't find settings for active client");
@@ -231,7 +231,7 @@ history_cursor_set_pos(int fd, guint client_id, int pos)
settings->hist_cur_pos = pos;
settings->hist_cur_uid = client_id;
MSG(4,"cursor pos:%d\n", settings->hist_cur_pos);
- return strdup(OK_CUR_SET_POS);
+ return g_strdup(OK_CUR_SET_POS);
}
char*
@@ -244,10 +244,10 @@ history_cursor_forward(int fd)
if (settings == NULL) FATAL("Couldn't find settings for active client");
client_msgs = get_messages_by_client(settings->hist_cur_uid);
- if ((settings->hist_cur_pos + 1) > g_list_length(client_msgs)-1) return
strdup(ERR_POS_HIGH);
+ if ((settings->hist_cur_pos + 1) > g_list_length(client_msgs)-1) return
g_strdup(ERR_POS_HIGH);
settings->hist_cur_pos++;
- return strdup(OK_CUR_MOV_FOR);
+ return g_strdup(OK_CUR_MOV_FOR);
}
char*
@@ -258,10 +258,10 @@ history_cursor_backward(int fd)
settings = get_client_settings_by_fd(fd);
if (settings == NULL) FATAL("Couldn't find settings for active client");
- if ((settings->hist_cur_pos - 1) < 0) return strdup(ERR_POS_LOW);
+ if ((settings->hist_cur_pos - 1) < 0) return g_strdup(ERR_POS_LOW);
settings->hist_cur_pos--;
- return strdup(OK_CUR_MOV_BACK);
+ return g_strdup(OK_CUR_MOV_BACK);
}
char*
@@ -279,7 +279,7 @@ history_cursor_get(int fd)
client_msgs = get_messages_by_client(settings->hist_cur_uid);
gl = g_list_nth(client_msgs, (int) settings->hist_cur_pos);
- if (gl == NULL) return strdup(ERR_NO_MESSAGE);
+ if (gl == NULL) return g_strdup(ERR_NO_MESSAGE);
new = gl->data;
g_string_printf(reply, C_OK_CUR_POS"-%d\r\n"OK_CUR_POS_RET, new->id);
@@ -293,15 +293,15 @@ history_say_id(int fd, int id)
GList *gl;
gl = g_list_find_custom(message_history, &id, p_msg_comp_id);
- if (gl == NULL) return strdup(ERR_ID_NOT_EXIST);
+ if (gl == NULL) return g_strdup(ERR_ID_NOT_EXIST);
msg = gl->data;
- if (msg == NULL) return strdup(ERR_INTERNAL);
+ if (msg == NULL) return g_strdup(ERR_INTERNAL);
MSG(4,"putting history message into queue\n");
new = (TSpeechDMessage*) spd_message_copy(msg);
// queue_message(new, fd, 0, 0);
- return strdup(OK_MESSAGE_QUEUED);
+ return g_strdup(OK_MESSAGE_QUEUED);
}
GList*
diff --git a/src/server/index_marking.c b/src/server/index_marking.c
index b1c4ddf..584b7bb 100644
--- a/src/server/index_marking.c
+++ b/src/server/index_marking.c
@@ -107,7 +107,7 @@ insert_index_marks(TSpeechDMessage *msg, int ssml_mode)
if (!ssml_mode) g_string_append_printf(marked_text, "</speak>");
- spd_free(msg->buf);
+ g_free(msg->buf);
msg->buf = marked_text->str;
g_string_free(marked_text, 0);
diff --git a/src/server/module.c b/src/server/module.c
index bb1cc3f..187d575 100644
--- a/src/server/module.c
+++ b/src/server/module.c
@@ -42,10 +42,10 @@ ssize_t getline (char **lineptr, size_t *n, FILE *f);
void
destroy_module(OutputModule *module)
{
- spd_free(module->name);
- spd_free(module->filename);
- spd_free(module->configfilename);
- spd_free(module);
+ g_free(module->name);
+ g_free(module->filename);
+ g_free(module->configfilename);
+ g_free(module);
}
OutputModule*
@@ -60,9 +60,9 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
if (mod_name == NULL) return NULL;
- module = (OutputModule*) spd_malloc(sizeof(OutputModule));
+ module = (OutputModule*) g_malloc(sizeof(OutputModule));
- module->name = (char*) spd_strdup(mod_name);
+ module->name = (char*) g_strdup(mod_name);
module->filename = (char*) spd_get_path(mod_prog, MODULEBINDIR);
module_conf_dir = g_strdup_printf("%s/modules/",
@@ -71,7 +71,7 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
module->configfilename = (char*) spd_get_path(mod_cfgfile,
module_conf_dir);
g_free(module_conf_dir);
- if (mod_dbgfile != NULL) module->debugfilename = strdup(mod_dbgfile);
+ if (mod_dbgfile != NULL) module->debugfilename = g_strdup(mod_dbgfile);
else module->debugfilename = NULL;
if (!strcmp(mod_name, "testing")){
@@ -140,7 +140,7 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
assert(0);
default:
- if (cfg) spd_free(arg1);
+ if (cfg) g_free(arg1);
module->pid = fr;
close(module->pipe_in[0]);
@@ -172,7 +172,7 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
output_close(module);
return NULL;
}else{
- char *rep_line = malloc(1024);
+ char *rep_line = g_malloc(1024);
FILE *f;
size_t n = 1024;
char s;
@@ -196,7 +196,7 @@ load_output_module(char* mod_name, char* mod_prog, char*
mod_cfgfile, char* mod_
if (rep_line[3] == '-') g_string_append(reply, rep_line + 4);
else{
s = rep_line[0];
- spd_free(rep_line);
+ g_free(rep_line);
break;
}
diff --git a/src/server/options.c b/src/server/options.c
index 21c360c..c9d5513 100644
--- a/src/server/options.c
+++ b/src/server/options.c
@@ -101,7 +101,7 @@ options_print_version(void)
}
#define SPD_OPTION_SET_STR(param) \
- SpeechdOptions.param = strdup(optarg)
+ SpeechdOptions.param = g_strdup(optarg)
void
options_parse(int argc, char *argv[])
@@ -164,7 +164,7 @@ options_parse(int argc, char *argv[])
if (!tmpdir)
tmpdir = g_strdup("/tmp");
SpeechdOptions.debug_destination=g_strdup_printf("%s/speechd-debug",
tmpdir);
- spd_free(tmpdir);
+ g_free(tmpdir);
ret = mkdir(SpeechdOptions.debug_destination, S_IRWXU);
if (ret){
@@ -181,7 +181,7 @@ options_parse(int argc, char *argv[])
SpeechdOptions.debug_destination);
/* Open logfile for writing */
debug_logfile = fopen(debug_logfile_path, "wx");
- spd_free(debug_logfile_path);
+ g_free(debug_logfile_path);
if (debug_logfile == NULL){
MSG(1, "Error: can't open additional debug logging file %s
[%d-%s]!\n",
debug_logfile_path, errno, strerror(errno));
diff --git a/src/server/output.c b/src/server/output.c
index 92d896e..7f00f58 100644
--- a/src/server/output.c
+++ b/src/server/output.c
@@ -61,7 +61,7 @@ char *strndup ( const char *s, size_t n)
nAvail = n + 1;
else
nAvail = strlen(s) + 1;
- p = malloc ( nAvail );
+ p = g_malloc ( nAvail );
memcpy ( p, s, nAvail );
p[nAvail - 1] = '\0';
@@ -87,7 +87,7 @@ ssize_t getline (char **lineptr, size_t *n, FILE *f)
if ( m++ >= buf_len )
{
buf_len += BUFFER_LEN;
- buf = (char *) realloc(buf, buf_len + 1);
+ buf = (char *) g_realloc(buf, buf_len + 1);
if ( buf == NULL )
{
return -1;
@@ -242,7 +242,7 @@ output_read_reply(OutputModule *output)
}while( !errors && !((strlen(line) < 4) || (line[3] == ' ')));
if(line != NULL)
- free(line); /* getline allocates with malloc and realloc. */
+ g_free(line);
if(errors) {
g_string_free(rstr, TRUE);
@@ -259,7 +259,7 @@ output_read_reply2(OutputModule *output)
char *reply;
- reply = malloc( 1024 * sizeof(char));
+ reply = g_malloc( 1024 * sizeof(char));
bytes = read(output->pipe_out[0], reply, 1024);
reply[bytes] = 0;
@@ -350,7 +350,7 @@ _output_get_voices(OutputModule *module)
//TODO: only 256 voices supported here
lines = g_strsplit(reply->str, "\n", 256);
g_string_free(reply, TRUE);
- voice_dscr = malloc(256*sizeof(VoiceDescription*));
+ voice_dscr = g_malloc(256*sizeof(VoiceDescription*));
for (i = 0; !errors && (lines[i] != NULL); i++) {
MSG(1, "LINE here:|%s|", lines[i]);
if (strlen(lines[i])<=4){
@@ -368,10 +368,10 @@ _output_get_voices(OutputModule *module)
errors = TRUE;
} else {
//Fill in VoiceDescription
- voice_dscr[i] = (VoiceDescription*) malloc(sizeof(VoiceDescription));
- voice_dscr[i]->name=strdup(atoms[0]);
- voice_dscr[i]->language=strdup(atoms[1]);
- voice_dscr[i]->dialect=strdup(atoms[2]);
+ voice_dscr[i] = (VoiceDescription*) g_malloc(sizeof(VoiceDescription));
+ voice_dscr[i]->name=g_strdup(atoms[0]);
+ voice_dscr[i]->language=g_strdup(atoms[1]);
+ voice_dscr[i]->dialect=g_strdup(atoms[2]);
}
if (atoms != NULL)
g_strfreev(atoms);
@@ -436,7 +436,7 @@ output_list_voices(char* module_name)
}else{ \
g_string_append_printf(set_str, #name"=NULL\n"); \
} \
- spd_free(val);
+ g_free(val);
int
output_send_settings(TSpeechDMessage *msg, OutputModule *output)
@@ -535,7 +535,7 @@ output_send_debug(OutputModule *output, int flag, char*
log_path)
if (flag){
cmd_str = g_strdup_printf("DEBUG ON %s \n", log_path);
err = output_send_data(cmd_str, output, 1);
- spd_free(cmd_str);
+ g_free(cmd_str);
if (err){
MSG(3, "ERROR: Can't set debugging on for output module %s",
output->name);
OL_RET(-1);
@@ -692,13 +692,13 @@ output_module_is_speaking(OutputModule *output, char
**index_mark)
retcode = 0;
MSG2(5, "output_module", "Received event:\n %s", response->str);
if (!strncmp(response->str, "701", 3))
- *index_mark = (char*) strdup("__spd_begin");
+ *index_mark = (char*) g_strdup("__spd_begin");
else if (!strncmp(response->str, "702", 3))
- *index_mark = (char*) strdup("__spd_end");
+ *index_mark = (char*) g_strdup("__spd_end");
else if (!strncmp(response->str, "703", 3))
- *index_mark = (char*) strdup("__spd_stopped");
+ *index_mark = (char*) g_strdup("__spd_stopped");
else if (!strncmp(response->str, "704", 3))
- *index_mark = (char*) strdup("__spd_paused");
+ *index_mark = (char*) g_strdup("__spd_paused");
else if (!strncmp(response->str, "700", 3)) {
char *p;
p = strchr(response->str, '\n');
@@ -902,7 +902,7 @@ escape_dot(char *otext)
ret = otext;
}else{
g_string_append(ntext, otext);
- free(ootext);
+ g_free(ootext);
ret = ntext->str;
g_string_free(ntext, 0);
}
diff --git a/src/server/parse.c b/src/server/parse.c
index 3b355f0..8b64913 100644
--- a/src/server/parse.c
+++ b/src/server/parse.c
@@ -49,15 +49,15 @@
#define CHECK_SSIP_COMMAND(cmd_name, parse_function, allowed_in_block)\
if(!strcmp(command, cmd_name)){ \
- spd_free(command); \
+ g_free(command); \
if ((allowed_in_block == BLOCK_NO) && speechd_socket->inside_block) \
- return strdup(ERR_NOT_ALLOWED_INSIDE_BLOCK); \
+ return g_strdup(ERR_NOT_ALLOWED_INSIDE_BLOCK); \
return (char*) (parse_function) (buf, bytes, fd, speechd_socket);
\
}
#define NOT_ALLOWED_INSIDE_BLOCK() \
if(speechd_socket->inside_block > 0) \
- return strdup(ERR_NOT_ALLOWED_INSIDE_BLOCK);
+ return g_strdup(ERR_NOT_ALLOWED_INSIDE_BLOCK);
#define ALLOWED_INSIDE_BLOCK() ;
@@ -79,7 +79,7 @@ parse(const char *buf, const int bytes, const int fd)
end_data = 0;
if ((buf == NULL) || (bytes == 0)){
if(SPEECHD_DEBUG) FATAL("invalid buffer for parse()\n");
- return strdup(ERR_INTERNAL);
+ return g_strdup(ERR_INTERNAL);
}
/* First the condition that we are not in data mode and we
@@ -95,7 +95,7 @@ parse(const char *buf, const int bytes, const int fd)
if (command == NULL){
if(SPEECHD_DEBUG) FATAL("Invalid buffer for parse()\n");
- return strdup(ERR_INTERNAL);
+ return g_strdup(ERR_INTERNAL);
}
CHECK_SSIP_COMMAND("set", parse_set, BLOCK_OK);
@@ -121,24 +121,24 @@ parse(const char *buf, const int bytes, const int fd)
speechd_connection_destroy(fd);
/* This is internal Speech Dispatcher message, see serve() */
- spd_free(command);
- return strdup("999 CLIENT GONE"); /* This is an internal message,
not part of SSIP */
+ g_free(command);
+ return g_strdup("999 CLIENT GONE"); /* This is an internal
message, not part of SSIP */
}
if (!strcmp(command,"speak")){
- spd_free(command);
+ g_free(command);
/* Ckeck if we have enough space in awaiting_data table for
* this client, that can have higher file descriptor that
* everything we got before */
r = server_data_on(fd);
if (r!=0){
if(SPEECHD_DEBUG) FATAL("Can't switch to data on mode\n");
- return strdup(ERR_INTERNAL);
+ return g_strdup(ERR_INTERNAL);
}
- return strdup(OK_RECEIVE_DATA);
+ return g_strdup(OK_RECEIVE_DATA);
}
- spd_free(command);
- return strdup(ERR_INVALID_COMMAND);
+ g_free(command);
+ return g_strdup(ERR_INVALID_COMMAND);
/* The other case is that we are in awaiting_data mode and
* we are waiting for text that is comming through the chanel */
@@ -163,17 +163,17 @@ parse(const char *buf, const int bytes, const int fd)
if ((bytes == 3) && (speechd_socket->o_bytes > 2))
speechd_socket->o_bytes -= 2;
/* Check if message contains any data */
- if (speechd_socket->o_bytes == 0) return strdup(OK_MSG_CANCELED);
+ if (speechd_socket->o_bytes == 0) return g_strdup(OK_MSG_CANCELED);
/* Check buffer for proper UTF-8 encoding */
if (!g_utf8_validate(speechd_socket->o_buf->str,
speechd_socket->o_bytes, NULL))
{
MSG(4, "ERROR: Invalid character encoding on input (failed
UTF-8 validation)");
MSG(4, "Rejecting this message.");
- return strdup(ERR_INVALID_ENCODING);
+ return g_strdup(ERR_INVALID_ENCODING);
}
- new = (TSpeechDMessage*) spd_malloc(sizeof(TSpeechDMessage));
+ new = (TSpeechDMessage*) g_malloc(sizeof(TSpeechDMessage));
new->bytes = speechd_socket->o_bytes;
assert(speechd_socket->o_buf != NULL);
new->buf = deescape_dot(speechd_socket->o_buf->str, new->bytes);
@@ -181,9 +181,9 @@ parse(const char *buf, const int bytes, const int fd)
MSG(5, "New buf is now: |%s|", new->buf);
if((msg_uid = queue_message(new, fd, 1, MSGTYPE_TEXT, reparted))
== 0){
if(SPEECHD_DEBUG) FATAL("Can't queue message\n");
- free(new->buf);
- free(new);
- return strdup(ERR_INTERNAL);
+ g_free(new->buf);
+ g_free(new);
+ return g_strdup(ERR_INTERNAL);
}
/* Clear the counter of bytes in the output buffer. */
@@ -219,7 +219,7 @@ parse(const char *buf, const int bytes, const int fd)
if (end_data == 1) goto enddata;
/* Don't reply on data */
- return strdup("999 DATA");
+ return g_strdup("999 DATA");
}
#undef CHECK_SSIP_COMMAND
@@ -227,7 +227,7 @@ parse(const char *buf, const int bytes, const int fd)
#define CHECK_PARAM(param) \
if (param == NULL){ \
MSG(4, "Missing parameter from client"); \
- return strdup(ERR_MISSING_PARAMETER); \
+ return g_strdup(ERR_MISSING_PARAMETER); \
}
#define GET_PARAM_INT(name, pos) \
@@ -236,11 +236,11 @@ parse(const char *buf, const int bytes, const int fd)
helper = get_param(buf, pos, bytes, 0); \
CHECK_PARAM(helper); \
if (!isanum(helper)){ \
- spd_free(helper); \
- return strdup(ERR_NOT_A_NUMBER); \
+ g_free(helper); \
+ return g_strdup(ERR_NOT_A_NUMBER); \
} \
name = atoi(helper); \
- spd_free(helper); \
+ g_free(helper); \
}
#define CONV_DOWN 1
@@ -253,7 +253,7 @@ parse(const char *buf, const int bytes, const int fd)
/* Tests if cmd is the same as str AND deallocates cmd if
the test is succesful */
#define TEST_CMD(cmd, str) \
- (!strcmp(cmd, str) ? spd_free(cmd), 1 : 0 )
+ (!strcmp(cmd, str) ? g_free(cmd), 1 : 0 )
/* Parses @history commands and calls the appropriate history_ functions. */
char*
@@ -280,11 +280,11 @@ parse_history(const char *buf, const int bytes, const int
fd, const TSpeechDSock
/* TODO: This needs to be (sim || am)-plified */
who = get_param(buf,3,bytes, 1);
CHECK_PARAM(who);
- if (!strcmp(who, "self")) return strdup(ERR_NOT_IMPLEMENTED);
- if (!strcmp(who, "all")) return strdup(ERR_NOT_IMPLEMENTED);
- if (!isanum(who)) return strdup(ERR_NOT_A_NUMBER);
+ if (!strcmp(who, "self")) return g_strdup(ERR_NOT_IMPLEMENTED);
+ if (!strcmp(who, "all")) return g_strdup(ERR_NOT_IMPLEMENTED);
+ if (!isanum(who)) return g_strdup(ERR_NOT_A_NUMBER);
who_id = atoi(who);
- spd_free(who);
+ g_free(who);
GET_PARAM_INT(start, 4);
GET_PARAM_INT(num, 5);
return (char*) history_get_message_list(who_id, start, num);
@@ -297,7 +297,7 @@ parse_history(const char *buf, const int bytes, const int
fd, const TSpeechDSock
GET_PARAM_INT(msg_id, 3);
return (char*) history_get_message(msg_id);
}else{
- return strdup(ERR_MISSING_PARAMETER);
+ return g_strdup(ERR_MISSING_PARAMETER);
}
}
else if (TEST_CMD(cmd_main, "cursor")){
@@ -323,8 +323,8 @@ parse_history(const char *buf, const int bytes, const int
fd, const TSpeechDSock
return (char*) history_cursor_set_pos(fd, who, pos);
}
else{
- spd_free(location);
- return strdup(ERR_MISSING_PARAMETER);
+ g_free(location);
+ return g_strdup(ERR_MISSING_PARAMETER);
}
}
else if (TEST_CMD(hist_cur_sub, "forward")){
@@ -336,8 +336,8 @@ parse_history(const char *buf, const int bytes, const int
fd, const TSpeechDSock
else if (TEST_CMD(hist_cur_sub,"get")){
return (char*) history_cursor_get(fd);
}else{
- spd_free(hist_cur_sub);
- return strdup(ERR_MISSING_PARAMETER);
+ g_free(hist_cur_sub);
+ return g_strdup(ERR_MISSING_PARAMETER);
}
}
@@ -348,15 +348,15 @@ parse_history(const char *buf, const int bytes, const int
fd, const TSpeechDSock
}
else if (TEST_CMD(cmd_main,"sort")){
// TODO: everything :)
- return strdup(ERR_NOT_IMPLEMENTED);
+ return g_strdup(ERR_NOT_IMPLEMENTED);
}
else{
- spd_free(cmd_main);
- return strdup(ERR_MISSING_PARAMETER);
+ g_free(cmd_main);
+ return g_strdup(ERR_MISSING_PARAMETER);
}
- return strdup(ERR_INVALID_COMMAND);
+ return g_strdup(ERR_INVALID_COMMAND);
}
#define SSIP_SET_COMMAND(param) \
@@ -376,12 +376,12 @@ parse_history(const char *buf, const int bytes, const int
fd, const TSpeechDSock
if(TEST_CMD(helper_s, "on")) param = 1; \
else if(TEST_CMD(helper_s, "off")) param = 0; \
else{ \
- spd_free(helper_s); \
- return strdup(ERR_PARAMETER_NOT_ON_OFF); \
+ g_free(helper_s); \
+ return g_strdup(ERR_PARAMETER_NOT_ON_OFF); \
} \
SSIP_SET_COMMAND(param); \
- if (ret) return strdup(err_message); \
- return strdup(ok_message); \
+ if (ret) return g_strdup(err_message); \
+ return g_strdup(ok_message); \
}
char*
@@ -401,10 +401,10 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
else if (isanum(who_s)){
who = 1;
uid = atoi(who_s);
- spd_free(who_s);
+ g_free(who_s);
}else{
- spd_free(who_s);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(who_s);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
GET_PARAM_STR(set_sub, 2, CONV_DOWN);
@@ -415,7 +415,7 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
NOT_ALLOWED_INSIDE_BLOCK();
/* Setting priority only allowed for "self" */
- if (who != 0) return strdup(ERR_COULDNT_SET_PRIORITY);
+ if (who != 0) return g_strdup(ERR_COULDNT_SET_PRIORITY);
GET_PARAM_STR(priority_s, 3, CONV_DOWN);
if (TEST_CMD(priority_s, "important")) priority = 1;
@@ -424,13 +424,13 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
else if (TEST_CMD(priority_s, "notification")) priority = 4;
else if (TEST_CMD(priority_s, "progress")) priority = 5;
else{
- spd_free(priority_s);
- return strdup(ERR_UNKNOWN_PRIORITY);
+ g_free(priority_s);
+ return g_strdup(ERR_UNKNOWN_PRIORITY);
}
ret = set_priority_self(fd, priority);
- if (ret) return strdup(ERR_COULDNT_SET_PRIORITY);
- return strdup(OK_PRIORITY_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_PRIORITY);
+ return g_strdup(OK_PRIORITY_SET);
}
else if (TEST_CMD(set_sub, "language")){
char *language;
@@ -438,10 +438,10 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
GET_PARAM_STR(language, 3, CONV_DOWN);
SSIP_SET_COMMAND(language);
- spd_free(language);
+ g_free(language);
- if (ret) return strdup(ERR_COULDNT_SET_LANGUAGE);
- return strdup(OK_LANGUAGE_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_LANGUAGE);
+ return g_strdup(OK_LANGUAGE_SET);
}
else if (TEST_CMD(set_sub, "synthesis_voice")){
char *synthesis_voice;
@@ -449,68 +449,68 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
GET_PARAM_STR(synthesis_voice, 3, CONV_DOWN);
SSIP_SET_COMMAND(synthesis_voice);
- spd_free(synthesis_voice);
+ g_free(synthesis_voice);
- if (ret) return strdup(ERR_COULDNT_SET_VOICE);
- return strdup(OK_VOICE_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_VOICE);
+ return g_strdup(OK_VOICE_SET);
}
else if (TEST_CMD(set_sub, "client_name")){
char *client_name;
NOT_ALLOWED_INSIDE_BLOCK();
/* Setting client name only allowed for "self" */
- if (who != 0) return strdup(ERR_PARAMETER_INVALID);
+ if (who != 0) return g_strdup(ERR_PARAMETER_INVALID);
GET_PARAM_STR(client_name, 3, CONV_DOWN);
ret = set_client_name_self(fd, client_name);
- spd_free(client_name);
+ g_free(client_name);
- if (ret) return strdup(ERR_COULDNT_SET_CLIENT_NAME);
- return strdup(OK_CLIENT_NAME_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_CLIENT_NAME);
+ return g_strdup(OK_CLIENT_NAME_SET);
}
else if (TEST_CMD(set_sub, "rate")){
signed int rate;
GET_PARAM_INT(rate, 3);
- if(rate < -100) return strdup(ERR_RATE_TOO_LOW);
- if(rate > +100) return strdup(ERR_RATE_TOO_HIGH);
+ if(rate < -100) return g_strdup(ERR_RATE_TOO_LOW);
+ if(rate > +100) return g_strdup(ERR_RATE_TOO_HIGH);
SSIP_SET_COMMAND(rate);
- if (ret) return strdup(ERR_COULDNT_SET_RATE);
- return strdup(OK_RATE_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_RATE);
+ return g_strdup(OK_RATE_SET);
}
else if (TEST_CMD(set_sub, "pitch")){
signed int pitch;
GET_PARAM_INT(pitch, 3);
- if(pitch < -100) return strdup(ERR_PITCH_TOO_LOW);
- if(pitch > +100) return strdup(ERR_PITCH_TOO_HIGH);
+ if(pitch < -100) return g_strdup(ERR_PITCH_TOO_LOW);
+ if(pitch > +100) return g_strdup(ERR_PITCH_TOO_HIGH);
SSIP_SET_COMMAND(pitch);
- if (ret) return strdup(ERR_COULDNT_SET_PITCH);
- return strdup(OK_PITCH_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_PITCH);
+ return g_strdup(OK_PITCH_SET);
}
else if (TEST_CMD(set_sub, "volume")){
signed int volume;
GET_PARAM_INT(volume, 3);
- if(volume < -100) return strdup(ERR_VOLUME_TOO_LOW);
- if(volume > +100) return strdup(ERR_VOLUME_TOO_HIGH);
+ if(volume < -100) return g_strdup(ERR_VOLUME_TOO_LOW);
+ if(volume > +100) return g_strdup(ERR_VOLUME_TOO_HIGH);
SSIP_SET_COMMAND(volume);
- if (ret) return strdup(ERR_COULDNT_SET_VOLUME);
- return strdup(OK_VOLUME_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_VOLUME);
+ return g_strdup(OK_VOLUME_SET);
}
else if (TEST_CMD(set_sub, "voice")){
char *voice;
GET_PARAM_STR(voice, 3, CONV_DOWN);
SSIP_SET_COMMAND(voice);
- spd_free(voice);
+ g_free(voice);
- if (ret) return strdup(ERR_COULDNT_SET_VOICE);
- return strdup(OK_VOICE_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_VOICE);
+ return g_strdup(OK_VOICE_SET);
}
else if (TEST_CMD(set_sub, "punctuation")){
char *punct_s;
@@ -523,14 +523,14 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
else if(TEST_CMD(punct_s,"some")) punctuation_mode = PUNCT_SOME;
else if(TEST_CMD(punct_s,"none")) punctuation_mode = PUNCT_NONE;
else{
- spd_free(punct_s);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(punct_s);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
SSIP_SET_COMMAND(punctuation_mode);
- if (ret) return strdup(ERR_COULDNT_SET_PUNCT_MODE);
- return strdup(OK_PUNCT_MODE_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_PUNCT_MODE);
+ return g_strdup(OK_PUNCT_MODE_SET);
}
else if (TEST_CMD(set_sub, "output_module")){
char *output_module;
@@ -538,10 +538,10 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
GET_PARAM_STR(output_module, 3, CONV_DOWN);
SSIP_SET_COMMAND(output_module);
- spd_free(output_module);
+ g_free(output_module);
- if (ret) return strdup(ERR_COULDNT_SET_OUTPUT_MODULE);
- return strdup(OK_OUTPUT_MODULE_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_OUTPUT_MODULE);
+ return g_strdup(OK_OUTPUT_MODULE_SET);
}
else if (TEST_CMD(set_sub, "cap_let_recogn")){
int capital_letter_recognition;
@@ -553,22 +553,22 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
else if(TEST_CMD(recognition, "spell")) capital_letter_recognition =
RECOGN_SPELL;
else if(TEST_CMD(recognition, "icon")) capital_letter_recognition =
RECOGN_ICON;
else{
- spd_free(recognition);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(recognition);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
SSIP_SET_COMMAND(capital_letter_recognition);
- if (ret) return strdup(ERR_COULDNT_SET_CAP_LET_RECOG);
- return strdup(OK_CAP_LET_RECOGN_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_CAP_LET_RECOG);
+ return g_strdup(OK_CAP_LET_RECOGN_SET);
}
else if (TEST_CMD(set_sub, "pause_context")){
int pause_context;
GET_PARAM_INT(pause_context, 3);
SSIP_SET_COMMAND(pause_context);
- if (ret) return strdup(ERR_COULDNT_SET_PAUSE_CONTEXT);
- return strdup(OK_PAUSE_CONTEXT_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_PAUSE_CONTEXT);
+ return g_strdup(OK_PAUSE_CONTEXT_SET);
}
else SSIP_ON_OFF_PARAM(spelling,
OK_SPELLING_SET, ERR_COULDNT_SET_SPELLING,
@@ -583,7 +583,7 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
char *par_s;
int par;
- if (who != 0) return strdup(ERR_PARAMETER_INVALID);
+ if (who != 0) return g_strdup(ERR_PARAMETER_INVALID);
GET_PARAM_STR(scope, 3, CONV_DOWN);
GET_PARAM_STR(par_s, 4, CONV_DOWN);
@@ -591,22 +591,22 @@ parse_set(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
if(TEST_CMD(par_s,"on")) par = 1;
else if(TEST_CMD(par_s,"off")) par = 0;
else{
- spd_free(par_s);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(par_s);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
ret = set_notification_self(fd, scope, par);
- spd_free(scope);
+ g_free(scope);
- if (ret) return strdup(ERR_COULDNT_SET_NOTIFICATION);
- return strdup(OK_NOTIFICATION_SET);
+ if (ret) return g_strdup(ERR_COULDNT_SET_NOTIFICATION);
+ return g_strdup(OK_NOTIFICATION_SET);
}
else{
- spd_free(set_sub);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(set_sub);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
- return strdup(ERR_INVALID_COMMAND);
+ return g_strdup(ERR_INVALID_COMMAND);
}
#undef SSIP_SET_COMMAND
@@ -627,25 +627,25 @@ parse_stop(const char *buf, const int bytes, const int
fd, const TSpeechDSock *s
}
else if (TEST_CMD(who_s, "self")){
uid = get_client_uid_by_fd(fd);
- if(uid == 0) return strdup(ERR_INTERNAL);
+ if(uid == 0) return g_strdup(ERR_INTERNAL);
pthread_mutex_lock(&element_free_mutex);
speaking_stop(uid);
pthread_mutex_unlock(&element_free_mutex);
}
else if (isanum(who_s)){
uid = atoi(who_s);
- spd_free(who_s);
+ g_free(who_s);
- if (uid <= 0) return strdup(ERR_ID_NOT_EXIST);
+ if (uid <= 0) return g_strdup(ERR_ID_NOT_EXIST);
pthread_mutex_lock(&element_free_mutex);
speaking_stop(uid);
pthread_mutex_unlock(&element_free_mutex);
}else{
- spd_free(who_s);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(who_s);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
- return strdup(OK_STOPPED);
+ return g_strdup(OK_STOPPED);
}
char*
@@ -663,21 +663,21 @@ parse_cancel(const char *buf, const int bytes, const int
fd, const TSpeechDSock
}
else if (TEST_CMD(who_s, "self")){
uid = get_client_uid_by_fd(fd);
- if(uid == 0) return strdup(ERR_INTERNAL);
+ if(uid == 0) return g_strdup(ERR_INTERNAL);
speaking_cancel(uid);
}
else if (isanum(who_s)){
uid = atoi(who_s);
- spd_free(who_s);
+ g_free(who_s);
- if (uid <= 0) return strdup(ERR_ID_NOT_EXIST);
+ if (uid <= 0) return g_strdup(ERR_ID_NOT_EXIST);
speaking_cancel(uid);
}else{
- spd_free(who_s);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(who_s);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
- return strdup(OK_CANCELED);
+ return g_strdup(OK_CANCELED);
}
char*
@@ -700,7 +700,7 @@ parse_pause(const char *buf, const int bytes, const int fd,
const TSpeechDSock *
}
else if (TEST_CMD(who_s, "self")){
uid = get_client_uid_by_fd(fd);
- if(uid == 0) return strdup(ERR_INTERNAL);
+ if(uid == 0) return g_strdup(ERR_INTERNAL);
pause_requested = 2;
pause_requested_fd = fd;
pause_requested_uid = uid;
@@ -708,18 +708,18 @@ parse_pause(const char *buf, const int bytes, const int
fd, const TSpeechDSock *
}
else if (isanum(who_s)){
uid = atoi(who_s);
- spd_free(who_s);
- if (uid <= 0) return strdup(ERR_ID_NOT_EXIST);
+ g_free(who_s);
+ if (uid <= 0) return g_strdup(ERR_ID_NOT_EXIST);
pause_requested = 2;
pause_requested_fd = fd;
pause_requested_uid = uid;
speaking_semaphore_post();
}else{
- spd_free(who_s);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(who_s);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
- return strdup(OK_PAUSED);
+ return g_strdup(OK_PAUSED);
}
char*
@@ -737,20 +737,20 @@ parse_resume(const char *buf, const int bytes, const int
fd, const TSpeechDSock
}
else if (TEST_CMD(who_s, "self")){
uid = get_client_uid_by_fd(fd);
- if(uid == 0) return strdup(ERR_INTERNAL);
+ if(uid == 0) return g_strdup(ERR_INTERNAL);
speaking_resume(uid);
}
else if (isanum(who_s)){
uid = atoi(who_s);
- spd_free(who_s);
- if (uid <= 0) return strdup(ERR_ID_NOT_EXIST);
+ g_free(who_s);
+ if (uid <= 0) return g_strdup(ERR_ID_NOT_EXIST);
speaking_resume(uid);
}else{
- spd_free(who_s);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(who_s);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
- return strdup(OK_RESUMED);
+ return g_strdup(OK_RESUMED);
}
char*
@@ -761,11 +761,11 @@ parse_general_event(const char *buf, const int bytes,
const int fd, const TSpeec
GET_PARAM_STR(param, 1, NO_CONV);
- if (param == NULL) return strdup(ERR_MISSING_PARAMETER);
+ if (param == NULL) return g_strdup(ERR_MISSING_PARAMETER);
if (param[0] == 0){
- spd_free(param);
- return strdup(ERR_MISSING_PARAMETER);
+ g_free(param);
+ return g_strdup(ERR_MISSING_PARAMETER);
}
/* Check for proper UTF-8 */
@@ -774,22 +774,22 @@ parse_general_event(const char *buf, const int bytes,
const int fd, const TSpeec
{
MSG(4, "ERROR: Invalid character encoding on event input (failed UTF-8
validation)");
MSG(4, "Rejecting this event (char/key/sound_icon).");
- return strdup(ERR_INVALID_ENCODING);
+ return g_strdup(ERR_INVALID_ENCODING);
}
- msg = (TSpeechDMessage*) spd_malloc(sizeof(TSpeechDMessage));
+ msg = (TSpeechDMessage*) g_malloc(sizeof(TSpeechDMessage));
msg->bytes = strlen(param);
- msg->buf = strdup(param);
+ msg->buf = g_strdup(param);
if(queue_message(msg, fd, 1, type, speechd_socket->inside_block) == 0){
if (SPEECHD_DEBUG) FATAL("Couldn't queue message\n");
MSG(2, "Error: Couldn't queue message!\n");
}
- spd_free(param);
+ g_free(param);
- return strdup(OK_MESSAGE_QUEUED);
+ return g_strdup(OK_MESSAGE_QUEUED);
}
char*
@@ -819,7 +819,7 @@ parse_list(const char* buf, const int bytes, const int fd,
const TSpeechDSock *s
GET_PARAM_STR(list_type, 1, CONV_DOWN);
if(TEST_CMD(list_type, "voices")){
- voice_list = (char*) spd_malloc(1024);
+ voice_list = (char*) g_malloc(1024);
sprintf(voice_list,
C_OK_VOICES"-MALE1\r\n"
C_OK_VOICES"-MALE2\r\n"
@@ -862,11 +862,11 @@ parse_list(const char* buf, const int bytes, const int
fd, const TSpeechDSock *s
uid = get_client_uid_by_fd(fd);
settings = get_client_settings_by_uid(uid);
- if (settings == NULL) return strdup(ERR_INTERNAL);
+ if (settings == NULL) return g_strdup(ERR_INTERNAL);
module_name = settings->output_module;
- if (module_name == NULL) return strdup(ERR_NO_OUTPUT_MODULE);
+ if (module_name == NULL) return g_strdup(ERR_NO_OUTPUT_MODULE);
voices = output_list_voices(module_name);
- if (voices == NULL) return strdup(ERR_CANT_REPORT_VOICES);
+ if (voices == NULL) return g_strdup(ERR_CANT_REPORT_VOICES);
result = g_string_new("");
for (i=0; ; i++){
@@ -879,8 +879,8 @@ parse_list(const char* buf, const int bytes, const int fd,
const TSpeechDSock *s
g_string_free(result, 0);
return helper;
}else{
- spd_free(list_type);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(list_type);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
}
@@ -895,7 +895,7 @@ parse_get(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
settings = get_client_settings_by_fd(fd);
if (settings == NULL)
- return strdup(ERR_INTERNAL);
+ return g_strdup(ERR_INTERNAL);
GET_PARAM_STR(get_type, 1, CONV_DOWN);
if(TEST_CMD(get_type, "voice")) {
@@ -945,8 +945,8 @@ parse_get(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
return helper;
}
else{
- spd_free(get_type);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(get_type);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
}
@@ -955,7 +955,7 @@ parse_help(const char* buf, const int bytes, const int fd,
const TSpeechDSock *s
{
char *help;
- help = (char*) spd_malloc(1024 * sizeof(char));
+ help = (char*) g_malloc(1024 * sizeof(char));
sprintf(help,
C_OK_HELP"- SPEAK -- say text \r\n"
@@ -982,23 +982,23 @@ parse_block(const char *buf, const int bytes, const int
fd, TSpeechDSock* speech
assert(speechd_socket->inside_block >= 0);
if (speechd_socket->inside_block == 0){
speechd_socket->inside_block = ++SpeechdStatus.max_gid;
- return strdup(OK_INSIDE_BLOCK);
+ return g_strdup(OK_INSIDE_BLOCK);
}else{
- return strdup(ERR_ALREADY_INSIDE_BLOCK);
+ return g_strdup(ERR_ALREADY_INSIDE_BLOCK);
}
}
else if (TEST_CMD(cmd_main, "end")){
assert(speechd_socket->inside_block >= 0);
if (speechd_socket->inside_block > 0){
speechd_socket->inside_block = 0;
- return strdup(OK_OUTSIDE_BLOCK);
+ return g_strdup(OK_OUTSIDE_BLOCK);
}else{
- return strdup(ERR_ALREADY_OUTSIDE_BLOCK);
+ return g_strdup(ERR_ALREADY_OUTSIDE_BLOCK);
}
}
else{
- spd_free(cmd_main);
- return strdup(ERR_PARAMETER_INVALID);
+ g_free(cmd_main);
+ return g_strdup(ERR_PARAMETER_INVALID);
}
}
@@ -1035,10 +1035,10 @@ deescape_dot(const char *orig_text, size_t orig_len)
if (orig_text == NULL)
return NULL;
- out_text = spd_malloc(orig_len + 1);
+ out_text = g_malloc(orig_len + 1);
/* We may have allocated more than we need. In any case, out_text
* can be no longer than orig_text.
- * Note: spd_malloc aborts the program on failure to allocate. */
+ * Note: g_malloc aborts the program on failure to allocate. */
out_ptr = out_text;
if (orig_len >= 2) {
@@ -1089,7 +1089,7 @@ get_param(const char *buf, const int n, const int bytes,
const int lower_case)
int i, y, z = 0;
assert (bytes != 0);
- param = (char*) spd_malloc(bytes);
+ param = (char*) g_malloc(bytes);
assert(param != NULL);
strcpy(param,"");
@@ -1109,7 +1109,7 @@ get_param(const char *buf, const int n, const int bytes,
const int lower_case)
}
if(z <= 0){
- spd_free(param);
+ g_free(param);
return NULL;
}
@@ -1122,7 +1122,7 @@ get_param(const char *buf, const int n, const int bytes,
const int lower_case)
if(lower_case){
par = g_ascii_strdown(param, strlen(param));
- spd_free(param);
+ g_free(param);
}else{
par = param;
}
diff --git a/src/server/server.c b/src/server/server.c
index 2d3858f..c235553 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -50,7 +50,7 @@ int last_message_id = 0;
*/
#define COPY_SET_STR(name) \
- new->settings.name = (char*) spd_strdup(settings->name);
+ new->settings.name = (char*) g_strdup(settings->name);
/* Queue a message _new_. When fd is a positive number,
it means we have a new message from the client on connection
@@ -237,7 +237,7 @@ serve(int fd)
{
size_t bytes = 0; /* Number of bytes we got */
int buflen = BUF_SIZE;
- char *buf = (char *)spd_malloc (buflen + 1);
+ char *buf = (char *)g_malloc (buflen + 1);
/* Read data from socket */
/* Read exactly one complete line, the `parse' routine relies on it */
@@ -247,7 +247,7 @@ serve(int fd)
int n = read (fd, buf+bytes, 1);
if (n <= 0)
{
- spd_free (buf);
+ g_free (buf);
return -1;
}
/* Note, bytes is a 0-based index into buf. */
@@ -260,7 +260,7 @@ serve(int fd)
if ((++bytes) == buflen)
{
buflen *= 2;
- buf = spd_realloc (buf, buflen + 1);
+ buf = g_realloc (buf, buflen + 1);
}
}
}
@@ -268,28 +268,28 @@ serve(int fd)
/* Parse the data and read the reply*/
MSG2(5, "protocol", "%d:DATA:|%s| (%d)", fd, buf, bytes);
reply = parse(buf, bytes, fd);
- spd_free(buf);
+ g_free(buf);
}
if (reply == NULL) FATAL("Internal error, reply from parse() is NULL!");
/* Send the reply to the socket */
if (strlen(reply) == 0){
- spd_free(reply);
+ g_free(reply);
return 0;
}
if(reply[0] != '9'){ /* Don't reply to data etc. */
pthread_mutex_lock(&socket_com_mutex);
MSG2(5, "protocol", "%d:REPLY:|%s|", fd, reply);
ret = write(fd, reply, strlen(reply));
- spd_free(reply);
+ g_free(reply);
pthread_mutex_unlock(&socket_com_mutex);
if (ret == -1){
MSG(5, "write() error: %s", strerror(errno));
return -1;
}
}else{
- spd_free(reply);
+ g_free(reply);
}
return 0;
diff --git a/src/server/set.c b/src/server/set.c
index 7fb5956..37d6da5 100644
--- a/src/server/set.c
+++ b/src/server/set.c
@@ -32,7 +32,6 @@
#include "alloc.h"
#include "msg.h"
-extern char *spd_strdup(char*);
gint
spd_str_compare(gconstpointer a, gconstpointer b)
@@ -159,7 +158,7 @@ set_voice_uid(int uid, char *voice)
else return 1;
if (settings->synthesis_voice != NULL){
- free(settings->synthesis_voice);
+ g_free(settings->synthesis_voice);
settings->synthesis_voice = NULL;
}
return 0;
@@ -258,8 +257,8 @@ set_synthesis_voice_uid(int uid, char *synthesis_voice)
MSG(4,"parameter " #name " set to %d", cl_set->val.name); }
#define CHECK_SET_PAR_STR(name) \
if (cl_set->val.name != NULL){ \
- spd_free(set->name); \
- set->name = strdup(cl_set->val.name); \
+ g_free(set->name); \
+ set->name = g_strdup(cl_set->val.name); \
MSG(4,"parameter " #name " set to %s", cl_set->val.name); \
}
@@ -337,7 +336,7 @@ set_output_module_uid(int uid, char* output_module)
/* Delete synth_voice since it is module specific */
if (settings->synthesis_voice != NULL){
- free(settings->synthesis_voice);
+ g_free(settings->synthesis_voice);
settings->synthesis_voice = NULL;
}
@@ -395,7 +394,7 @@ set_debug_uid(int uid, int debug)
}
SpeechdOptions.debug = debug;
- spd_free(debug_logfile_path);
+ g_free(debug_logfile_path);
/* Redirecting debugging for all output modules */
speechd_modules_debug();
@@ -460,7 +459,7 @@ default_fd_set(void)
{
TFDSetElement *new;
- new = (TFDSetElement*) spd_malloc(sizeof(TFDSetElement));
+ new = (TFDSetElement*) g_malloc(sizeof(TFDSetElement));
new->paused = 0;
@@ -472,15 +471,15 @@ default_fd_set(void)
new->rate = GlobalFDSet.rate;
new->pitch = GlobalFDSet.pitch;
new->volume = GlobalFDSet.volume;
- new->language = spd_strdup(GlobalFDSet.language);
- new->output_module = spd_strdup(GlobalFDSet.output_module);
- new->client_name = spd_strdup(GlobalFDSet.client_name);
- new->index_mark = spd_strdup(GlobalFDSet.index_mark);
- new->audio_output_method = spd_strdup(GlobalFDSet.audio_output_method);
- new->audio_oss_device = spd_strdup(GlobalFDSet.audio_oss_device);
- new->audio_alsa_device = spd_strdup(GlobalFDSet.audio_alsa_device);
- new->audio_nas_server = spd_strdup(GlobalFDSet.audio_nas_server);
- new->audio_pulse_server = spd_strdup(GlobalFDSet.audio_pulse_server);
+ new->language = g_strdup(GlobalFDSet.language);
+ new->output_module = g_strdup(GlobalFDSet.output_module);
+ new->client_name = g_strdup(GlobalFDSet.client_name);
+ new->index_mark = g_strdup(GlobalFDSet.index_mark);
+ new->audio_output_method = g_strdup(GlobalFDSet.audio_output_method);
+ new->audio_oss_device = g_strdup(GlobalFDSet.audio_oss_device);
+ new->audio_alsa_device = g_strdup(GlobalFDSet.audio_alsa_device);
+ new->audio_nas_server = g_strdup(GlobalFDSet.audio_nas_server);
+ new->audio_pulse_server = g_strdup(GlobalFDSet.audio_pulse_server);
new->voice = GlobalFDSet.voice;
new->synthesis_voice = NULL;
@@ -564,7 +563,7 @@ set_param_str(char* parameter, char* value)
return new;
}
- new = realloc(parameter, (strlen(value) + 1) * sizeof(char));
+ new = g_realloc(parameter, (strlen(value) + 1) * sizeof(char));
strcpy(new, value);
return new;
diff --git a/src/server/speaking.c b/src/server/speaking.c
index 678dbe6..17a3ec9 100644
--- a/src/server/speaking.c
+++ b/src/server/speaking.c
@@ -63,7 +63,7 @@ speak(void* data)
/* Block all signals and set thread states */
set_speak_thread_attributes();
- poll_fds = spd_malloc (2 * sizeof(struct pollfd));
+ poll_fds = g_malloc (2 * sizeof(struct pollfd));
main_pfd.fd = speaking_pipe[0];
main_pfd.events = POLLIN;
@@ -298,7 +298,7 @@ reload_message(TSpeechDMessage *msg)
}
newtext = strip_index_marks(pos, client_settings->ssml_mode);
- spd_free(msg->buf);
+ g_free(msg->buf);
if (newtext == NULL) return -1;
msg->buf = newtext;
@@ -306,8 +306,8 @@ reload_message(TSpeechDMessage *msg)
if(queue_message(msg, -msg->settings.uid, 0, MSGTYPE_TEXT, 0) == 0){
if(SPEECHD_DEBUG) FATAL("Can't queue message\n");
- spd_free(msg->buf);
- spd_free(msg);
+ g_free(msg->buf);
+ g_free(msg);
return -1;
}
@@ -317,8 +317,8 @@ reload_message(TSpeechDMessage *msg)
if(queue_message(msg, -msg->settings.uid, 0, MSGTYPE_TEXT, 0) == 0){
if(SPEECHD_DEBUG) FATAL("Can't queue message\n");
- spd_free(msg->buf);
- spd_free(msg);
+ g_free(msg->buf);
+ g_free(msg);
return -1;
}
@@ -569,7 +569,7 @@ report_index_mark(TSpeechDMessage *msg, char *index_mark)
MSG(1, "ERROR: Can't report index mark!");
return -1;
}
- spd_free(cmd);
+ g_free(cmd);
return 0;
}
@@ -586,7 +586,7 @@ report_index_mark(TSpeechDMessage *msg, char *index_mark)
MSG(2, "ERROR: Can't report index mark!"); \
return -1; \
} \
- spd_free(cmd); \
+ g_free(cmd); \
return 0; \
}
@@ -618,7 +618,7 @@ is_sb_speaking(void)
if (index_mark == NULL) return SPEAKING=0;
if (!strcmp(index_mark, "no")){
- spd_free(index_mark);
+ g_free(index_mark);
return SPEAKING;
}
@@ -661,12 +661,12 @@ is_sb_speaking(void)
}else{
MSG(5, "Setting current index_mark for the message to %s",
index_mark);
if (current_message->settings.index_mark != NULL)
- free(current_message->settings.index_mark);
- current_message->settings.index_mark = strdup(index_mark);
+ g_free(current_message->settings.index_mark);
+ current_message->settings.index_mark = g_strdup(index_mark);
}
}
- spd_free(index_mark);
+ g_free(index_mark);
}else{
MSG(5, "Speaking module is NULL, SPEAKING==%d", SPEAKING);
SPEAKING = 0;
diff --git a/src/server/speechd.c b/src/server/speechd.c
index 547a937..9a360c5 100644
--- a/src/server/speechd.c
+++ b/src/server/speechd.c
@@ -142,7 +142,7 @@ MSG2(int level, char *kind, char *format, ...)
char *tstr;
struct timeval tv;
t = time(NULL);
- tstr = strdup(ctime(&t));
+ tstr = g_strdup(ctime(&t));
gettimeofday(&tv,NULL);
assert(tstr);
/* Remove the trailing \n */
@@ -162,7 +162,7 @@ MSG2(int level, char *kind, char *format, ...)
fprintf(debug_logfile, "[%s : %d] speechd: ",
tstr, (int) tv.tv_usec);
}
- spd_free(tstr);
+ g_free(tstr);
}
for(i=1;i<level;i++){
if(std_log) {
@@ -221,7 +221,7 @@ MSG(int level, char *format, ...)
char *tstr;
struct timeval tv;
t = time(NULL);
- tstr = strdup(ctime(&t));
+ tstr = g_strdup(ctime(&t));
gettimeofday(&tv,NULL);
/* Remove the trailing \n */
assert(tstr);
@@ -237,7 +237,7 @@ MSG(int level, char *format, ...)
tstr, (int) tv.tv_usec);
/* fprintf(logfile, "[%s : %d] speechd: ",
tstr, (int) tv.tv_usec);*/
- spd_free(tstr);
+ g_free(tstr);
}
for(i=1;i<level;i++){
@@ -279,7 +279,7 @@ int
speechd_sockets_status_init(void)
{
speechd_sockets_status = g_hash_table_new_full(g_int_hash, g_int_equal,
- (GDestroyNotify) spd_free,
+ (GDestroyNotify) g_free,
(GDestroyNotify)
speechd_socket_free);
if (speechd_sockets_status)
return 0;
@@ -293,12 +293,12 @@ speechd_socket_register(int fd)
{
int *fd_key;
TSpeechDSock* speechd_socket;
- speechd_socket = spd_malloc(sizeof(TSpeechDSock));
+ speechd_socket = g_malloc(sizeof(TSpeechDSock));
speechd_socket->o_buf = NULL;
speechd_socket->o_bytes = 0;
speechd_socket->awaiting_data = 0;
speechd_socket->inside_block = 0;
- fd_key = spd_malloc(sizeof(int));
+ fd_key = g_malloc(sizeof(int));
*fd_key = fd;
g_hash_table_insert(speechd_sockets_status, fd_key, speechd_socket);
return 0;
@@ -310,7 +310,7 @@ speechd_socket_free(TSpeechDSock* speechd_socket)
{
if (speechd_socket->o_buf)
g_string_free(speechd_socket->o_buf, 1);
- spd_free(speechd_socket);
+ g_free(speechd_socket);
}
/* Unregister a socket for SSIP communication */
@@ -362,9 +362,9 @@ speechd_connection_new(int server_socket)
}
new_fd_set->fd = client_socket;
new_fd_set->uid = ++SpeechdStatus.max_uid;
- p_client_socket = (int*) spd_malloc(sizeof(int));
- p_client_uid = (int*) spd_malloc(sizeof(int));
- p_client_uid2 = (int*) spd_malloc(sizeof(int));
+ p_client_socket = (int*) g_malloc(sizeof(int));
+ p_client_uid = (int*) g_malloc(sizeof(int));
+ p_client_uid2 = (int*) g_malloc(sizeof(int));
*p_client_socket = client_socket;
*p_client_uid = SpeechdStatus.max_uid;
*p_client_uid2 = SpeechdStatus.max_uid;
@@ -434,7 +434,7 @@ speechd_client_terminate(gpointer key, gpointer value,
gpointer user)
speechd_connection_destroy(set->fd);
}
mem_free_fdset(set);
- spd_free(set);
+ g_free(set);
return TRUE;
}
@@ -579,13 +579,13 @@ speechd_init()
/* Initialize hash tables */
fd_settings = g_hash_table_new_full(g_int_hash, g_int_equal,
- (GDestroyNotify) spd_free,
+ (GDestroyNotify) g_free,
NULL);
assert(fd_settings != NULL);
fd_uid = g_hash_table_new_full(g_int_hash, g_int_equal,
- (GDestroyNotify) spd_free,
- (GDestroyNotify) spd_free);
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
assert(fd_uid != NULL);
language_default_modules = g_hash_table_new(g_str_hash, g_str_equal);
@@ -677,7 +677,7 @@ speechd_load_configuration(int sig)
configfile = dotconf_create(SpeechdOptions.conf_file, spd_options, 0,
CASE_INSENSITIVE);
if (configfile){
- configfile->includepath = strdup(SpeechdOptions.conf_dir);
+ configfile->includepath = g_strdup(SpeechdOptions.conf_dir);
MSG(5, "Config file include path is: %s", configfile->includepath);
if (dotconf_command_loop(configfile) == 0) DIE("Error reading config
file\n");
dotconf_cleanup(configfile);
@@ -934,8 +934,8 @@ main(int argc, char *argv[])
parameters into temporary spawn_ variables for later comparison
with the config file and unset them*/
if (SpeechdOptions.communication_method_set){
- spawn_communication_method =
strdup(SpeechdOptions.communication_method);
- spd_free(SpeechdOptions.communication_method);
+ spawn_communication_method =
g_strdup(SpeechdOptions.communication_method);
+ g_free(SpeechdOptions.communication_method);
SpeechdOptions.communication_method_set = 0;
}
if (SpeechdOptions.port_set){
@@ -943,8 +943,8 @@ main(int argc, char *argv[])
SpeechdOptions.port_set = 0;
}
if (SpeechdOptions.socket_path_set){
- spawn_socket_path = strdup(SpeechdOptions.socket_path);
- spd_free(SpeechdOptions.socket_path);
+ spawn_socket_path = g_strdup(SpeechdOptions.socket_path);
+ g_free(SpeechdOptions.socket_path);
SpeechdOptions.socket_path_set = 0;
}
}
@@ -978,8 +978,8 @@ main(int argc, char *argv[])
SpeechdOptions.conf_dir = g_strdup_printf("%s/conf/",
SpeechdOptions.home_speechd_dir);
if (!g_file_test(SpeechdOptions.conf_dir, G_FILE_TEST_IS_DIR)){
/* If the local confiration dir doesn't exist, read the global
configuration */
- if (strcmp(SYS_CONF, "")) SpeechdOptions.conf_dir =
strdup(SYS_CONF);
- else SpeechdOptions.conf_dir = strdup("/etc/speech-dispatcher/");
+ if (strcmp(SYS_CONF, "")) SpeechdOptions.conf_dir =
g_strdup(SYS_CONF);
+ else SpeechdOptions.conf_dir = g_strdup("/etc/speech-dispatcher/");
}
}
}else{
@@ -1046,8 +1046,8 @@ main(int argc, char *argv[])
}else{
FATAL("Socket name file not set and user has no home directory");
}
- spd_free(SpeechdOptions.socket_path);
- SpeechdOptions.socket_path = strdup(socket_filename->str);
+ g_free(SpeechdOptions.socket_path);
+ SpeechdOptions.socket_path = g_strdup(socket_filename->str);
g_string_free(socket_filename, 1);
}
@@ -1092,8 +1092,8 @@ main(int argc, char *argv[])
} else assert (0);
}
}
- spd_free(spawn_communication_method);
- spd_free(spawn_socket_path);
+ g_free(spawn_communication_method);
+ g_free(spawn_socket_path);
}
if(!strcmp(SpeechdOptions.communication_method, "inet_socket")){
--
1.7.2.3
- [PATCH] Use GLib's allocation functions consistently in src/server/*.c.,
Christopher Brannon <=