diff options
author | Ulrich Drepper <drepper@redhat.com> | 1999-04-28 21:56:46 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1999-04-28 21:56:46 +0000 |
commit | 390500b147a8063ea4be7313ec38cada26f9235a (patch) | |
tree | edf14c04a0a46992ce4c04eeaf604fab99a9d960 /iconv | |
parent | fbb9cc9129ae3efdb1652b175f57956033102876 (diff) | |
download | glibc-390500b147a8063ea4be7313ec38cada26f9235a.tar.gz glibc-390500b147a8063ea4be7313ec38cada26f9235a.tar.xz glibc-390500b147a8063ea4be7313ec38cada26f9235a.zip |
Update.
1999-04-28 Ulrich Drepper <drepper@cygnus.com> * manager.c (pthread_allocate_stack): Optimize initialization of new thread descriptor.
Diffstat (limited to 'iconv')
-rw-r--r-- | iconv/gconv.h | 2 | ||||
-rw-r--r-- | iconv/gconv_close.c | 3 | ||||
-rw-r--r-- | iconv/gconv_conf.c | 11 | ||||
-rw-r--r-- | iconv/gconv_db.c | 9 | ||||
-rw-r--r-- | iconv/gconv_open.c | 72 |
5 files changed, 45 insertions, 52 deletions
diff --git a/iconv/gconv.h b/iconv/gconv.h index 6576b0621f..4b71ccf4b8 100644 --- a/iconv/gconv.h +++ b/iconv/gconv.h @@ -123,7 +123,7 @@ typedef struct gconv_info { size_t nsteps; struct gconv_step *steps; - struct gconv_step_data *data; + struct gconv_step_data data[0]; } *gconv_t; #endif /* gconv.h */ diff --git a/iconv/gconv_close.c b/iconv/gconv_close.c index de0937d610..2fe842467b 100644 --- a/iconv/gconv_close.c +++ b/iconv/gconv_close.c @@ -1,5 +1,5 @@ /* Release any resource associated with given conversion descriptor. - Copyright (C) 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -44,7 +44,6 @@ __gconv_close (gconv_t cd) while (!(drunp++)->is_last); /* Free the data allocated for the descriptor. */ - free (cd->data); free (cd); /* Close the participating modules. */ diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index a0aae43138..dce913da74 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -67,8 +67,7 @@ static struct gconv_module builtin_modules[] = #undef BUILTIN_TRANSFORMATION #undef BUILTIN_ALIAS -static const char * -builtin_aliases[] = +static const char *builtin_aliases[] = { #define BUILTIN_TRANSFORMATION(From, ConstPfx, ConstLen, To, Cost, Name, \ Fct, Init, End, MinF, MaxF, MinT, MaxT) @@ -201,14 +200,16 @@ add_alias (char *rp, void *modules) malloc (sizeof (struct gconv_alias) + (wp - from)); if (new_alias != NULL) { + void **inserted; + new_alias->fromname = memcpy ((char *) new_alias + sizeof (struct gconv_alias), from, wp - from); new_alias->toname = new_alias->fromname + (to - from); - if (__tfind (new_alias, &__gconv_alias_db, __gconv_alias_compare) != NULL - || (__tsearch (new_alias, &__gconv_alias_db, __gconv_alias_compare) - == NULL)) + inserted = (void **) __tsearch (new_alias, &__gconv_alias_db, + __gconv_alias_compare); + if (inserted == NULL || *inserted != (void **) new_alias) /* Something went wrong, free this entry. */ free (new_alias); } diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c index fdc3064d5c..4abc1ae48b 100644 --- a/iconv/gconv_db.c +++ b/iconv/gconv_db.c @@ -139,14 +139,17 @@ add_derivation (const char *fromset, const char *toset, malloc (sizeof (struct known_derivation) + fromset_len + toset_len); if (new_deriv != NULL) { - new_deriv->from = memcpy (new_deriv + 1, fromset, fromset_len); - new_deriv->to = memcpy ((char *) new_deriv->from + fromset_len, + new_deriv->from = (char *) (new_deriv + 1); + new_deriv->to = memcpy (__mempcpy (new_deriv + 1, fromset, fromset_len), toset, toset_len); new_deriv->steps = handle; new_deriv->nsteps = nsteps; - __tsearch (new_deriv, &known_derivations, derivation_compare); + if (__tsearch (new_deriv, &known_derivations, derivation_compare) + == NULL) + /* There is some kind of memory allocation problem. */ + free (new_deriv); } /* Please note that we don't complain if the allocation failed. This is not tragically but in case we use the memory debugging facilities diff --git a/iconv/gconv_open.c b/iconv/gconv_open.c index fb5f88b9a3..f3b6dfa86e 100644 --- a/iconv/gconv_open.c +++ b/iconv/gconv_open.c @@ -1,5 +1,5 @@ /* Find matching transformation algorithms and initialize steps. - Copyright (C) 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -38,7 +38,8 @@ __gconv_open (const char *toset, const char *fromset, gconv_t *handle) if (res == GCONV_OK) { /* Allocate room for handle. */ - result = (gconv_t) malloc (sizeof (struct gconv_info)); + result = (gconv_t) malloc (sizeof (struct gconv_info) + + nsteps * sizeof (struct gconv_step_data)); if (result == NULL) res = GCONV_NOMEM; else @@ -47,47 +48,41 @@ __gconv_open (const char *toset, const char *fromset, gconv_t *handle) result->steps = steps; result->nsteps = nsteps; - /* Allocate array for the step data. */ - result->data = (struct gconv_step_data *) - calloc (nsteps, sizeof (struct gconv_step_data)); + /* Clear the array for the step data. */ + memset (result->data, '\0', + nsteps * sizeof (struct gconv_step_data)); - if (result->data == NULL) - res = GCONV_NOMEM; - else + /* Call all initialization functions for the transformation + step implemenations. */ + for (cnt = 0; cnt < nsteps; ++cnt) { - /* Call all initialization functions for the transformation - step implemenations. */ - struct gconv_step_data *data = result->data; + /* If this is the last step we must not allocate an + output buffer. */ + result->data[cnt].is_last = cnt == nsteps - 1; - for (cnt = 0; cnt < nsteps; ++cnt) - { - /* If this is the last step we must not allocate an output - buffer. */ - data[cnt].is_last = cnt == nsteps - 1; + /* Reset the counter. */ + result->data[cnt].invocation_counter = 0; - /* Reset the counter. */ - data[cnt].invocation_counter = 0; + /* It's a regular use. */ + result->data[cnt].internal_use = 0; - /* It's a regular use. */ - data[cnt].internal_use = 0; + /* We use the `mbstate_t' member in DATA. */ + result->data[cnt].statep = &result->data[cnt].__state; - /* We use the `mbstate_t' member in DATA. */ - data[cnt].statep = &data[cnt].__state; + /* Allocate the buffer. */ + if (!result->data[cnt].is_last) + { + size_t size = (GCONV_NCHAR_GOAL + * steps[cnt].max_needed_to); - /* Allocate the buffer. */ - if (!data[cnt].is_last) + result->data[cnt].outbuf = (char *) malloc (size); + if (result->data[cnt].outbuf == NULL) { - size_t size = (GCONV_NCHAR_GOAL - * steps[cnt].max_needed_to); - - data[cnt].outbuf = (char *) malloc (size); - if (data[cnt].outbuf == NULL) - { - res = GCONV_NOMEM; - break; - } - data[cnt].outbufend = data[cnt].outbuf + size; + res = GCONV_NOMEM; + break; } + result->data[cnt].outbufend = (result->data[cnt].outbuf + + size); } } } @@ -100,13 +95,8 @@ __gconv_open (const char *toset, const char *fromset, gconv_t *handle) if (result != NULL) { - if (result->data != NULL) - { - while (cnt-- > 0) - free (result->data[cnt].outbuf); - - free (result->data); - } + while (cnt-- > 0) + free (result->data[cnt].outbuf); free (result); result = NULL; |