[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
libspeechd SPDVoice cleanup api
From: |
Trevor Saunders |
Subject: |
libspeechd SPDVoice cleanup api |
Date: |
Sat, 25 Oct 2014 16:19:49 -0400 |
On Sat, Oct 25, 2014 at 10:11:31AM +0200, Bohdan R. Rau wrote:
> W dniu 2014-10-24 11:29, Bohdan R. Rau napisa?(a):
> >On library level: we need only one malloc (no reallocs) in
> >spd_execute_command_with_list_reply function
>
> Code below is not tested - it only shows possibility of single malloc
> instead of several strndups and reallocs ;)
yes, and its about as ugly as I expected, without taking care of
spd_list_synthesis_voices() which I expect will be worse. It also
doesn't address the issue that your baking the size of SPDVoice into the
ABI.
Trev
>
>
> char **spd_execute_command_with_list_reply(SPDConnection * connection,
> char *command)
> {
> char *reply = NULL;
> char *line;
> int err;
> char **result;
> int i, count, linelen;
> char *string_block;
> size_t result_size=sizeof(char *);
>
> spd_execute_command_with_reply(connection, command, &reply);
> if (!ret_ok(reply)) {
> if (reply != NULL)
> free(reply);
> return NULL;
> }
>
> for (count=0 ;; count++) {
> line = get_param_str(reply, i + 1, &linelen, &err);
> if ((err) || (line == NULL))
> break;
> result_size += linelen + 1 + sizeof(char *);
> }
> result=malloc(result_size);
> string_block=(char *)(result + count + 1);
> for (i=0 ; i < count; i++) {
> result[i]=string_block;
> line = get_param_str_len(reply, i + 1, &linelen, &err);
> memcpy(string_block,line,linelen);
> string_block += linelen;
> *string_block++ = 0;
> }
> result[i]=NULL;
> free(reply);
> return result;
> }
>
>
> static char *get_param_str_len(char *reply, int num, int *len, int *err)
> {
> int i;
> char *tptr;
> char *pos;
> char *pos_begin;
> char *pos_end;
>
> assert(err != NULL);
>
> if (num < 1) {
> *err = -1;
> return NULL;
> }
>
> pos = reply;
> for (i = 0; i <= num - 2; i++) {
> pos = strstr(pos, "\r\n");
> if (pos == NULL) {
> *err = -2;
> return NULL;
> }
> pos += 2;
> }
>
> if (strlen(pos) < 4)
> return NULL;
>
> *err = strtol(pos, &tptr, 10);
> if (*err >= 300 && *err <= 399)
> return NULL;
>
> if ((*tptr != '-') || (tptr != pos + 3)) {
> *err = -3;
> return NULL;
> }
>
> pos_begin = pos + 4;
> pos_end = strstr(pos_begin, "\r\n");
> if (pos_end == NULL) {
> *err = -4;
> return NULL;
> }
>
> *len = (pos_end - pos_begin);
> *err = 0;
>
> return pos_begin;
> }
>
> static char *get_param_str(char *reply, int num, int *err)
> {
> char *rc;
> int len;
> rc=get_param_str_len(reply,num,&len,err);
> if (rc) {
> rc = strndup(rc,len);
> }
> return rc;
> }
>
> ethanak
> --
> http://milena.polip.com/ - Pa pa, Ivonko!
>
> _______________________________________________
> Speechd mailing list
> Speechd at lists.freebsoft.org
> http://lists.freebsoft.org/mailman/listinfo/speechd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL:
<http://lists.freebsoft.org/pipermail/speechd/attachments/20141025/4005a431/attachment.pgp>
libspeechd SPDVoice cleanup api, Jeremy Whiting, 2014/10/24
libspeechd SPDVoice cleanup api, Luke Yelavich, 2014/10/24