On Tue, Mar 02, 2021 at 08:46:18PM -0500, Nick Rosbrook wrote:
> +def libxl_func_define_device_add(func):
> +    s = ''
> +
> +    return_type = func.return_type.typename
> +    if isinstance(func.return_type, idl.Enumeration):
> +        return_type = idl.integer.typename
> +
> +    params = ', '.join([ ty.make_arg(name) for (name,ty) in func.params ])
> +
> +    s += '{0} {1}({2})\n'.format(return_type, func.name, params)
> +    s += '{\n'
> +    s += '\tAO_CREATE(ctx, domid, ao_how);\n'
> +    s += '\tlibxl__ao_device *aodev;\n\n'
> +    s += '\tGCNEW(aodev);\n'
> +    s += '\tlibxl__prepare_ao_device(ao, aodev);\n'
> +    s += '\taodev->action = LIBXL__DEVICE_ACTION_ADD;\n'
> +    s += '\taodev->callback = device_addrm_aocomplete;\n'
> +    s += '\taodev->update_json = true;\n'
> +    s += '\tlibxl__{0}(egc, domid, type, aodev);\n\n'.format(func.rawname)
> +    s += '\treturn AO_INPROGRESS;\n'
> +    s += '}\n'

That's kind of hard to read, I think we could use python's triple-quote
(or triple double-quote) ''' or """ to have a multi-line string and
remove all those \t \n
Something like:

    s = '''
    {ret} {func}({params})
    {{
        return ERROR_FAIL;
        libxl__{rawname}(gc);
    }}
    '''.format(ret=return_type, func=func.name, params=params,
               rawname=func.rawname)

That would produce some extra indentation in the generated C file, but
that doesn't matter to me. They could be removed with textwrap.dedent()
if needed.

Thanks,

-- 
Anthony PERARD

Reply via email to