public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: binutils@sourceware.org
Subject: [PATCH 20/22] libctf: don't pass errno into ctf_err_warn so often
Date: Wed, 17 Apr 2024 21:20:16 +0100	[thread overview]
Message-ID: <20240417202018.34966-21-nick.alcock@oracle.com> (raw)
In-Reply-To: <20240417202018.34966-1-nick.alcock@oracle.com>

The libctf-internal warning function ctf_err_warn() can be passed a libctf
errno as a parameter, and will add its textual errmsg form to the passed-in
error message. But if there is an error on the fp already, and this is
specifically an error and not a warning, ctf_err_warn() will print the error
out regardless: there's no need to pass in anything but 0.

There are still a lot of places where we do

ctf_err_warn (fp, 0, EFOO, ...);
return ctf_set_errno (fp, 0, EFOO);

I've left all of those alone, because fixing it makes the code a bit longer:
but fixing the cases where no return is involved and the error has just been
set on the fp itself costs nothing and reduces redundancy a bit.

libctf/

	* ctf-dedup.c (ctf_dedup_walk_output_mapping): Drop the errno arg.
	(ctf_dedup_emit): Likewise.
	(ctf_dedup_type_mapping): Likewise.
	* ctf-link.c (ctf_create_per_cu): Likewise.
	(ctf_link_deduplicating_close_inputs): Likewise.
	(ctf_link_deduplicating_one_symtypetab): Likewise.
	(ctf_link_deduplicating_per_cu): Likewise.
	* ctf-lookup.c (ctf_lookup_symbol_idx): Likewise.
	* ctf-subr.c (ctf_assert_fail_internal): Likewise.
---
 libctf/ctf-dedup.c  |  8 ++++----
 libctf/ctf-link.c   | 22 +++++++++++-----------
 libctf/ctf-lookup.c |  4 ++--
 libctf/ctf-subr.c   |  4 ++--
 4 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/libctf/ctf-dedup.c b/libctf/ctf-dedup.c
index dc7a1cf79e2..c7db6ab4965 100644
--- a/libctf/ctf-dedup.c
+++ b/libctf/ctf-dedup.c
@@ -2398,8 +2398,8 @@ ctf_dedup_walk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
     }
   if (err != ECTF_NEXT_END)
     {
-      ctf_err_warn (output, 0, err, _("cannot recurse over output mapping"));
       ctf_set_errno (output, err);
+      ctf_err_warn (output, 0, 0, _("cannot recurse over output mapping"));
       goto err;
     }
   ctf_dynset_destroy (already_visited);
