[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v1 2/5] tools/ocaml/libs/xc: add binding to xc_evtchn_status
- To: Edwin Torok <edvin.torok@xxxxxxxxxx>
- From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
- Date: Thu, 1 Dec 2022 13:59:35 +0000
- Accept-language: en-GB, en-US
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; 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=PMPnxgIzo7ykEuiZkyBSQB0i85IGY7wDUm+O3cK+iCA=; b=PpKlTr1sc26JRPEyosFYVyWVe6jF3e7Zl0Uue9PGCyQXrkF7Box+2EJ4QdAA10A390GTERdE1Q2LiwgWk7XNwXUJl4PXotDyVZM6xpbWYjMGFAKjYxl4w0uzhJWa+uhM8YAoni9iKoWics0Xy0oPl7wWg/ywWu+CVtUZrECjHN4Eqa9JUjLWpEHz2WiTZQWGVnx6L/rN5ip+ksJy4crnc+XhZJJs/J8IN6jiD7znuO0ELTkBtQwUMz1v8rsj99wsHRmCK756IzpI14qZGffaAr5R4MlXh3Ks3iycozHnWdQzQSQ6N0t55uKr0PN8pHR1FlYuLYNDvTgSv774wqOvLA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UQEVRYQNvpiaITEGBJwoPlEW8EfWeRggyQsN9bhDyw9d9n573VduqJCOfmhX411//prRSQPGvsuiiYnVOXSrR+GpzAZaP3pvK6hKKOh0pWUytRMgivU72hC9oSChjTbO84wzArOtz5bC3r3iKnPGOxZlpAqhmJz83aJyk5UNKYORNkoyq6RzbWYfVT0kgZdEWd+9FQcQARwk8qZFI5uNT0Xk9tFyP9sHu5D1G84k6NlwREm0KuQO/vGiCJxoNdjrNHBBFQ5nI7QrLKa7XsjqywL/mh4g2jPEuFWsjodItv0SY0Cfc3udcKqZx7/Tprbdg2nceE+8Oy3rGGy38wjMNQ==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>
- Delivery-date: Thu, 01 Dec 2022 14:00:00 +0000
- Ironport-data: A9a23:31KB/a8xxNOsp2QPKJeHDrUDoH+TJUtcMsCJ2f8bNWPcYEJGY0x3z mccWGmPO/fZNmH0c9t1Pdi3ox8DucTUm9ZiGlds+Sg8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKucYHsZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kIx1BjOkGlA5AZnP6gS5AW2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDkli+ dwjByEmMSndiuCmnYC9bulotsc8eZyD0IM34hmMzBn/JNN/G9XmfP+P4tVVmjAtmspJAPDSI dIDbiZiZwjBZBsJPUoLDJU5n6GjgXyXnz9w8QrJ4/ZopTaNilAquFTuGIO9ltiibMNZhEuH4 EnB+Hz0GEoyP92D0zuVtHmrg4cjmAurBtpPS+Hmr5aGhnXIxXQDORQ1W2C4+/ajyX6bRd1TC VcLr39GQa8asRb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en developer discussion <xen-devel.lists.xenproject.org>
- Thread-index: AQHZBOHxNXiRQvtogESX/t4C8rGLVK5Y590AgAAh3oCAAAbKgA==
- Thread-topic: [PATCH v1 2/5] tools/ocaml/libs/xc: add binding to xc_evtchn_status
On 01/12/2022 13:35, Edwin Torok wrote:
>> On 1 Dec 2022, at 11:34, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx> wrote:
>>
>> On 30/11/2022 17:32, Edwin Török wrote:
>>> +
>>> + caml_enter_blocking_section();
>>> + rc = xc_evtchn_status(_H(xch), &status);
>>> + caml_leave_blocking_section();
>>> +
>>> + if ( rc < 0 )
>>> + failwith_xc(_H(xch));
>>> +
>>> + if ( status.status == EVTCHNSTAT_closed )
>>> + result = Val_none;
>>> + else
>>> + {
>> This is actually one example where using a second CAMLreturn would
>> simply things substantially.
>>
>> switch ( status.status )
>> {
>> case EVTCHNSTAT_closed:
>> CAMLreturn(Val_none);
>>
>> case EVTCHNSTAT_unbound:
>> ...
>>
>> Would remove the need for the outer if/else.
>
> CAMLreturn has some macro magic to ensure it gets paired with the toplevel
> CAMLparam correctly (one of them opens a { scope and the other closes it, or
> something like that),
> so I'd avoid putting it into the middle of other syntactic elements, it might
> just cause the build to fail (either now or in the future).
From the manual:
"The macros CAMLreturn, CAMLreturn0, and CAMLreturnT are used to replace
the C keyword return. Every occurrence of return x must be replaced by ..."
It is common in C to have multiple returns, and the manual does say
"Every occurrence" without stating any requirement for there to be a
single occurrence.
CAMLreturn can't syntactically work splitting a scope with CAMLparam,
because then this wouldn't compile:
CAMLprim value stub_xc_evtchn_status(value foo)
{
CAMLparam1(foo);
int bar = 0;
retry:
if ( bar )
CAMLreturn(foo);
bar++
goto retry;
}
CAMLreturn does use a normal "do { ... } while (0)" construct simply for
being a macro, and forces paring with CAMLparamX by referencing the
caml__frame local variable by name.
So I really do think that multiple CAMLreturns are fine and cannot
reasonably be broken in the future.
But if we do really still want to keep a single return, then a "goto
done" would be acceptable here and still better than the if/else.
>> caml_alloc_some() is perhaps less interesting as it only appeared in
>> Ocaml 4.12 AFAICT, but we could also have some ifdefary for that at the
>> top of the file.
>>
>> I don't know whether we have opencoded options elsewhere in the
>> bindings, but it certainly would be reduce the amount opencoding that
>> exists for standard patterns.
>
> perhaps we can look into doing that cleanup as a separate patch.
Probably best, yes.
~Andrew
|