Skip to content

Commit

Permalink
Make localedef output generation use more logical interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Sandiford authored and Joseph Myers committed Sep 6, 2013
1 parent 2618d9d commit 1ecbb38
Show file tree
Hide file tree
Showing 16 changed files with 738 additions and 1,611 deletions.
80 changes: 80 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,83 @@
2013-09-06 Richard Sandiford <richard@codesourcery.com>
Joseph Myers <joseph@codesourcery.com>

* locale/programs/locfile.c: Include <assert.h>, <wchar.h> and
"localeinfo.h".
(obstack_chunk_alloc): New macro.
(obstack_chunk_free): Likewise.
(record_offset): New function.
(init_locale_data): Likewise.
(align_locale_data): Likewise.
(add_locale_empty): Likewise.
(add_locale_raw_data): Likewise.
(add_locale_raw_obstack): Likewise.
(add_locale_string): Likewise.
(add_locale_wstring): Likewise.
(add_locale_uint32): Likewise.
(add_locale_uint32_array): Likewise.
(add_locale_char): Likewise.
(start_locale_structure): Likewise.
(end_locale_structure): Likewise.
(start_locale_prelude): Likewise.
(end_locale_prelude): Likewise.
(write_locale_data): Take locale_file structure rather than an
iovec.
* locale/programs/locfile.h: Include "obstack.h".
(struct locale_file): Change to store locale file contents instead
of header.
(init_locale_data): New prototype.
(align_locale_data): Likewise.
(add_locale_empty): Likewise.
(add_locale_raw_data): Likewise.
(add_locale_raw_obstack): Likewise.
(add_locale_string): Likewise.
(add_locale_wstring): Likewise.
(add_locale_uint32): Likewise.
(add_locale_uint32_array): Likewise.
(add_locale_char): Likewise.
(start_locale_structure): Likewise.
(end_locale_structure): Likewise.
(start_locale_prelude): Likewise.
(end_locale_prelude): Likewise.
(write_locale_data): Update prototype.
* locale/programs/3level.h (struct TABLE): Remove result field.
(CONCAT(TABLE,_finalize)): Change to CONCAT(add_locale_,TABLE).
Use new locale_file interface.
[!NO_FINALIZE]: Change condition to [!NO_ADD_LOCALE].
(NO_FINALIZE): Change #undef to #undef of NO_ADD_LOCALE.
* locale/programs/ld-address.c (address_output): Use new
locale_file interface.
* locale/programs/ld-collate.c (NO_FINALIZE): Change to
NO_ADD_LOCALE.
(collate_finish): Don't call collseq_table_finalize.
(collate_output): Use new locale_file interface.
* locale/programs/ld-ctype.c: Move includes of "3level.h" earlier
in file.
(NO_FINALIZE): Change to NO_ADD_LOCALE.
(TABLE): Move defines earlier in file.
(ELEMENT): Likewise.
(DEFAULT): Likewise.
(wctrans_table_add): Move macro and inline function earlier in
file.
(struct wctype_table): Move type earlier in file.
(add_locale_wctype_table): New static prototype.
(struct locale_ctype_t): Use logical types instead of struct iovec
pointers for members.
(ctype_output): Use new locale_file interface.
(wctype_table_finalize): Change to add_locale_wctype_table. Use
new locale_file interface.
(allocate_arrays): Update for use of new locale_file interface.
* locale/programs/ld-identification.c (identification_output): Use
new locale_file interface.
* locale/programs/ld-measurement.c (measurement_output): Likewise.
* locale/programs/ld-messages.c (messages_output): Likewise.
* locale/programs/ld-monetary.c (monetary_output): Likewise.
* locale/programs/ld-name.c (name_output): Likewise.
* locale/programs/ld-numeric.c (numeric_output): Likewise.
* locale/programs/ld-paper.c (paper_output): Likewise.
* locale/programs/ld-telephone.c (telephone_output): Likewise.
* locale/programs/ld-time.c (time_output): Likewise.

2013-09-06 Adhemerval Zanella <azanella@linux.vnet.ibm.com>

* benchtests/Makefile: Add memrchr benchmark.
Expand Down
54 changes: 29 additions & 25 deletions locale/programs/3level.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
ELEMENT to the type of every entry
DEFAULT to the default value for empty entries
ITERATE if you want the TABLE_iterate function to be defined
NO_FINALIZE if you don't want the TABLE_finalize function to be defined
NO_ADD_LOCALE if you don't want the add_locale_TABLE function
to be defined
This will define
Expand All @@ -36,7 +37,7 @@
void TABLE_add (struct TABLE *t, uint32_t wc, ELEMENT value);
void TABLE_iterate (struct TABLE *t,
void (*fn) (uint32_t wc, ELEMENT value));
void TABLE_finalize (struct TABLE *t);
void add_locale_TABLE (struct locale_file *file, struct TABLE *t);
*/

#define CONCAT(a,b) CONCAT1(a,b)
Expand All @@ -57,9 +58,8 @@ struct TABLE
size_t level3_alloc;
size_t level3_size;
ELEMENT *level3;
/* Compressed representation. */
/* Size of compressed representation. */
size_t result_size;
char *result;
};

/* Initialize. Assumes t->p and t->q have already been set. */
Expand Down Expand Up @@ -206,15 +206,15 @@ CONCAT(TABLE,_iterate) (struct TABLE *t,
}
#endif

