public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Subject: [PATCH 2/7] x86: de-duplicate sub-architecture strings accumulation
Date: Thu, 30 Jun 2022 14:53:35 +0200	[thread overview]
Message-ID: <736c0fe5-af5d-9d2d-d518-d5b3ccf8a4b8@suse.com> (raw)
In-Reply-To: <01f502ff-5b51-86d3-ed54-646df7d22037@suse.com>

Introduce a helper function to replace 4 instances of similar code. Use
reconcat() to cover the previously explicit free() (which really should
have been xfree() anyway).

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -2851,6 +2851,16 @@ check_cpu_arch_compatible (const char *n
 }
 
 static void
+extend_cpu_sub_arch_name (const char *name)
+{
+  if (cpu_sub_arch_name)
+    cpu_sub_arch_name = reconcat (cpu_sub_arch_name, cpu_sub_arch_name,
+				  name, (const char *) NULL);
+  else
+    cpu_sub_arch_name = xstrdup (name);
+}
+
+static void
 set_cpu_arch (int dummy ATTRIBUTE_UNUSED)
 {
   SKIP_WHITESPACE ();
@@ -2899,16 +2909,7 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED
 
 	      if (!cpu_flags_equal (&flags, &cpu_arch_flags))
 		{
-		  if (cpu_sub_arch_name)
-		    {
-		      char *name = cpu_sub_arch_name;
-		      cpu_sub_arch_name = concat (name,
-						  cpu_arch[j].name,
-						  (const char *) NULL);
-		      free (name);
-		    }
-		  else
-		    cpu_sub_arch_name = xstrdup (cpu_arch[j].name);
+		  extend_cpu_sub_arch_name (string);
 		  cpu_arch_flags = flags;
 		  cpu_arch_isa_flags = flags;
 		}
@@ -2932,15 +2933,7 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED
 					   cpu_noarch[j].flags);
 		if (!cpu_flags_equal (&flags, &cpu_arch_flags))
 		  {
-		    if (cpu_sub_arch_name)
-		      {
-			char *name = cpu_sub_arch_name;
-			cpu_sub_arch_name = concat (name, string,
-						    (const char *) NULL);
-			free (name);
-		      }
-		    else
-		      cpu_sub_arch_name = xstrdup (string);
+		    extend_cpu_sub_arch_name (string);
 		    cpu_arch_flags = flags;
 		    cpu_arch_isa_flags = flags;
 		  }
@@ -13430,16 +13423,7 @@ md_parse_option (int c, const char *arg)
 
 		  if (!cpu_flags_equal (&flags, &cpu_arch_flags))
 		    {
-		      if (cpu_sub_arch_name)
-			{
-			  char *name = cpu_sub_arch_name;
-			  cpu_sub_arch_name = concat (name,
-						      cpu_arch[j].name,
-						      (const char *) NULL);
-			  free (name);
-			}
-		      else
-			cpu_sub_arch_name = xstrdup (cpu_arch[j].name);
+		      extend_cpu_sub_arch_name (cpu_arch[j].name);
 		      cpu_arch_flags = flags;
 		      cpu_arch_isa_flags = flags;
 		    }
@@ -13463,15 +13447,7 @@ md_parse_option (int c, const char *arg)
 					       cpu_noarch[j].flags);
 		    if (!cpu_flags_equal (&flags, &cpu_arch_flags))
 		      {
-			if (cpu_sub_arch_name)
-			  {
-			    char *name = cpu_sub_arch_name;
-			    cpu_sub_arch_name = concat (arch,
-							(const char *) NULL);
-			    free (name);
-			  }
-			else
-			  cpu_sub_arch_name = xstrdup (arch);
+			extend_cpu_sub_arch_name (arch);
 			cpu_arch_flags = flags;
 			cpu_arch_isa_flags = flags;
 		      }


  parent reply	other threads:[~2022-06-30 12:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 12:52 [PATCH] gas/x86: .arch / -march= enhancements Jan Beulich
2022-06-30 12:53 ` [PATCH 1/7] x86: don't leak sub-architecture accumulated strings Jan Beulich
2022-06-30 22:54   ` H.J. Lu
2022-07-01 10:18     ` Jan Beulich
2022-07-01 19:44       ` H.J. Lu
2022-06-30 12:53 ` Jan Beulich [this message]
2022-06-30 22:55   ` [PATCH 2/7] x86: de-duplicate sub-architecture strings accumulation H.J. Lu
2022-06-30 12:53 ` [PATCH 3/7] x86: permit "default" with .arch Jan Beulich
2022-06-30 22:58   ` H.J. Lu
2022-06-30 12:54 ` [PATCH 4/7] x86: macro-ize cpu_arch[] entries Jan Beulich
2022-06-30 23:00   ` H.J. Lu
2022-06-30 12:54 ` [PATCH 5/7] x86: introduce fake processor type to mark sub-arch entries in cpu_arch[] Jan Beulich
2022-06-30 23:03   ` H.J. Lu
2022-06-30 12:55 ` [PATCH 6/7] x86: generalize disabling of sub-architectures Jan Beulich
2022-06-30 23:11   ` H.J. Lu
2022-06-30 12:55 ` [PATCH 7/7] x86: introduce a state stack for .arch Jan Beulich
2022-06-30 23:15   ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=736c0fe5-af5d-9d2d-d518-d5b3ccf8a4b8@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).