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

Re: [PATCH v2] lib: extend ASSERT()


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: George Dunlap <George.Dunlap@xxxxxxxxxx>
  • Date: Wed, 16 Feb 2022 12:23:47 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZslmnCZbH+Dwlon09I1JD2kLv+rewuSwj369UdN1pVI=; b=i6wtUpy4Qq8cxLN5VjSEVFm07ugJ/jY6EqMJ+EZ0LWoE8a2CpSeXVzFACRbthaOXDSoC+vZVsXBw65B0+yAv55S55BrIPB3VrUxUSJ2tjpRjUWBbtOwf1c3SPQ984W4z5qZuCCeeXpehg/aX3bqU8x7cMrdiiEybcRCzTubFlbGOW7bmO1UIzyGLIBoFWUNJHrg17X5ppiYeuUvgC/hTGhxwyRuxERA6z/WJCgSz71kawwkxyso4UczpcRHWY6dQmKYbz7Tr7CcJLbDllye49pkNarDAuOc1cYhpWOBgy7DFG9s+5D1OBeAJ0XHwXapWEc+fK/QE9l8ztqdPqQ1TIw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EATn1/qh1FdD7XTATLN5HbxeSkU3HQc2GAzNtSX77Sz/EqXu+q7gQdJlzCLMjqFdlFLbLleSbvGfXBadQSe3x5hKUJ5Mo+54wfPRTIrCWWxlYvoc08YbMIWMssgMGmo7k/EHILP4CdGY4bqCzL1blAK3XZS2cjzawapgbMaC1KQtjmOGbiVv6/qpg02fg7TUC6iQPbCxQqmDkmZpIXaO3aCfsDOb5zYlu/RpFveUJLwLH+/l7r6CUTXQXHdC231qMRjQhjnmz07hJdWq8FvDzjQz9FeKzH8hpw568iwYDXEjMGIiI5EH3nQbSQfCLAlrEw2lo4gWzPfYigmq+MoQlw==
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=hardfail (body hash did not verify [final]) header.i=@citrix.onmicrosoft.com
  • Cc: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Andrew Cooper" <Andrew.Cooper3@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Wed, 16 Feb 2022 12:24:02 +0000
  • Ironport-data: A9a23:viJiI64RFPrRXLBAcomosAxRtCXBchMFZxGqfqrLsTDasI4TYg02e lBvGjDRZK7OJyCgZYg1O70CxjoFu8PRx9cxGldr+XoxQSpH8JKcX96VcUqpZi6fccCfFhw7s JhCZIKacJ5sQnXQrEbza7Gw9ykmj6zYGeGgAeKeUswdqXeIbQ944f40s7Jp0uaE+OSEPj5hm e8eguWBNQX5hmEqbThLsfnSpUoztamp52xH5gZgPKFA4gCCyyhJAMoTK5/qIiqjSOG4PAIbq 8Uvbl2d1jmEl/v4Ior9yt4XSqCOK1LrFVDmZkB+AsBOuTAf4HxiukoHHKBEMx0P0WzXx4kZJ Ohl7vRcdy94ZsUgp8xFO/VoO3kW0XpuoeKvzdCX6KR//mWeG5fe66wG4HIeZOX0zt1fE2BWn cH0HRhWBvy1a0Ba95rgIgVkrpxLwMAGp+rzsFk4pd3SJa5OrZwu38wmTDKXtds9rpkmIBrQW yYWQTh0cTH4Xy1JAGgGAb8kse6qgCDjegQN/Tp5pYJvi4TS5Al40byrO9vJYN2aA85Smy50p EqfoT6/WEtDcoXCl3zVqRpAhceW9c//cK0fE6e3+7hGnVuXz3Q7AxwKT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gGrJaJvv+CCGROjHOzmp PmcOHFI27qOe3TEXHVlPQbbDe8jcKY9PEAdLukMf9y1cfgDIqHjceSPoimvky02AFY+0tzioCz w+nTVXTbdW3YjpbGbaGaUsRe
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYE4shsIFDV42A206yi2y9mPx4ZqyVNw0AgADQCYCAAAHgAIAAIi+AgAACZYCAAAt2AA==
  • Thread-topic: [PATCH v2] lib: extend ASSERT()


> On Feb 16, 2022, at 11:42 AM, Jan Beulich <jbeulich@xxxxxxxx> wrote:
> 
> On 16.02.2022 12:34, George Dunlap wrote:
> 
>> I am opposed to overloading “ASSERT” for this new kind of macro; I think it 
>> would not only be unnecessarily confusing to people not familiar with our 
>> codebase, but it would be too easy for people to fail to notice which macro 
>> was being used.
>> 
>> ASSERT_ACTION(condition, code) (or even ASSERT_OR_ACTION()) would be a bare 
>> minimum for me.
>> 
>> But I can’t imagine that there are more than a handful of actions we might 
>> want to take, so defining a macro for each one shouldn’t be too burdensome.
>> 
>> Furthermore, the very flexibility seems dangerous; you’re not seeing what 
>> actual code is generated, so it’s to easy to be “clever”, and/or write code 
>> that ends up doing something different than you expect.
>> 
>> At the moment I think ASSERT_OR_RETURN(condition, code), plus other new 
>> macros for the other behavior is needed, would be better.
> 
> Hmm, while I see your point of things possibly looking confusing or
> unexpected, something like ASSERT_OR_RETURN() (shouldn't it be
> ASSERT_AND_RETURN()?) is imo less readable. In particular I dislike
> the larger amount of uppercase text. But yes, I could accept this
> as a compromise as it still seems better to me than the multi-line
> constructs we currently use.

I see what you’re saying with AND/OR; I personally still prefer OR but wouldn’t 
argue to hard against AND if others preferred it.

As far as I’m concerned, the fact that we’re reducing lines of code isn’t a 
reason to use this at all.  As our CODING_STYLE says, ASSERT() is just a louder 
printk.  We would never consider writing PRINTK_AND_RETURN(), and we would 
never consider writing a macro like CONDRET(condition, retval) to replace

if (condition)
    return retval;

The only justification for this kind of macro, in my opinion, is to avoid 
duplication errors; i.e. replacing your code segment with the following:

if (condition) {
    ASSERT(!condition);
    return foo;
}

is undesirable because there’s too much risk that the conditions will drift or 
be inverted incorrectly. But having control statements like ‘return’ and 
‘continue’ in a macro is also undesirable in my opinion; I’m personally not 
sure which I find most undesirable.

I guess one advantage of something like ASSERT_OR(condition, return foo); or 
ASSERT_OR(condition, continue); is that searching for “return” or “continue” 
will come up even if you’re doing a case-sensitive search.  But I’m still wary 
of unintended side effects.

Bertrand / Julien, any more thoughts?

 -George

Attachment: signature.asc
Description: Message signed with OpenPGP


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.