#ifndef NO_FINALIZE
#ifndef NO_ADD_LOCALE
/* Finalize and shrink. */
static void
CONCAT(TABLE,_finalize) (struct TABLE *t)
CONCAT(add_locale_,TABLE) (struct locale_file *file, struct TABLE *t)
{
size_t i, j, k;
uint32_t reorder3[t->level3_size];
uint32_t reorder2[t->level2_size];
uint32_t level1_offset, level2_offset, level3_offset, last_offset;
uint32_t level2_offset, level3_offset, last_offset;

/* Uniquify level3 blocks. */
k = 0;
Expand Down Expand Up @@ -271,10 +271,7 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
+ (t->level2_size << t->q) * sizeof (uint32_t)
+ (t->level3_size << t->p) * sizeof (ELEMENT);
t->result_size = (last_offset + 3) & ~3ul;
t->result = (char *) xmalloc (t->result_size);

level1_offset =
5 * sizeof (uint32_t);
level2_offset =
5 * sizeof (uint32_t)
+ t->level1_size * sizeof (uint32_t);
Expand All @@ -283,29 +280,36 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
+ t->level1_size * sizeof (uint32_t)
+ (t->level2_size << t->q) * sizeof (uint32_t);

((uint32_t *) t->result)[0] = t->q + t->p;
((uint32_t *) t->result)[1] = t->level1_size;
((uint32_t *) t->result)[2] = t->p;
((uint32_t *) t->result)[3] = (1 << t->q) - 1;
((uint32_t *) t->result)[4] = (1 << t->p) - 1;
start_locale_structure (file);
add_locale_uint32 (file, t->q + t->p);
add_locale_uint32 (file, t->level1_size);
add_locale_uint32 (file, t->p);
add_locale_uint32 (file, (1 << t->q) - 1);
add_locale_uint32 (file, (1 << t->p) - 1);

for (i = 0; i < t->level1_size; i++)
((uint32_t *) (t->result + level1_offset))[i] =
(t->level1[i] == EMPTY
add_locale_uint32
(file,
t->level1[i] == EMPTY
? 0
: (t->level1[i] << t->q) * sizeof (uint32_t) + level2_offset);

for (i = 0; i < (t->level2_size << t->q); i++)
((uint32_t *) (t->result + level2_offset))[i] =
(t->level2[i] == EMPTY
add_locale_uint32
(file,
t->level2[i] == EMPTY
? 0
: (t->level2[i] << t->p) * sizeof (ELEMENT) + level3_offset);

for (i = 0; i < (t->level3_size << t->p); i++)
((ELEMENT *) (t->result + level3_offset))[i] = t->level3[i];

if (last_offset < t->result_size)
memset (t->result + last_offset, 0, t->result_size - last_offset);
if (sizeof (ELEMENT) == 1)
add_locale_raw_data (file, t->level3, t->level3_size << t->p);
else if (sizeof (ELEMENT) == sizeof (uint32_t))
add_locale_uint32_array (file, (uint32_t *) t->level3,
t->level3_size << t->p);
else
abort ();
align_locale_data (file, 4);
end_locale_structure (file);

if (t->level1_alloc > 0)
free (t->level1);
Expand All @@ -321,4 +325,4 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
#undef ELEMENT
#undef DEFAULT
#undef ITERATE
#undef NO_FINALIZE
#undef NO_ADD_LOCALE
108 changes: 17 additions & 91 deletions locale/programs/ld-address.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,97 +349,23 @@ address_output (struct localedef_t *locale, const struct charmap_t *charmap,
const char *output_path)
{
struct locale_address_t *address = locale->categories[LC_ADDRESS].address;
struct iovec iov[3 + _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS)];
struct locale_file data;
uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS)];
size_t cnt = 0;

data.magic = LIMAGIC (LC_ADDRESS);
data.n = _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS);
iov[cnt].iov_base = (void *) &data;
iov[cnt].iov_len = sizeof (data);
++cnt;

iov[cnt].iov_base = (void *) idx;
iov[cnt].iov_len = sizeof (idx);
++cnt;

idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len;
iov[cnt].iov_base = (void *) address->postal_fmt;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->country_name;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->country_post;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->country_ab2;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->country_ab3;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->country_car;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;

/* Align following data */
iov[cnt].iov_base = (void *) "\0\0";
iov[cnt].iov_len = ((idx[cnt - 2] + 3) & ~3) - idx[cnt - 2];
idx[cnt - 2] = (idx[cnt - 2] + 3) & ~3;
++cnt;

iov[cnt].iov_base = (void *) &address->country_num;
iov[cnt].iov_len = sizeof (uint32_t);
++cnt;

idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->country_isbn;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->lang_name;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->lang_ab;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->lang_term;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) address->lang_lib;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

idx[cnt - 3] = idx[cnt - 4] + iov[cnt - 1].iov_len;
iov[cnt].iov_base = (void *) charmap->code_set_name;
iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
++cnt;

assert (cnt == 3 + _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS));

write_locale_data (output_path, LC_ADDRESS, "LC_ADDRESS",
3 + _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS), iov);
struct locale_file file;

init_locale_data (&file, _NL_ITEM_INDEX (_NL_NUM_LC_ADDRESS));
add_locale_string (&file, address->postal_fmt);
add_locale_string (&file, address->country_name);
add_locale_string (&file, address->country_post);
add_locale_string (&file, address->country_ab2);
add_locale_string (&file, address->country_ab3);
add_locale_string (&file, address->country_car);
add_locale_uint32 (&file, address->country_num);
add_locale_string (&file, address->country_isbn);
add_locale_string (&file, address->lang_name);
add_locale_string (&file, address->lang_ab);
add_locale_string (&file, address->lang_term);
add_locale_string (&file, address->lang_lib);
add_locale_string (&file, charmap->code_set_name);
write_locale_data (output_path, LC_ADDRESS, "LC_ADDRESS", &file);
}


Expand Down
Loading

0 comments on commit 1ecbb38

Please sign in to comment.