This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


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

Re: buystring and xstrdup in ld


On Wed, May 02, 2001 at 12:52:10PM +0930, amodra@one.net.au wrote:
> On Tue, May 01, 2001 at 10:17:42AM -0700, H . J . Lu wrote:
> > The ld directory defines and uses buystring which does the same thing
> > as xstrdup in libiberty. Should I send a patch to replace buystring
> > with xstrdup?
> 
> Yes, looks like a no-brainer.

I checked this patch into CVS. Let me know if there are any problems.

Thanks.

H.J.
----
2001-05-02  H.J. Lu  <hjl@gnu.org>

	* ldfile.c: Include "libiberty.h".
	* ldlex.l: Likewise.

	* ldmisc.c (buystring): Removed.
	* ldmisc.h: Likewise.

	* ldfile.c: Replace buystring with xstrdup.
	* ldlang.c: Likewise.
	* ldlex.l: Likewise.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* lexsup.c: Likewise.
	* mpw-eppcmac.c: Likewise.

Index: ldfile.c
===================================================================
RCS file: /cvs/src/src/ld/ldfile.c,v
retrieving revision 1.10
diff -u -p -r1.10 ldfile.c
--- ldfile.c	2001/03/13 06:14:27	1.10
+++ ldfile.c	2001/05/02 16:37:37
@@ -33,6 +33,7 @@ Software Foundation, 59 Temple Place - S
 #include "ldgram.h"
 #include "ldlex.h"
 #include "ldemul.h"
+#include "libiberty.h"
 
 #include <ctype.h>
 
@@ -414,7 +415,7 @@ void
 ldfile_add_arch (in_name)
      CONST char *in_name;
 {
-  char *name = buystring (in_name);
+  char *name = xstrdup (in_name);
   search_arch_type *new =
     (search_arch_type *) xmalloc (sizeof (search_arch_type));
 
Index: ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.44
diff -u -p -r1.44 ldlang.c
--- ldlang.c	2001/04/28 18:00:10	1.44
+++ ldlang.c	2001/05/02 16:37:48
@@ -623,7 +623,7 @@ lang_memory_region_lookup (name)
     lang_memory_region_type *new =
     (lang_memory_region_type *) stat_alloc (sizeof (lang_memory_region_type));
 
-    new->name = buystring (name);
+    new->name = xstrdup (name);
     new->next = (lang_memory_region_type *) NULL;
 
     *lang_memory_region_list_tail = new;
@@ -1994,7 +1994,7 @@ ldlang_add_undef (name)
   new->next = ldlang_undef_chain_list_head;
   ldlang_undef_chain_list_head = new;
 
-  new->name = buystring (name);
+  new->name = xstrdup (name);
 }
 
 /* Run through the list of undefineds created above and place them
Index: ldlex.l
===================================================================
RCS file: /cvs/src/src/ld/ldlex.l,v
retrieving revision 1.4
diff -u -p -r1.4 ldlex.l
--- ldlex.l	2001/03/13 06:14:27	1.4
+++ ldlex.l	2001/05/02 16:37:49
@@ -45,6 +45,7 @@ This was written by steve chamberlain
 #include "ldfile.h"
 #include "ldlex.h"
 #include "ldmain.h"
+#include "libiberty.h"
 
 /* The type of top-level parser input.
    yylex and yyparse (indirectly) both check this.  */
@@ -147,7 +148,7 @@ V_IDENTIFIER [*?.$_a-zA-Z]([*?.$_a-zA-Z0
 
 <DEFSYMEXP>"-"                  { RTOKEN('-');}
 <DEFSYMEXP>"+"                  { RTOKEN('+');}
-<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = buystring(yytext); return NAME; }
+<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = xstrdup(yytext); return NAME; }
 <DEFSYMEXP>"="                  { RTOKEN('='); }
 
 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
