qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v2 44/58] qom: provide convenient macros for declaring and de


From: Eduardo Habkost
Subject: Re: [PATCH v2 44/58] qom: provide convenient macros for declaring and defining types
Date: Thu, 20 Aug 2020 13:45:06 -0400

(CCing Eric Blake, who reviewed the original patch.  Sorry for
not CCing you previously, Eric)

On Wed, Aug 19, 2020 at 08:12:22PM -0400, Eduardo Habkost wrote:
[...]
> +/**
> + * OBJECT_DECLARE_TYPE:
> + * @ModuleObjName: the object name with initial capitalization
> + * @module_obj_name: the object name in lowercase with underscore separators
> + * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators

We need to decide what to do with TYPE_SWIM:

  #define TYPE_SWIM "swim"
  typedef struct SWIM SWIM;
  #define SWIM(obj) OBJECT_CHECK(SWIM, (obj), TYPE_SWIM)

Both the typedef and type checking macros are called "SWIM".
This makes usage of OBJECT_DECLARE_TYPE impossible (because the
type checking function can't have the same as the typedef).  What
should be the recommended style here?  Rename the struct to
"Swim"?

We have similar issues with RXCPU and ARMSSE, but these type
checking macros can be easily renamed to RX_CPU and ARM_SSE. so
they won't be an issue.

> + *
> + * This macro is typically used in a header file, and will:
> + *
> + *   - create the typedefs for the object and class structs
> + *   - register the type for use with g_autoptr
> + *   - provide three standard type cast functions
> + *
> + * The object struct and class struct need to be declared manually.
> + */
> +#define OBJECT_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME) 
> \
> +    typedef struct ModuleObjName ModuleObjName; \
> +    typedef struct ModuleObjName##Class ModuleObjName##Class; \
> +    \
> +    G_DEFINE_AUTOPTR_CLEANUP_FUNC(ModuleObjName, object_unref) \
> +    \
> +    static inline G_GNUC_UNUSED ModuleObjName##Class * \
> +    MODULE_OBJ_NAME##_GET_CLASS(void *obj) \
> +    { return OBJECT_GET_CLASS(ModuleObjName##Class, obj, \
> +                              TYPE_##MODULE_OBJ_NAME); } \
> +    \
> +    static inline G_GNUC_UNUSED ModuleObjName##Class * \
> +    MODULE_OBJ_NAME##_CLASS(void *klass) \
> +    { return OBJECT_CLASS_CHECK(ModuleObjName##Class, klass, \
> +                                TYPE_##MODULE_OBJ_NAME); } \
> +    \
> +    static inline G_GNUC_UNUSED ModuleObjName * \
> +    MODULE_OBJ_NAME(void *obj) \
> +    { return OBJECT_CHECK(ModuleObjName, obj, \
> +                          TYPE_##MODULE_OBJ_NAME); }
[...]

-- 
Eduardo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]