@@ -3092,9 +3092,9 @@ ctf_dedup_emit (ctf_dict_t *output, ctf_dict_t **inputs, uint32_t ninputs,
 
   if ((outputs = calloc (num_outputs, sizeof (ctf_dict_t *))) == NULL)
     {
-      ctf_err_warn (output, 0, ENOMEM,
-		    _("out of memory allocating link outputs array"));
       ctf_set_errno (output, ENOMEM);
+      ctf_err_warn (output, 0, 0,
+		    _("out of memory allocating link outputs array"));
       return NULL;
     }
   *noutputs = num_outputs;
@@ -3146,7 +3146,7 @@ ctf_dedup_type_mapping (ctf_dict_t *fp, ctf_dict_t *src_fp, ctf_id_t src_type)
   else
     {
       ctf_set_errno (fp, ECTF_INTERNAL);
-      ctf_err_warn (fp, 0, ECTF_INTERNAL,
+      ctf_err_warn (fp, 0, 0,
 		    _("dict %p passed to ctf_dedup_type_mapping is not a "
 		      "deduplicated output"), (void *) fp);
       return CTF_ERR;
diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index 44d4e496f6a..801b6ee599d 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -330,9 +330,9 @@ ctf_create_per_cu (ctf_dict_t *fp, ctf_dict_t *input, const char *cu_name)
 
       if ((cu_fp = ctf_create (&err)) == NULL)
 	{
-	  ctf_err_warn (fp, 0, err, _("cannot create per-CU CTF archive for "
-				      "input CU %s"), cu_name);
 	  ctf_set_errno (fp, err);
+	  ctf_err_warn (fp, 0, 0, _("cannot create per-CU CTF archive for "
+				    "input CU %s"), cu_name);
 	  return NULL;
 	}
 
@@ -886,9 +886,9 @@ ctf_link_deduplicating_close_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
 	}
       if (err != ECTF_NEXT_END)
 	{
-	  ctf_err_warn (fp, 0, err, _("iteration error in deduplicating link "
-				      "input freeing"));
 	  ctf_set_errno (fp, err);
+	  ctf_err_warn (fp, 0, 0, _("iteration error in deduplicating link "
+				    "input freeing"));
 	}
     }
   else
@@ -1087,8 +1087,8 @@ ctf_link_deduplicating_one_symtypetab (ctf_dict_t *fp, ctf_dict_t *input,
   if (ctf_errno (input) != ECTF_NEXT_END)
     {
       ctf_set_errno (fp, ctf_errno (input));
-      ctf_err_warn (fp, 0, ctf_errno (input),
-		    functions ? _("iterating over function symbols") :
+      ctf_err_warn (fp, 0, 0, functions ?
+		    _("iterating over function symbols") :
 		    _("iterating over data symbols"));
       return -1;
     }
@@ -1156,9 +1156,9 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
 
       if (labs ((long int) ninputs) > 0xfffffffe)
 	{
-	  ctf_err_warn (fp, 0, EFBIG, _("too many inputs in deduplicating "
-					"link: %li"), (long int) ninputs);
 	  ctf_set_errno (fp, EFBIG);
+	  ctf_err_warn (fp, 0, 0, _("too many inputs in deduplicating "
+				    "link: %li"), (long int) ninputs);
 	  goto err_open_inputs;
 	}
 
@@ -1180,10 +1180,10 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
 						  &ai, NULL, 0, &err);
 	  if (!only_input->clin_fp)
 	    {
-	      ctf_err_warn (fp, 0, err, _("cannot open archive %s in "
-					  "CU-mapped CTF link"),
-			    only_input->clin_filename);
 	      ctf_set_errno (fp, err);
+	      ctf_err_warn (fp, 0, 0, _("cannot open archive %s in "
+					"CU-mapped CTF link"),
+			    only_input->clin_filename);
 	      goto err_open_inputs;
 	    }
 	  ctf_next_destroy (ai);
diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c
index 1b1ebedc4b7..e4d18bec112 100644
--- a/libctf/ctf-lookup.c
+++ b/libctf/ctf-lookup.c
@@ -665,8 +665,8 @@ ctf_lookup_symbol_idx (ctf_dict_t *fp, const char *symname, int try_parent,
     }
 oom:
   ctf_set_errno (fp, ENOMEM);
-  ctf_err_warn (fp, 0, ENOMEM, _("cannot allocate memory for symbol "
-				 "lookup hashtab"));
+  ctf_err_warn (fp, 0, 0, _("cannot allocate memory for symbol "
+			    "lookup hashtab"));
   return (unsigned long) -1;
 
 }
diff --git a/libctf/ctf-subr.c b/libctf/ctf-subr.c
index ecc68848d31..deb9e0ba5c4 100644
--- a/libctf/ctf-subr.c
+++ b/libctf/ctf-subr.c
@@ -340,7 +340,7 @@ void
 ctf_assert_fail_internal (ctf_dict_t *fp, const char *file, size_t line,
 			  const char *exprstr)
 {
-  ctf_err_warn (fp, 0, ECTF_INTERNAL, _("%s: %lu: libctf assertion failed: %s"),
-		file, (long unsigned int) line, exprstr);
   ctf_set_errno (fp, ECTF_INTERNAL);
+  ctf_err_warn (fp, 0, 0, _("%s: %lu: libctf assertion failed: %s"),
+		file, (long unsigned int) line, exprstr);
 }
-- 
2.44.0.273.ge0bd14271f


  parent reply	other threads:[~2024-04-17 20:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 20:19 [PATCH libctf 00/22] more modifiable CTF dicts (and a few bugfixes) Nick Alcock
2024-04-17 20:19 ` [PATCH 01/22] binutils, objdump: Add --ctf-parent-section Nick Alcock
2024-04-18  2:05   ` Alan Modra
2024-04-18 13:06     ` Nick Alcock
2024-04-17 20:19 ` [PATCH 02/22] libctf: don't leak the symbol name in the name->type cache Nick Alcock
2024-04-17 20:19 ` [PATCH 03/22] libctf: remove static/dynamic name lookup distinction Nick Alcock
2024-04-17 20:20 ` [PATCH 04/22] libctf: fix name lookup in dicts containing base-type bitfields Nick Alcock
2024-04-17 20:20 ` [PATCH 05/22] libctf: support addition of types to dicts read via ctf_open() Nick Alcock
2024-04-17 20:20 ` [PATCH 06/22] libctf: fix a comment Nick Alcock
2024-04-17 20:20 ` [PATCH 07/22] libctf: delete LCTF_DIRTY Nick Alcock
2024-04-17 20:20 ` [PATCH 08/22] libctf: fix a comment typo Nick Alcock
2024-04-17 20:20 ` [PATCH 09/22] libctf: rename ctf_dict.ctf_{symtab,strtab} Nick Alcock
2024-04-17 20:20 ` [PATCH 10/22] Revert "libctf: do not corrupt strings across ctf_serialize" Nick Alcock
2024-04-17 20:20 ` [PATCH 11/22] libctf: replace 'pending refs' abstraction Nick Alcock
2024-04-17 20:20 ` [PATCH 12/22] libctf: rethink strtab writeout Nick Alcock
2024-04-17 20:20 ` [PATCH 13/22] libctf: make ctf_serialize() actually serialize Nick Alcock
2024-04-17 20:20 ` [PATCH 14/22] libctf: fix tiny dumping error Nick Alcock
2024-04-17 20:20 ` [PATCH 15/22] libctf: improve handling of type dumping errors Nick Alcock
2024-04-17 20:20 ` [PATCH 16/22] libctf: make ctf_lookup of symbols by name work in more cases Nick Alcock
2024-04-17 20:20 ` [PATCH 17/22] libctf: fix a debugging typo Nick Alcock
2024-04-17 20:20 ` [PATCH 18/22] libctf: add rewriting tests Nick Alcock
2024-04-17 20:20 ` [PATCH 19/22] libctf: fix leak in test Nick Alcock
2024-04-17 20:20 ` Nick Alcock [this message]
2024-04-17 20:20 ` [PATCH 21/22] libctf: Remove undefined functions from ver. map Nick Alcock
2024-04-17 20:20 ` [PATCH 22/22] libctf: do not include undefined functions in libctf.ver Nick Alcock
2024-04-19 15:51 ` [PATCH libctf 00/22] more modifiable CTF dicts (and a few bugfixes) Nick Alcock

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=20240417202018.34966-21-nick.alcock@oracle.com \
    --to=nick.alcock@oracle.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).