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

Re: [RFC v2 6/7] libxl: implement device add/remove/destroy functions generation


  • To: Nick Rosbrook <rosbrookn@xxxxxxxxx>
  • From: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Date: Tue, 4 May 2021 16:02:55 +0100
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <george.dunlap@xxxxxxxxxx>, "Nick Rosbrook" <rosbrookn@xxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 04 May 2021 15:03:12 +0000
  • Ironport-hdrordr: A9a23:wNupua/pajgfEffGhfhuk+BJI+orLtY04lQ7vn1ZYzY9SK2lvu qpm+kW0gKxpTYKQXc7mc2BPq7oewK6ybde544NMbC+GDT3oWfAFvAH0aLOyyDtcheTysdzzq FlGpIQNPTRChxAgd/+8E2EFb8bsb+62YSJocub8Ht3VwFtbMhbnmJEIyKWCFd/SgUDJbdRLu v+2uN9qzCteWsaY62AbxFvNYX+jubGm578bRkNCwRP0njtsRqS5KPnCB/d5x8CUlp0sM4f2F LYmA/07LjLiZGG4yLbvlW806hr
  • Ironport-sdr: LXlZInGMc84TC13rmkdvYlglLgEPiYzHshJbYVslgnsuVGucC3WnlT2tt2Q9DeaVZATqjJYJUP +YCNFFzNunCebmOumatmw/dVL2cTDBwuC5HHa58nbSYoC5vhDOCn+HY9R30axF8FAcAJkrQdnC IJlehiPu1xdHxgIQnwp7cnpclin2JRD3+mgQzRqsrB8vBlv88h9RWAdynnRAfld7SbKJO7jorX S+X1NcJn2ULIgSKucAN7iB/nFcYfUO0W+ASpaJbCFu766EPyrYlWAjg4Jo8c8wRn3W2aPs5akj erc=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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



 


Rackspace

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