From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Wrap (and poison) PyObject_CallFunctionObjArgs
Date: Mon, 14 Sep 2026 16:09:20 -0400 [thread overview]
Message-ID: <7288831a-098e-486d-8c02-088a2e1affc3@simark.ca> (raw)
In-Reply-To: <20260914190624.4178522-1-tom@tromey.com>
On 9/14/26 3:06 PM, Tom Tromey wrote:
> This patch adds a new wrapper for PyObject_CallFunctionObjArgs. The
> wrapper function knows how to unwrap gdbpy_ref<> and
> gdbpy_borrowed_ref<>. It rejects null arguments, and it automatically
> supplies the trailing NULL required by PyObject_CallFunctionObjArgs.
> Finally, PyObject_CallFunctionObjArgs is poisoned to avoid introducing
> new calls.
>
> The idea behind this change is that passing anything other than
> PyObject* to this function will cause failures; this patch turns
> silent failures (like passing a gdbpy_borrowed_ref<>) into a
> compile-time failure.
LGTM, see minor comments below.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
> +/* A wrapper for PyObject_CallFunctionObjArgs that takes various kinds
> + of gdb wrappers, in addition to "PyObject *". This variant does
> + not allow NULL arguments. While PyObject_CallFunctionObjArgs
> + requires a trailing NULL, this function does not -- it supplies the
> + required trailing NULL on its own.
> +
> + As a safety measure, no argument may be NULL. While this may be
> + slightly inconvenient at times (you can't early-terminate the
> + arguments, you have to add a special case at the call site), it
> + avoids bugs where early termination was unintentional. */
I think it's fine. One example is in evpy_emit_event, and I find the
new code clearer, because it's more explicit about the two
possibilities.
> +template<typename Arg, typename... Args>
> +static inline gdbpy_ref<>
> +gdbpy_object_call_function_obj_args (Arg &&fn, Args && ...args)
> +{
> + PyObject *result
> + = PyObject_CallFunctionObjArgs (detail::unwrap_ref (fn),
> + detail::unwrap_ref (args)...,
> + nullptr);
> + return gdbpy_ref<> (result);
> +}
> +
> +/* Poison PyObject_CallFunctionObjArgs. The typesafe wrapper
> + gdbpy_objects_call_function_obj_args should be used instead. */
Typo, gdbpy_objects_call_function_obj_ar -> gdbpy_object_call_function_obj_args
> +#undef PyObject_CallFunctionObjArgs
> +#ifdef __GNUC__
> +# pragma GCC poison PyObject_CallFunctionObjArgs
> +#else
> +# define PyObject_CallFunctionObjArgs POISONED_PyObject_CallFunctionObjArgs
> +#endif
Clang appears to support "pragma GCC poison", could we use it
unconditionnaly?
Simon
next prev parent reply other threads:[~2026-09-14 20:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 19:06 Tom Tromey
2026-09-14 20:09 ` Simon Marchi [this message]
2026-09-14 22:15 ` Tom Tromey
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=7288831a-098e-486d-8c02-088a2e1affc3@simark.ca \
--to=simark@simark.ca \
--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