From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16001 invoked by alias); 15 Apr 2007 23:29:32 -0000 Received: (qmail 15985 invoked by uid 22791); 15 Apr 2007 23:29:31 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 16 Apr 2007 00:29:29 +0100 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l3FNZvr9007949; Mon, 16 Apr 2007 01:35:57 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l3FNZvVc007948; Mon, 16 Apr 2007 01:35:57 +0200 Date: Sun, 15 Apr 2007 23:29:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] locale-archive localedef fixes Message-ID: <20070415233557.GN1826@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-04/txt/msg00008.txt.bz2 Hi! I looked a little bit at locale-archive and found a couple of issues: 1) any time we enlarge_archive, all aliases are lost as aliases, they become normal locale-archive entries with their own locrec, rather than sharing a locrec. As locrec is fairly big structure, this impacts the size of the locale-archive. 2) serial field in the header was unitialized, containing whatever happened to be on the stack 3) since 2002 when locarchive.c was written, localedata/SUPPORTED grew substantially, so while perhaps initially we wouldn't need to grow the locale-archive ever for the supported locales, now we need to at least 2 times. 2007-04-15 Jakub Jelinek * locale/programs/locarchive.c (INITIAL_NUM_NAMES, INITIAL_SIZE_STRINGS, INITIAL_NUM_LOCREC): Update to accomodate current number of locales in SUPPORTED. (create_archive): Initialize serial. (enlarge_archive): Preserve aliases rather than duplicating their locrecs. --- libc/locale/programs/locarchive.c.jj 2005-12-07 06:47:27.000000000 +0100 +++ libc/locale/programs/locarchive.c 2007-04-16 01:15:45.000000000 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -64,9 +64,9 @@ static const char *locnames[] = /* Size of the initial archive header. */ -#define INITIAL_NUM_NAMES 450 -#define INITIAL_SIZE_STRINGS 3500 -#define INITIAL_NUM_LOCREC 350 +#define INITIAL_NUM_NAMES 900 +#define INITIAL_SIZE_STRINGS 7500 +#define INITIAL_NUM_LOCREC 420 #define INITIAL_NUM_SUMS 2000 @@ -88,6 +88,7 @@ create_archive (const char *archivefname /* Create the initial content of the archive. */ head.magic = AR_MAGIC; + head.serial = 0; head.namehash_offset = sizeof (struct locarhead); head.namehash_used = 0; head.namehash_size = next_prime (INITIAL_NUM_NAMES); @@ -217,9 +218,12 @@ oldlocrecentcmp (const void *a, const vo } -/* forward decl for below */ +/* forward decls for below */ static uint32_t add_locale (struct locarhandle *ah, const char *name, locale_data_t data, bool replace); +static void add_alias (struct locarhandle *ah, const char *alias, + bool replace, const char *oldname, + uint32_t *locrec_offset_p); static void enlarge_archive (struct locarhandle *ah, const struct locarhead *head) @@ -350,6 +354,7 @@ enlarge_archive (struct locarhandle *ah, qsort (oldlocrecarray, loccnt, sizeof (struct oldlocrecent), oldlocrecentcmp); + uint32_t last_locrec_offset = 0; for (cnt = 0; cnt < loccnt; ++cnt) { /* Insert this entry in the new hash table. */ @@ -368,10 +373,25 @@ enlarge_archive (struct locarhandle *ah, old_data[idx].sum); } - if (add_locale (&new_ah, - ((char *) ah->addr - + oldnamehashtab[oldlocrecarray[cnt].cnt].name_offset), - old_data, 0) == 0) + if (cnt > 0 && oldlocrecarray[cnt - 1].locrec == oldlocrec) + { + const char *oldname + = ((char *) ah->addr + + oldnamehashtab[oldlocrecarray[cnt - 1].cnt].name_offset); + + add_alias (&new_ah, + ((char *) ah->addr + + oldnamehashtab[oldlocrecarray[cnt].cnt].name_offset), + 0, oldname, &last_locrec_offset); + continue; + } + + last_locrec_offset = + add_locale (&new_ah, + ((char *) ah->addr + + oldnamehashtab[oldlocrecarray[cnt].cnt].name_offset), + old_data, 0); + if (last_locrec_offset == 0) error (EXIT_FAILURE, 0, _("cannot extend locale archive file")); } Jakub