qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] qdev: add return value to init() callbacks.


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH] qdev: add return value to init() callbacks.
Date: Thu, 13 Aug 2009 13:42:02 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux)

Gerd Hoffmann <address@hidden> writes:

>   Hi,
>
>> I find stashing error messages for later printing rather awkward.  Do
>> you provide space for one fixed-sized message?  Or arbitrary length?
>> Arbitrary number of messages?  Once you start to malloc(), you get to
>> worry about free()...  Meh.
>
> Arbitrary length.  See attached patch.

I just don't like filing diagnostics away in the hope that somebody up
the stack will remember to print them :)

At least, qemu_error_message needs to be thread-local.

>> I'd rather use the global or thread-local state to hold the sink for the
>> messages, then send the messages there as we make them.  No memory
>> management worries.
>
> i.e. like config_error() in net.c?  What I don't like there is that
> the error handling policy (monitor -> continue, otherwise exit) is in
> the error printing function.  IMHO it is the job of the caller to
> decide how to handle an error (exit, ignore, pass up, whatever).

config_error() uses a Monitor * to encode what to do on error, which is
admittedly rather limiting.  If you want to be more flexible, use (error
callback, argument).  If you need a richer interface than that, define
an output object with suitable methods, say error, warning, information,
...

The difference to your patch is what the error object does.

With your patch:

    call stuff (may accumulate messages in the output object)
    flush output object down the appropriate sink

Alternative I'd prefer:

    set up output object to point to the appropriate sink
    call stuff (may print messages via output object to sink)

Look ma, no buffer management!

Output diversions are easy, too:

    save output object
    set up output object to point to the appropriate sink
    call stuff (may print messages via output object to sink)
    restore output object




reply via email to

[Prev in Thread] Current Thread [Next in Thread]