block-coroutine-wrapper.py: support also basic return types (bsc#1211000)
Extend the regex to cover also return type, pointers included.
This implies that the value returned by the function cannot be
a simple "int" anymore, but the custom return type.
Therefore remove poll_state->ret and instead use a per-function
custom "ret" field.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-13-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Git-commit: 6700dfb1b8
References: bsc#1211000
Signed-off-by: Joao Silva <joao.silva@suse.com>
Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
This commit is contained in:
@@ -75,14 +75,15 @@ class FuncDecl:
|
||||
|
||||
|
||||
# Match wrappers declared with a generated_co_wrapper mark
|
||||
func_decl_re = re.compile(r'^int\s*generated_co_wrapper\s*'
|
||||
func_decl_re = re.compile(r'^(?P<return_type>[a-zA-Z][a-zA-Z0-9_]* [\*]?)'
|
||||
r'\s*generated_co_wrapper\s*'
|
||||
r'(?P<wrapper_name>[a-z][a-z0-9_]*)'
|
||||
r'\((?P<args>[^)]*)\);$', re.MULTILINE)
|
||||
|
||||
|
||||
def func_decl_iter(text: str) -> Iterator:
|
||||
for m in func_decl_re.finditer(text):
|
||||
yield FuncDecl(return_type='int',
|
||||
yield FuncDecl(return_type=m.group('return_type'),
|
||||
name=m.group('wrapper_name'),
|
||||
args=m.group('args'))
|
||||
|
||||
@@ -99,7 +100,6 @@ def snake_to_camel(func_name: str) -> str:
|
||||
|
||||
def gen_wrapper(func: FuncDecl) -> str:
|
||||
assert not '_co_' in func.name
|
||||
assert func.return_type == 'int'
|
||||
assert func.args[0].type in ['BlockDriverState *', 'BdrvChild *',
|
||||
'BlockBackend *']
|
||||
|
||||
@@ -123,6 +123,7 @@ def gen_wrapper(func: FuncDecl) -> str:
|
||||
|
||||
typedef struct {struct_name} {{
|
||||
BdrvPollCo poll_state;
|
||||
{func.return_type} ret;
|
||||
{ func.gen_block(' {decl};') }
|
||||
}} {struct_name};
|
||||
|
||||
@@ -130,13 +131,13 @@ static void coroutine_fn {name}_entry(void *opaque)
|
||||
{{
|
||||
{struct_name} *s = opaque;
|
||||
|
||||
s->poll_state.ret = {name}({ func.gen_list('s->{name}') });
|
||||
s->ret = {name}({ func.gen_list('s->{name}') });
|
||||
s->poll_state.in_progress = false;
|
||||
|
||||
aio_wait_kick();
|
||||
}}
|
||||
|
||||
int {func.name}({ func.gen_list('{decl}') })
|
||||
{func.return_type} {func.name}({ func.gen_list('{decl}') })
|
||||
{{
|
||||
if (qemu_in_coroutine()) {{
|
||||
return {name}({ func.gen_list('{name}') });
|
||||
@@ -150,7 +151,8 @@ int {func.name}({ func.gen_list('{decl}') })
|
||||
|
||||
s.poll_state.co = qemu_coroutine_create({name}_entry, &s);
|
||||
|
||||
return bdrv_poll_co(&s.poll_state);
|
||||
bdrv_poll_co(&s.poll_state);
|
||||
return s.ret;
|
||||
}}
|
||||
}}"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user