All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org,  zhao1.liu@intel.com,  qemu-rust@nongnu.org
Subject: Re: [PATCH 04/14] util/error: allow non-NUL-terminated err->src
Date: Thu, 05 Jun 2025 13:57:02 +0200	[thread overview]
Message-ID: <87y0u6flkh.fsf@pond.sub.org> (raw)
In-Reply-To: <87a56mh08w.fsf@pond.sub.org> (Markus Armbruster's message of "Thu, 05 Jun 2025 13:54:39 +0200")

Markus Armbruster <armbru@redhat.com> writes:

> Paolo Bonzini <pbonzini@redhat.com> writes:
>
>> Rust makes the current file available as a statically-allocated string,
>> but without a NUL terminator.  Allow this by storing an optional maximum
>> length in the Error.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  include/qapi/error-internal.h | 9 ++++++++-
>>  util/error.c                  | 5 +++--
>>  2 files changed, 11 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/qapi/error-internal.h b/include/qapi/error-internal.h
>> index d5c3904adec..1ec3ceb40f0 100644
>> --- a/include/qapi/error-internal.h
>> +++ b/include/qapi/error-internal.h
>> @@ -18,7 +18,14 @@ struct Error
>>  {
>>      char *msg;
>>      ErrorClass err_class;
>> -    const char *src, *func;
>> +    const char *func;
>> +
>> +    /*
>> +     * src might be NUL-terminated or not.  If it is, src_len is negative.
>> +     * If it is not, src_len is the length.
>> +     */
>
> I habitually prefix identifiers with @ in comments, like this:
>
>        /*
>         * @src might be NUL-terminated or not.  If it is, @src_len is
>         * negative.  If it is not, @src_len is the length.
>         */
>
> Can really help readability when identifiers are also common English
> words.  Not much of a difference here.  Still nice for consistency with
> error.h.
>
>> +    const char *src;
>> +    int src_len;
>>      int line;
>>      GString *hint;
>>  };
>> diff --git a/util/error.c b/util/error.c
>> index e5bcb7c0225..3449ecc0b92 100644
>> --- a/util/error.c
>> +++ b/util/error.c
>> @@ -24,8 +24,8 @@ Error *error_warn;
>>  static void error_handle(Error **errp, Error *err)
>>  {
>>      if (errp == &error_abort) {
>> -        fprintf(stderr, "Unexpected error in %s() at %s:%d:\n",
>> -                err->func, err->src, err->line);
>> +        fprintf(stderr, "Unexpected error in %s() at %.*s:%d:\n",
>> +                err->func, err->src_len, err->src, err->line);
>>          error_report("%s", error_get_pretty(err));
>>          if (err->hint) {
>>              error_printf("%s", err->hint->str);
>> @@ -67,6 +67,7 @@ static void error_setv(Error **errp,
>>          g_free(msg);
>>      }
>>      err->err_class = err_class;
>> +    err->src_len = -1;
>>      err->src = src;
>>      err->line = line;
>>      err->func = func;

Almost forgot:

Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2025-06-05 11:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 10:15 [PATCH v3 00/14] rust: bindings for Error Paolo Bonzini
2025-06-05 10:15 ` [PATCH 01/14] subprojects: add the anyhow crate Paolo Bonzini
2025-06-05 10:15   ` Paolo Bonzini via
2025-06-05 10:15 ` [PATCH 02/14] subprojects: add the foreign crate Paolo Bonzini
2025-06-05 10:15 ` [PATCH 03/14] util/error: expose Error definition to Rust code Paolo Bonzini
2025-06-05 13:31   ` Zhao Liu
2025-06-05 10:15 ` [PATCH 04/14] util/error: allow non-NUL-terminated err->src Paolo Bonzini
2025-06-05 11:54   ` Markus Armbruster
2025-06-05 11:57     ` Markus Armbruster [this message]
2025-06-05 13:32   ` Zhao Liu
2025-06-05 10:15 ` [PATCH 05/14] util/error: make func optional Paolo Bonzini
2025-06-05 11:57   ` Markus Armbruster
2025-06-05 10:15 ` [PATCH 06/14] rust: qemu-api: add bindings to Error Paolo Bonzini
2025-06-05 12:06   ` Markus Armbruster
2025-06-05 13:45   ` Zhao Liu
2025-06-05 10:15 ` [PATCH 07/14] rust: qemu-api: add tests for Error bindings Paolo Bonzini
2025-06-05 13:53   ` Zhao Liu
2025-06-05 10:15 ` [PATCH 08/14] rust: qdev: support returning errors from realize Paolo Bonzini
2025-06-05 10:15 ` [PATCH 09/14] rust/hpet: change type of num_timers to usize Paolo Bonzini
2025-06-05 10:15 ` [PATCH 10/14] hpet: adjust VMState for consistency with Rust version Paolo Bonzini
2025-06-05 10:15 ` [PATCH 11/14] hpet: return errors from realize if properties are incorrect Paolo Bonzini
2025-06-05 10:15 ` [PATCH 12/14] rust/hpet: " Paolo Bonzini
2025-06-05 10:15 ` [PATCH 13/14] rust/hpet: Drop BqlCell wrapper for num_timers Paolo Bonzini
2025-06-05 10:15 ` [PATCH 14/14] docs: update Rust module status Paolo Bonzini
  -- strict thread matches above, loose matches on Subject: below --
2025-05-30  8:02 [PATCH v2 00/14] rust: bindings for Error Paolo Bonzini
2025-05-30  8:02 ` [PATCH 04/14] util/error: allow non-NUL-terminated err->src Paolo Bonzini
2025-06-02 10:47   ` Markus Armbruster

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=87y0u6flkh.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=zhao1.liu@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.