public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] locale-archive localedef fixes
@ 2007-04-15 23:29 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2007-04-15 23:29 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

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  <jakub@redhat.com>

	* 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 <drepper@redhat.com>, 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-04-15 23:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-15 23:29 [PATCH] locale-archive localedef fixes Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).