[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 23/46] qapi: Smooth error checking with Coccinelle
From: |
Markus Armbruster |
Subject: |
Re: [PATCH 23/46] qapi: Smooth error checking with Coccinelle |
Date: |
Thu, 25 Jun 2020 17:03:22 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Eric Blake <eblake@redhat.com> writes:
> On 6/24/20 11:43 AM, Markus Armbruster wrote:
>> The previous commit enables conversion of
>>
>> visit_foo(..., &err);
>> if (err) {
>> ...
>> }
>>
>> to
>>
>> if (!visit_foo(..., errp)) {
>> ...
>> }
>>
>> for visitor functions that now return true / false on success / error.
>> Coccinelle script:
>>
>> @@
>> identifier fun =~
>> "check_list|input_type_enum|lv_start_struct|lv_type_bool|lv_type_int64|lv_type_str|lv_type_uint64|output_type_enum|parse_type_bool|parse_type_int64|parse_type_null|parse_type_number|parse_type_size|parse_type_str|parse_type_uint64|print_type_bool|print_type_int64|print_type_null|print_type_number|print_type_size|print_type_str|print_type_uint64|qapi_clone_start_alternate|qapi_clone_start_list|qapi_clone_start_struct|qapi_clone_type_bool|qapi_clone_type_int64|qapi_clone_type_null|qapi_clone_type_number|qapi_clone_type_str|qapi_clone_type_uint64|qapi_dealloc_start_list|qapi_dealloc_start_struct|qapi_dealloc_type_anything|qapi_dealloc_type_bool|qapi_dealloc_type_int64|qapi_dealloc_type_null|qapi_dealloc_type_number|qapi_dealloc_type_str|qapi_dealloc_type_uint64|qobject_input_check_list|qobject_input_check_struct|qobject_input_start_alternate|qobject_input_start_list|qobject_input_start_struct|qobject_input_type_any|qobject_input_type_bool|qobject_input_type_bool_keyval|qobject_input_type_int64|qobject_input_type_int64_keyval|qobject_input_type_null|qobject_input_type_number|qobject_input_type_number_keyval|qobject_input_type_size_keyval|qobject_input_type_str|qobject_input_type_str_keyval|qobject_input_type_uint64|qobject_input_type_uint64_keyval|qobject_output_start_list|qobject_output_start_struct|qobject_output_type_any|qobject_output_type_bool|qobject_output_type_int64|qobject_output_type_null|qobject_output_type_number|qobject_output_type_str|qobject_output_type_uint64|start_list|visit_check_list|visit_check_struct|visit_start_alternate|visit_start_list|visit_start_struct|visit_type_.*";
>
> Long line. Does coccinelle understand \-newline wrapping?
Documentation is mum on it. A quick test appears to work. I'll check
whether I still get the same result here.
>> expression list args, args2;
>> typedef Error;
>> Error *err;
>> identifier errp;
>> @@
>> - fun(args, &err, args2);
>> - if (err) {
>> + if (!fun(args, errp, args2)) {
>> ... when != err
>> - error_propagate(errp, err);
>> ...
>> }
>>
>> @@
>> identifier fun =~
>> "check_list|input_type_enum|lv_start_struct|lv_type_bool|lv_type_int64|lv_type_str|lv_type_uint64|output_type_enum|parse_type_bool|parse_type_int64|parse_type_null|parse_type_number|parse_type_size|parse_type_str|parse_type_uint64|print_type_bool|print_type_int64|print_type_null|print_type_number|print_type_size|print_type_str|print_type_uint64|qapi_clone_start_alternate|qapi_clone_start_list|qapi_clone_start_struct|qapi_clone_type_bool|qapi_clone_type_int64|qapi_clone_type_null|qapi_clone_type_number|qapi_clone_type_str|qapi_clone_type_uint64|qapi_dealloc_start_list|qapi_dealloc_start_struct|qapi_dealloc_type_anything|qapi_dealloc_type_bool|qapi_dealloc_type_int64|qapi_dealloc_type_null|qapi_dealloc_type_number|qapi_dealloc_type_str|qapi_dealloc_type_uint64|qobject_input_check_list|qobject_input_check_struct|qobject_input_start_alternate|qobject_input_start_list|qobject_input_start_struct|qobject_input_type_any|qobject_input_type_bool|qobject_input_type_bool_keyval|qobject_input_type_int64|qobject_input_type_int64_keyval|qobject_input_type_null|qobject_input_type_number|qobject_input_type_number_keyval|qobject_input_type_size_keyval|qobject_input_type_str|qobject_input_type_str_keyval|qobject_input_type_uint64|qobject_input_type_uint64_keyval|qobject_output_start_list|qobject_output_start_struct|qobject_output_type_any|qobject_output_type_bool|qobject_output_type_int64|qobject_output_type_null|qobject_output_type_number|qobject_output_type_str|qobject_output_type_uint64|start_list|visit_check_list|visit_check_struct|visit_start_alternate|visit_start_list|visit_start_struct|visit_type_.*";
>
> The same list twice. Is there a way to write it only once, then refer
> to it by reference in the two halves of the script?
I wish I knew! Tell me, and I owe you a beverage of your choice at the
next in-person KVM Forum.
>> 46 files changed, 95 insertions(+), 331 deletions(-)
>
> Nice to see the size reduction.
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks!
- Re: [PATCH 35/46] qom: Use return values to check for error where that's simpler, (continued)
- [PATCH 27/46] qapi: Purge error_propagate() from QAPI core, Markus Armbruster, 2020/06/24
- [PATCH 33/46] qom: Crash more nicely on object_property_get_link() failure, Markus Armbruster, 2020/06/24
- [PATCH 25/46] qapi: Smooth visitor error checking in generated code, Markus Armbruster, 2020/06/24
- [PATCH 23/46] qapi: Smooth error checking with Coccinelle, Markus Armbruster, 2020/06/24
- [PATCH 30/46] s390x/pci: Fix harmless mistake in zpci's property fid's setter, Markus Armbruster, 2020/06/24
- [PATCH 37/46] qom: Make functions taking Error ** return bool, not void, Markus Armbruster, 2020/06/24
- [PATCH 26/46] qapi: Smooth another visitor error checking pattern, Markus Armbruster, 2020/06/24
- [PATCH 24/46] qapi: Smooth error checking manually, Markus Armbruster, 2020/06/24