Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/3] gdb/python: add type traits check for all PyObject sub-classes
Date: Sat, 16 May 2026 13:27:42 +0100	[thread overview]
Message-ID: <87lddjczep.fsf@redhat.com> (raw)
In-Reply-To: <87tss8ha3h.fsf@tromey.com>

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> The problem is that Python is written in C, and PyObject_New doesn't
> Andrew> call any constructors for `some_new_type`, nor for any of the fields
> Andrew> within `some_new_type`.
>
> Since working on the Python safety series, I have been wondering if we
> could remedy this.  That is, give gdb's classes constructors and
> destructors and arrange for these to be called in-place in tp_init /
> whatever the destroy one is.
>
> This way we could use idiomatic gdb code, which would be safer.
>
> I was planning to investigate this more deeply once Matthew Longo's work
> was done, since I didn't want to touch all the type objects and cause
> conflicts.
>
> Andrew> +
> Andrew> +template <typename T>
> Andrew> +struct is_python_allocatable {
> Andrew> +  static constexpr bool value =
> Andrew> +    std::is_trivially_destructible_v<T> &&
> Andrew> +    std::is_trivially_copyable_v<T>;
>
> Brace and operator placement.

Fixed.  Thanks.

>
> Otherwise this looks good to me.
>
> If the tp_init experiment works out I suppose we may end up reverting
> this.  But IMO it's best not to wait on something that might not
> happen.

ACK.  If/when you have a better solution I'm happy for this series, at
least the static_assert bits and the associated test, to be removed.
This was really just me trying to find a way to "test" the fix that is
in patch #2.  If we can come up with a solution that means we can use
C++ objects and the constructos/destructors "just work" then I'm 100% in
favour.

For now though, I've gone ahead and pushed this series.

Thanks,
Andrew

>
> Approved-By: Tom Tromey <tom@tromey.com>
>
> Tom


  reply	other threads:[~2026-05-16 12:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 10:00 [PATCH 0/3] Use C++ type traits check to catch bugs in Python API Andrew Burgess
2026-05-15 10:00 ` [PATCH 1/3] gdb/python: add type traits check for all PyObject sub-classes Andrew Burgess
2026-05-15 17:10   ` Tom Tromey
2026-05-16 12:27     ` Andrew Burgess [this message]
2026-05-15 10:00 ` [PATCH 2/3] gdb/python: fix use of frame_info_ptr within pending_frame_object Andrew Burgess
2026-05-15 17:22   ` Tom Tromey
2026-05-16 12:28     ` Andrew Burgess
2026-05-15 10:00 ` [PATCH 3/3] gdb/testsuite: add a test to check for Python traits static_assert Andrew Burgess
2026-05-15 17:31   ` Tom Tromey
2026-05-16 12:29     ` Andrew Burgess

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=87lddjczep.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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