From: jacob navia <jacob@jacob.remcomp.fr>
To: binutils@sourceware.org
Subject: Use always XCNEW instead of XNEW
Date: Fri, 15 Sep 2023 13:17:20 +0200 [thread overview]
Message-ID: <885DB947-1B5C-489A-A283-223AFFDF6B48@jacob.remcomp.fr> (raw)
[-- Attachment #1: Type: text/plain, Size: 1124 bytes --]
Hi
Reflecting on the causes of the usage of XNEW (see my last mails) I think that as a general rule it would be much better if we always use XCNEW, that lease to calloc, instead of using XNEW that leads to malloc.
Look for instance at this code: (function riscv_set_arch file gas/config/tc-riscv.c)
if (riscv_rps_as.subset_list == NULL) {
riscv_rps_as.subset_list = XNEW(riscv_subset_list_t);
riscv_rps_as.subset_list->head = NULL;
riscv_rps_as.subset_list->tail = NULL;
riscv_rps_as.subset_list->arch_str = NULL;
}
All that could be replaced with:
if (riscv_rps_as.subset_list == NULL) {
riscv_rps_as.subset_list = XNEW(riscv_subset_list_t);
}
Besides, if you add a new field to the structure you have to modify all calls to the constructor adding a new field to set to NULL. In the second form all that is done automatically.
I think it would be a good idea to change then all usages of XNEW in calls to XCNEW.
Jacob
P.S. Yes, I know, there will be a performance loss of some microseconds in the case where you initialize fields anyway but I think that has absolutely NO IMPORTANCE.
reply other threads:[~2023-09-15 11:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=885DB947-1B5C-489A-A283-223AFFDF6B48@jacob.remcomp.fr \
--to=jacob@jacob.remcomp.fr \
--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).