* [pushed] Remove useless NULL check in python.c
@ 2020-02-19 14:57 Tom Tromey
2020-02-19 15:16 ` Christian Biesinger via gdb-patches
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2020-02-19 14:57 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I noticed that do_start_initialization, in python.c, checks the result
of xmalloc. However, xmalloc cannot fail, so this check is useless.
This patch also changes the code to use XNEWVEC.
gdb/ChangeLog
2020-02-19 Tom Tromey <tromey@adacore.com>
* python/python.c (do_start_initialization): Use XNEWVEC. Remove
NULL check.
---
gdb/ChangeLog | 5 +++++
gdb/python/python.c | 7 +------
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 27d6042c618..fbbc159ede3 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1679,12 +1679,7 @@ do_start_initialization ()
std::string oldloc = setlocale (LC_ALL, NULL);
setlocale (LC_ALL, "");
progsize = strlen (progname.get ());
- progname_copy = (wchar_t *) xmalloc ((progsize + 1) * sizeof (wchar_t));
- if (!progname_copy)
- {
- fprintf (stderr, "out of memory\n");
- return false;
- }
+ progname_copy = XNEWVEC (wchar_t, progsize + 1);
count = mbstowcs (progname_copy, progname.get (), progsize + 1);
if (count == (size_t) -1)
{
--
2.21.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [pushed] Remove useless NULL check in python.c
2020-02-19 14:57 [pushed] Remove useless NULL check in python.c Tom Tromey
@ 2020-02-19 15:16 ` Christian Biesinger via gdb-patches
2020-02-19 15:35 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Christian Biesinger via gdb-patches @ 2020-02-19 15:16 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Wed, Feb 19, 2020, 18:57 Tom Tromey <tromey@adacore.com> wrote:
> I noticed that do_start_initialization, in python.c, checks the result
> of xmalloc. However, xmalloc cannot fail, so this check is useless.
> This patch also changes the code to use XNEWVEC.
>
> gdb/ChangeLog
> 2020-02-19 Tom Tromey <tromey@adacore.com>
>
> * python/python.c (do_start_initialization): Use XNEWVEC. Remove
> NULL check.
> ---
> gdb/ChangeLog | 5 +++++
> gdb/python/python.c | 7 +------
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index 27d6042c618..fbbc159ede3 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -1679,12 +1679,7 @@ do_start_initialization ()
> std::string oldloc = setlocale (LC_ALL, NULL);
> setlocale (LC_ALL, "");
> progsize = strlen (progname.get ());
> - progname_copy = (wchar_t *) xmalloc ((progsize + 1) * sizeof (wchar_t));
> - if (!progname_copy)
> - {
> - fprintf (stderr, "out of memory\n");
> - return false;
> - }
> + progname_copy = XNEWVEC (wchar_t, progsize + 1);
>
Have you considered using STD::wstring instead of this manual memory
management?
count = mbstowcs (progname_copy, progname.get (), progsize + 1);
if (count == (size_t) -1)
> {
> --
> 2.21.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [pushed] Remove useless NULL check in python.c
2020-02-19 15:16 ` Christian Biesinger via gdb-patches
@ 2020-02-19 15:35 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2020-02-19 15:35 UTC (permalink / raw)
To: Christian Biesinger via gdb-patches; +Cc: Tom Tromey, Christian Biesinger
>>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:
Christian> Have you considered using STD::wstring instead of this manual memory
Christian> management?
I did, but converting to wstring seemed unusually complicated compared
to what we have. Though, this isn't a part of C++ that I know well, so
I'm open to being wrong about that.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-02-19 15:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-19 14:57 [pushed] Remove useless NULL check in python.c Tom Tromey
2020-02-19 15:16 ` Christian Biesinger via gdb-patches
2020-02-19 15:35 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox