This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Moving xmalloc and xstrdup around



Hi,

locale/programs/ contains xmalloc and xstrdup.  xmalloc is used also
in catgets/gencat (see also catgets/Makefile). xmalloc and xstrdup
will be used in my ldconfig program.

Currently xmalloc is compiled twice - once for locale and once for
catgets :-(.

What do you think of putting xmalloc and xstrdup into an extra
directory to clean this up a bit?

I'm proposing the appended patch to put xmalloc and xstrdup into a
directory program-lib.

Andreas

1999-11-29  Andreas Jaeger  <aj@suse.de>

	* locale/Makefile ($(objpfx)localedef $(objpfx)locale): Add
	dependencies for xmalloc and xstrdup.
	(lib-modules): Remove xmalloc and xstrdup.

	* catgets/Makefile ($(objpfx)gencat): Add dependency on xmalloc.
	(vpath): Removed, not needed with changed xmalloc location.
	(gencat-modules): Likewise.
	(extra-objs): Likewise.

	* locale/Depend: New file, depend on program-lib.
	* catgets/Depend: Likewise.

	* program-lib/Makefile: New file.

	* Makeconfig (all-subdirs): Added program-lib.
	(xmalloc-obj-name): New.
	(xstrdup-obj-name): New.

	* locale/programs/xmalloc.c: Move to ...
	* program-lib/xmalloc.c: ... here.
	* locale/programs/xstrdup.c: Move to ...
	* program-lib/xstrdup.c: ... here.

============================================================
Index: locale/Makefile
--- locale/Makefile	1999/10/29 17:23:38	1.40
+++ locale/Makefile	1999/11/29 12:40:45
@@ -60,7 +60,7 @@
 localedef-modules	:= $(categories:%=ld-%) charmap linereader locfile \
 			   repertoire
 locale-modules		:= locale-spec
-lib-modules		:= simple-hash xmalloc xstrdup
+lib-modules		:= simple-hash
 
 
 GPERF = gperf
@@ -74,7 +74,8 @@
 
 $(objpfx)localedef: $(localedef-modules:%=$(objpfx)%.o)
 $(objpfx)locale: $(locale-modules:%=$(objpfx)%.o)
-$(objpfx)localedef $(objpfx)locale: $(lib-modules:%=$(objpfx)%.o)
+$(objpfx)localedef $(objpfx)locale: $(lib-modules:%=$(objpfx)%.o) \
+	$(xmalloc-obj-name) $(xstrdup-obj-name)
 
 localepath = "$(localedir):$(i18ndir)"
 
============================================================
Index: catgets/Makefile
--- catgets/Makefile	1999/09/13 08:38:33	1.9
+++ catgets/Makefile	1999/11/29 12:40:45
@@ -26,17 +26,10 @@
 routines	= catgets open_catalog
 others		= gencat
 install-bin	= gencat
-extra-objs	= $(gencat-modules:=.o)
 
-gencat-modules	= xmalloc
-
-# To find xmalloc.c
-vpath %.c ../locale/programs
-
-
 include ../Rules
 
-$(objpfx)gencat: $(gencat-modules:%=$(objpfx)%.o)
+$(objpfx)gencat: $(xmalloc-obj-name)
 
 CPPFLAGS := -DNLSPATH='"$(msgcatdir)/%L/%N:$(msgcatdir)/%L/LC_MESSAGES/%N:$(msgcatdir)/%l/%N:$(msgcatdir)/%l/LC_MESSAGES/%N:"' \
 	    -DHAVE_CONFIG_H $(CPPFLAGS)
============================================================
Index: Makeconfig
--- Makeconfig	1999/11/25 18:30:16	1.220
+++ Makeconfig	1999/11/29 12:40:46
@@ -775,6 +775,10 @@
 libdl =
 endif
 
+
+xmalloc-obj-name = $(common-objpfx)program-lib/xmalloc.o
+xstrdup-obj-name = $(common-objpfx)program-lib/xstrdup.o
+
 # These are the subdirectories containing the library source.  The order
 # is more or less arbitrary.  The sorting step will take care of the
 # dependencies.  Only the $(binfmt-subdir) should always be kept at the
@@ -783,7 +787,8 @@
 	      stdlib stdio-common $(stdio) malloc string wcsmbs time dirent \
 	      grp pwd posix io termios resource misc socket sysvipc gmon    \
 	      gnulib iconv iconvdata wctype manual shadow md5-crypt po argp \
-	      $(add-ons) nss localedata timezone rt debug $(sysdep-subdirs) \
+	      $(add-ons) nss localedata timezone rt debug program-lib       \
+	      $(sysdep-subdirs)                                             \
 	      $(dlfcn) $(binfmt-subdir)
 all-subdirs := $(filter-out $(sysdep-inhibit-subdirs),$(all-subdirs))
 
============================================================
Index: locale/Depend
--- locale/Depend	created
+++ locale/Depend	Mon Nov 29 10:26:20 1999	1.1
@@ -0,0 +1 @@
+program-lib
============================================================
Index: catgets/Depend
--- catgets/Depend	created
+++ catgets/Depend	Mon Nov 29 10:26:14 1999	1.1
@@ -0,0 +1 @@
+program-lib
============================================================
Index: program-lib/Makefile
--- program-lib/Makefile	created
+++ program-lib/Makefile	Mon Nov 29 10:27:51 1999	1.1
@@ -0,0 +1,30 @@
+# Copyright (C) 1999 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Library General Public License for more details.
+
+# You should have received a copy of the GNU Library General Public
+# License along with the GNU C Library; see the file COPYING.LIB.  If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+#
+#	Sub-makefile for program-lib portion of the library.
+#
+
+subdir	:= program-lib
+
+extra-objs := xmalloc.o xstrdup.o
+
+distribute := xmalloc.c xstrdup.c
+
+include ../Rules
+
============================================================
Index: program-lib/xmalloc.c
--- program-lib/xmalloc.c	created
+++ program-lib/xmalloc.c	Sat Jan 17 10:57:44 1998	1.1
@@ -0,0 +1,117 @@
+/* xmalloc.c -- malloc with out of memory checking
+   Copyright (C) 1990,91,92,93,94,95,96,97 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if __STDC__
+#define VOID void
+#else
+#define VOID char
+#endif
+
+#include <sys/types.h>
+
+#if STDC_HEADERS || _LIBC
+#include <stdlib.h>
+static VOID *fixup_null_alloc __P ((size_t n));
+VOID *xmalloc __P ((size_t n));
+VOID *xcalloc __P ((size_t n, size_t s));
+VOID *xrealloc __P ((VOID *p, size_t n));
+#else
+VOID *calloc ();
+VOID *malloc ();
+VOID *realloc ();
+void free ();
+#endif
+
+#include <libintl.h>
+#include "error.h"
+
+#ifndef _
+# define _(str) gettext (str)
+#endif
+
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 4
+#endif
+
+/* Exit value when the requested amount of memory is not available.
+   The caller may set it to some other value.  */
+int xmalloc_exit_failure = EXIT_FAILURE;
+
+static VOID *
+fixup_null_alloc (n)
+     size_t n;
+{
+  VOID *p;
+
+  p = 0;
+  if (n == 0)
+    p = malloc ((size_t) 1);
+  if (p == 0)
+    error (xmalloc_exit_failure, 0, _("memory exhausted"));
+  return p;
+}
+
+/* Allocate N bytes of memory dynamically, with error checking.  */
+
+VOID *
+xmalloc (n)
+     size_t n;
+{
+  VOID *p;
+
+  p = malloc (n);
+  if (p == 0)
+    p = fixup_null_alloc (n);
+  return p;
+}
+
+/* Allocate memory for N elements of S bytes, with error checking.  */
+
+VOID *
+xcalloc (n, s)
+     size_t n, s;
+{
+  VOID *p;
+
+  p = calloc (n, s);
+  if (p == 0)
+    p = fixup_null_alloc (n);
+  return p;
+}
+
+/* Change the size of an allocated block of memory P to N bytes,
+   with error checking.
+   If P is NULL, run xmalloc.  */
+
+VOID *
+xrealloc (p, n)
+     VOID *p;
+     size_t n;
+{
+  if (p == 0)
+    return xmalloc (n);
+  p = realloc (p, n);
+  if (p == 0)
+    p = fixup_null_alloc (n);
+  return p;
+}
============================================================
Index: program-lib/xstrdup.c
--- program-lib/xstrdup.c	created
+++ program-lib/xstrdup.c	Fri Oct 15 19:25:22 1999	1.1
@@ -0,0 +1,39 @@
+/* xstrdup.c -- copy a string with out of memory checking
+   Copyright (C) 1990, 1996, 1997, 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if defined STDC_HEADERS || defined HAVE_STRING_H || __LIBC
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+void *xmalloc __P ((size_t n));
+char *xstrdup __P ((char *string));
+
+/* Return a newly allocated copy of STRING.  */
+
+char *
+xstrdup (string)
+     char *string;
+{
+  return strcpy (xmalloc (strlen (string) + 1), string);
+}
============================================================
Index: locale/programs/xmalloc.c
--- locale/programs/xmalloc.c	Mon Nov 29 13:40:13 1999	1.5
+++ locale/programs/xmalloc.c	removed
@@ -1,117 +0,0 @@
-/* xmalloc.c -- malloc with out of memory checking
-   Copyright (C) 1990,91,92,93,94,95,96,97 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#if __STDC__
-#define VOID void
-#else
-#define VOID char
-#endif
-
-#include <sys/types.h>
-
-#if STDC_HEADERS || _LIBC
-#include <stdlib.h>
-static VOID *fixup_null_alloc __P ((size_t n));
-VOID *xmalloc __P ((size_t n));
-VOID *xcalloc __P ((size_t n, size_t s));
-VOID *xrealloc __P ((VOID *p, size_t n));
-#else
-VOID *calloc ();
-VOID *malloc ();
-VOID *realloc ();
-void free ();
-#endif
-
-#include <libintl.h>
-#include "error.h"
-
-#ifndef _
-# define _(str) gettext (str)
-#endif
-
-#ifndef EXIT_FAILURE
-#define EXIT_FAILURE 4
-#endif
-
-/* Exit value when the requested amount of memory is not available.
-   The caller may set it to some other value.  */
-int xmalloc_exit_failure = EXIT_FAILURE;
-
-static VOID *
-fixup_null_alloc (n)
-     size_t n;
-{
-  VOID *p;
-
-  p = 0;
-  if (n == 0)
-    p = malloc ((size_t) 1);
-  if (p == 0)
-    error (xmalloc_exit_failure, 0, _("memory exhausted"));
-  return p;
-}
-
-/* Allocate N bytes of memory dynamically, with error checking.  */
-
-VOID *
-xmalloc (n)
-     size_t n;
-{
-  VOID *p;
-
-  p = malloc (n);
-  if (p == 0)
-    p = fixup_null_alloc (n);
-  return p;
-}
-
-/* Allocate memory for N elements of S bytes, with error checking.  */
-
-VOID *
-xcalloc (n, s)
-     size_t n, s;
-{
-  VOID *p;
-
-  p = calloc (n, s);
-  if (p == 0)
-    p = fixup_null_alloc (n);
-  return p;
-}
-
-/* Change the size of an allocated block of memory P to N bytes,
-   with error checking.
-   If P is NULL, run xmalloc.  */
-
-VOID *
-xrealloc (p, n)
-     VOID *p;
-     size_t n;
-{
-  if (p == 0)
-    return xmalloc (n);
-  p = realloc (p, n);
-  if (p == 0)
-    p = fixup_null_alloc (n);
-  return p;
-}
============================================================
Index: locale/programs/xstrdup.c
--- locale/programs/xstrdup.c	Mon Nov 29 13:40:13 1999	1.4
+++ locale/programs/xstrdup.c	removed
@@ -1,39 +0,0 @@
-/* xstrdup.c -- copy a string with out of memory checking
-   Copyright (C) 1990, 1996, 1997, 1999 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#if defined STDC_HEADERS || defined HAVE_STRING_H || __LIBC
-# include <string.h>
-#else
-# include <strings.h>
-#endif
-void *xmalloc __P ((size_t n));
-char *xstrdup __P ((char *string));
-
-/* Return a newly allocated copy of STRING.  */
-
-char *
-xstrdup (string)
-     char *string;
-{
-  return strcpy (xmalloc (strlen (string) + 1), string);
-}

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]