@@ -333,17 +334,17 @@ V_IDENTIFIER [*?.$_a-zA-Z]([*?.$_a-zA-Z0
 
 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}*	{
 /* Filename without commas, needed to parse mri stuff */
-				 yylval.name = buystring(yytext); 
+				 yylval.name = xstrdup(yytext); 
 				  return NAME;
 				}
 
 
 <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}*	{
-				 yylval.name = buystring(yytext); 
+				 yylval.name = xstrdup(yytext); 
 				  return NAME;
 				}
 <BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {
-				  yylval.name = buystring (yytext + 2);
+				  yylval.name = xstrdup (yytext + 2);
 				  return LNAME;
 				}
 <SCRIPT>{WILDCHAR}* {
@@ -358,7 +359,7 @@ V_IDENTIFIER [*?.$_a-zA-Z]([*?.$_a-zA-Z0
 		  }
 		else
 		  {
-		    yylval.name = buystring(yytext);
+		    yylval.name = xstrdup(yytext);
 		    return NAME;
 		  }
 	}
@@ -366,7 +367,7 @@ V_IDENTIFIER [*?.$_a-zA-Z]([*?.$_a-zA-Z0
 <EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {
 					/* No matter the state, quotes
 					   give what's inside */
-					yylval.name = buystring(yytext+1);
+					yylval.name = xstrdup(yytext+1);
 					yylval.name[yyleng-2] = 0;
 					return NAME;
 				}
@@ -381,10 +382,10 @@ V_IDENTIFIER [*?.$_a-zA-Z]([*?.$_a-zA-Z0
 
 <VERS_NODE>extern		{ RTOKEN(EXTERN); }
 
-<VERS_NODE>{V_IDENTIFIER}	{ yylval.name = buystring (yytext);
+<VERS_NODE>{V_IDENTIFIER}	{ yylval.name = xstrdup (yytext);
 				  return VERS_IDENTIFIER; }
 
-<VERS_SCRIPT>{V_TAG}		{ yylval.name = buystring (yytext);
+<VERS_SCRIPT>{V_TAG}		{ yylval.name = xstrdup (yytext);
 				  return VERS_TAG; }
 
 <VERS_START>"{"			{ BEGIN(VERS_SCRIPT); return *yytext; }
Index: ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.20
diff -u -p -r1.20 ldmain.c
--- ldmain.c	2001/04/13 00:34:36	1.20
+++ ldmain.c	2001/05/02 16:37:51
@@ -1205,7 +1205,7 @@ undefined_symbol (info, name, abfd, sect
       error_count = 0;
       if (error_name != (char *) NULL)
 	free (error_name);
-      error_name = buystring (name);
+      error_name = xstrdup (name);
     }
 
   if (section != NULL)
Index: ldmisc.c
===================================================================
RCS file: /cvs/src/src/ld/ldmisc.c,v
retrieving revision 1.6
diff -u -p -r1.6 ldmisc.c
--- ldmisc.c	2001/04/13 02:22:23	1.6
+++ ldmisc.c	2001/05/02 16:37:52
@@ -335,10 +335,10 @@ vfinfo (fp, fmt, arg)
 			    last_bfd = abfd;
 			    if (last_file != NULL)
 			      free (last_file);
-			    last_file = buystring (filename);
+			    last_file = xstrdup (filename);
 			    if (last_function != NULL)
 			      free (last_function);
-			    last_function = buystring (functionname);
+			    last_function = xstrdup (functionname);
 			  }
 			discard_last = false;
 			if (linenumber != 0)
@@ -465,16 +465,6 @@ info_assert (file, line)
      unsigned int line;
 {
   einfo (_("%F%P: internal error %s %d\n"), file, line);
-}
-
-char *
-buystring (x)
-     CONST char *CONST x;
-{
-  size_t l = strlen (x) + 1;
-  char *r = xmalloc (l);
-  memcpy (r, x, l);
-  return r;
 }
 
 /* ('m' for map) Format info message and print on map.  */
Index: ldmisc.h
===================================================================
RCS file: /cvs/src/src/ld/ldmisc.h,v
retrieving revision 1.2
diff -u -p -r1.2 ldmisc.h
--- ldmisc.h	2001/03/13 06:14:27	1.2
+++ ldmisc.h	2001/05/02 16:37:52
@@ -42,7 +42,6 @@ extern void yyerror PARAMS ((const char 
 extern PTR xmalloc PARAMS ((size_t));
 extern PTR xrealloc PARAMS ((PTR, size_t));
 extern void xexit PARAMS ((int));
-extern char *buystring PARAMS ((CONST char *CONST));
 
 #define ASSERT(x) \
 do { if (!(x)) info_assert(__FILE__,__LINE__); } while (0)
Index: lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.32
diff -u -p -r1.32 lexsup.c
--- lexsup.c	2001/04/13 02:22:23	1.32
+++ lexsup.c	2001/05/02 16:37:55
@@ -816,7 +816,7 @@ parse_args (argc, argv)
 	  /* Fall through.  */
 	case OPTION_RPATH:
 	  if (command_line.rpath == NULL)
-	    command_line.rpath = buystring (optarg);
+	    command_line.rpath = xstrdup (optarg);
 	  else
 	    {
 	      size_t rpath_len = strlen (command_line.rpath);
@@ -853,7 +853,7 @@ parse_args (argc, argv)
 	  break;
 	case OPTION_RPATH_LINK:
 	  if (command_line.rpath_link == NULL)
-	    command_line.rpath_link = buystring (optarg);
+	    command_line.rpath_link = xstrdup (optarg);
 	  else
 	    {
 	      char *buf;
Index: mpw-eppcmac.c
===================================================================
RCS file: /cvs/src/src/ld/mpw-eppcmac.c,v
retrieving revision 1.3
diff -u -p -r1.3 mpw-eppcmac.c
--- mpw-eppcmac.c	2001/03/13 06:14:27	1.3
+++ mpw-eppcmac.c	2001/05/02 16:37:57
@@ -843,7 +843,7 @@ gldppcmacos_read_file (filename, import)
 	  n = ((struct export_symbol_list *)
 	       xmalloc (sizeof (struct export_symbol_list)));
 	  n->next = export_symbols;
-	  n->name = buystring (symname);
+	  n->name = xstrdup (symname);
 	  n->syscall = syscall;
 	  export_symbols = n;
 	}


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