* Use always XCNEW instead of XNEW
@ 2023-09-15 11:17 jacob navia
0 siblings, 0 replies; only message in thread
From: jacob navia @ 2023-09-15 11:17 UTC (permalink / raw)
To: binutils
[-- 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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-15 11:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-15 11:17 Use always XCNEW instead of XNEW jacob navia
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).