Il mar 21 gen 2020, 15:22 Markus Armbruster <arm...@redhat.com> ha scritto:

> > To see it a different way, these are the "C bindings" to QMP, just that
> > the implementation is an in-process call rather than RPC.  If the QAPI
> > code generator was also able to generate Python bindings and the like,
> > they would have to be the same for all QEMU binaries, wouldn't they?
>
> Ommitting the kind of #if we've been discussing is relatively harmless
> but what about this one, in qapi-types-block-core.h:
>
>     typedef enum BlockdevDriver {
>         BLOCKDEV_DRIVER_BLKDEBUG,
>         [...]
>     #if defined(CONFIG_REPLICATION)
>         BLOCKDEV_DRIVER_REPLICATION,
>     #endif /* defined(CONFIG_REPLICATION) */
>         [...]
>         BLOCKDEV_DRIVER__MAX,
>     } BlockdevDriver;
>

Well, I don't think this should be conditional at all. Introspection is a
tool to detect unsupported features, not working features. KVM will be
present in introspection data even if /dev/kvm doesn't exist on your
machine or you don't have permission to access it. I would restrict very
much #if usage in QAPI to the very minimum necessary.

Paolo



> If I omit it in the header, I then have to omit it in
> qapi-types-block-core.c's
>
>     const QEnumLookup BlockdevDriver_lookup = {
>         .array = (const char *const[]) {
>             [BLOCKDEV_DRIVER_BLKDEBUG] = "blkdebug",
>             [...]
>     #if defined(CONFIG_REPLICATION)
>             [BLOCKDEV_DRIVER_REPLICATION] = "replication",
>     #endif /* defined(CONFIG_REPLICATION) */
>             [...]
>         },
>         .size = BLOCKDEV_DRIVER__MAX
>     };
>
> and God knows what else.  But I must not omit it in qapi-introspect.c's
>
>         QLIT_QDICT(((QLitDictEntry[]) {
>             { "meta-type", QLIT_QSTR("enum"), },
>             { "name", QLIT_QSTR("245"), },
>             { "values", QLIT_QLIST(((QLitObject[]) {
>                 QLIT_QSTR("blkdebug"),
>                 [...]
>     #if defined(CONFIG_REPLICATION)
>                 QLIT_QSTR("replication"),
>     #endif /* defined(CONFIG_REPLICATION) */
>                 [...]
>                 {}
>             })), },
>             {}
>         })),
>
> because that would defeat introspection.
>
> I smell a swamp.
>
> I'd rather not complicate the generator to support not including a
> header I feel we *should* include.  #ifdef CONFIG_FOO can occur not just
> in QAPI-generated code, and neglecting to include the relevant header
> can cause *nasty* problems not just in QAPI-generated code.  Like
> inconsistent struct definitions in separate compilation units.  Been
> there, debugged that, wasn't fun, do not want to go there again.
>
>

Reply via email to