Received: from eggs.gnu.org ([2001:4830:134:3::10]:59322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhFYS-0007xn-F1 for qemu-devel@nongnu.org; Mon, 05 May 2014 05:51:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhFYM-0000sR-AD for qemu-devel@nongnu.org; Mon, 05 May 2014 05:51:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30218) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhFYM-0000sL-2b for qemu-devel@nongnu.org; Mon, 05 May 2014 05:51:18 -0400 From: Markus Armbruster References: <1398764656-27534-1-git-send-email-famz@redhat.com> <1398764656-27534-3-git-send-email-famz@redhat.com> <20140429112436.GE4835@noname.str.redhat.com> <535FA06F.2060603@redhat.com> Date: Mon, 05 May 2014 11:51:11 +0200 In-Reply-To: <535FA06F.2060603@redhat.com> (Eric Blake's message of "Tue, 29 Apr 2014 06:51:59 -0600") Message-ID: <87iopktuy8.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2 2/2] qapi: Allow setting default values for optional parameters List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Kevin Wolf , Peter Maydell , Fam Zheng , Michael Roth , qemu-devel@nongnu.org, Luiz Capitulino , akong@redhat.com Eric Blake writes: > On 04/29/2014 05:24 AM, Kevin Wolf wrote: >> Am 29.04.2014 um 11:44 hat Fam Zheng geschrieben: >>> In command definition, 'defaults' is now parsed as a dict of default >>> values. Only optional parameters will have effect in generated code. >>> >>> 'str' and 'int' are supported. In generated code, 'str' will be >>> converted to g_strdup'ed string pointer, 'int' will be identically >>> assigned. >>> > >>> { 'command': 'my-command', >>> - 'data': { 'arg1': 'str', '*arg2': 'str' }, >>> + 'data': { 'arg1': 'str', '*arg2': 'str', '*arg3': 'int' }, >>> + 'defaults': { 'arg2': 'default value for arg2', 'arg3': 12345 }, >>> 'returns': 'str' } >> >> I think we should document what effect setting a default has for the >> code generation, and that it can be left out even for optional arguments >> (because your example sets it for every optional member). > > That includes documenting that omitting a defaults entry for an optional > parameter will now guarantee 0-initialization of that member. Currently, an optional FOO should only be used when has_FOO. We initialize it anyway, to suppress complaints from static analyzers. Do we want to relax the rule "officially", so that code can rely on zero-initialization instead of checking has_FOO? >> Also, for the actual qmp_foo() handler, I would very much prefer if it >> didn't get a has_foo argument which is meaningless because it is always >> true. Instead, the has_foo argument shouldn't even be generated in the >> first place if the schema has a default for foo. > > Yes, that's a nice idea - anywhere we have a qapi-documented default, we > can simplify the code to take advantage of the default. It's backward > compatible since none of the existing code has any contract on defaults. s/can simplify/should simplify/! Defining a default value for FOO renders anything guarded by !has_FOO dead code. Not generating has_FOO is good, because it forces us to bury the dead code properly. Losely related: I want to get rid of has_FOO for pointer-valued FOOs, too. > Also, is the default value allowed to change between qemu versions? > What are the back-compat ramifications if two different releases want to > tweak an omitted variable to different defaults? The documentation > should mention the rule of thumb that we plan on enforcing during > reviews. I could go either way: the wire format is unimpacted by what > default value is used when an argument is omitted, and management can > always explicitly specify a parameter if they don't trust the default; > on the other hand, if changing a default changes visible behavior, then > we have not maintained ABI compatibility. We should use common sense. Changing the schema in a way that alters the meaning of existing usage is a no-no, and that applies to defaults as much as to anything else. But not every change of a default necessarily does that. Contrieved example: if the value defines a buffer size, and it's specified to default to a sensible size, then we can and should let the default value evolve along with our idea of what a sensible size is.