Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MbYj5-0003U4-K9 for qemu-devel@nongnu.org; Thu, 13 Aug 2009 07:44:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MbYj1-0003TT-9U for qemu-devel@nongnu.org; Thu, 13 Aug 2009 07:44:11 -0400 Received: from [199.232.76.173] (port=43431 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MbYj1-0003TQ-56 for qemu-devel@nongnu.org; Thu, 13 Aug 2009 07:44:07 -0400 Received: from mx2.redhat.com ([66.187.237.31]:38491) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MbYj0-0002hJ-MD for qemu-devel@nongnu.org; Thu, 13 Aug 2009 07:44:06 -0400 Subject: Re: [Qemu-devel] [PATCH] qdev: add return value to init() callbacks. References: <1250092766-23986-1-git-send-email-kraxel@redhat.com> <200908122028.41012.paul@codesourcery.com> <4A831C47.3070309@redhat.com> <873a7w2q6n.fsf@pike.pond.sub.org> <4A83C562.1090802@redhat.com> <87tz0cytem.fsf@pike.pond.sub.org> <4A83F389.7080302@redhat.com> From: Markus Armbruster Date: Thu, 13 Aug 2009 13:42:02 +0200 In-Reply-To: <4A83F389.7080302@redhat.com> (Gerd Hoffmann's message of "Thu\, 13 Aug 2009 13\:05\:45 +0200") Message-ID: <87r5vgx7n9.fsf@pike.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: Paul Brook , qemu-devel@nongnu.org Gerd Hoffmann 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