[Qemu-devel] [PATCH for-3.2 v5 15/19] qom: add object_class_get_class_data()

Marc-André Lureau posted 19 patches 6 years, 10 months ago
There is a newer version of this series
[Qemu-devel] [PATCH for-3.2 v5 15/19] qom: add object_class_get_class_data()
Posted by Marc-André Lureau 6 years, 10 months ago
Add a simple function to retrieve the associated class data.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qom/object.h | 9 +++++++++
 qom/object.c         | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 5183c587f3..d5266405da 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -916,6 +916,15 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
  */
 ObjectClass *object_class_get_parent(ObjectClass *klass);
 
+
+/**
+ * object_class_get_class_data:
+ * @klass: The class to obtain associated data.
+ *
+ * Returns: the class_data given when registering the type.
+ */
+void *object_class_get_class_data(ObjectClass *klass);
+
 /**
  * object_class_get_name:
  * @klass: The class to obtain the QOM typename for.
diff --git a/qom/object.c b/qom/object.c
index aa6f3a2a71..bbc6fbbc01 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -867,6 +867,11 @@ const char *object_class_get_name(ObjectClass *klass)
     return klass->type->name;
 }
 
+void *object_class_get_class_data(ObjectClass *klass)
+{
+    return klass->type->class_data;
+}
+
 ObjectClass *object_class_by_name(const char *typename)
 {
     TypeImpl *type = type_get_by_name(typename);
-- 
2.20.0.rc1


Re: [Qemu-devel] [PATCH for-3.2 v5 15/19] qom: add object_class_get_class_data()
Posted by Igor Mammedov 6 years, 9 months ago
On Tue,  4 Dec 2018 18:20:19 +0400
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:

> Add a simple function to retrieve the associated class data.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  include/qom/object.h | 9 +++++++++
>  qom/object.c         | 5 +++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 5183c587f3..d5266405da 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -916,6 +916,15 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
>   */
>  ObjectClass *object_class_get_parent(ObjectClass *klass);
>  
> +
> +/**
> + * object_class_get_class_data:
> + * @klass: The class to obtain associated data.
> + *
> + * Returns: the class_data given when registering the type.
> + */
> +void *object_class_get_class_data(ObjectClass *klass);
> +
>  /**
>   * object_class_get_name:
>   * @klass: The class to obtain the QOM typename for.
> diff --git a/qom/object.c b/qom/object.c
> index aa6f3a2a71..bbc6fbbc01 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -867,6 +867,11 @@ const char *object_class_get_name(ObjectClass *klass)
>      return klass->type->name;
>  }
>  
> +void *object_class_get_class_data(ObjectClass *klass)
> +{
> +    return klass->type->class_data;
> +}
> +
>  ObjectClass *object_class_by_name(const char *typename)
>  {
>      TypeImpl *type = type_get_by_name(typename);

alternatively to what's done in 16/19 which requires this helper
you can drop it and use x86 cpu approach, see:

static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data)               
{                                                                                
    X86CPUDefinition *cpudef = data;                                             
    X86CPUClass *xcc = X86_CPU_CLASS(oc);                                        
                                                                                 
    xcc->cpu_def = cpudef;
    ...

Re: [Qemu-devel] [PATCH for-3.2 v5 15/19] qom: add object_class_get_class_data()
Posted by Marc-André Lureau 6 years, 9 months ago
Hi

On Tue, Dec 11, 2018 at 8:24 PM Igor Mammedov <imammedo@redhat.com> wrote:
>
> On Tue,  4 Dec 2018 18:20:19 +0400
> Marc-André Lureau <marcandre.lureau@redhat.com> wrote:
>
> > Add a simple function to retrieve the associated class data.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  include/qom/object.h | 9 +++++++++
> >  qom/object.c         | 5 +++++
> >  2 files changed, 14 insertions(+)
> >
> > diff --git a/include/qom/object.h b/include/qom/object.h
> > index 5183c587f3..d5266405da 100644
> > --- a/include/qom/object.h
> > +++ b/include/qom/object.h
> > @@ -916,6 +916,15 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
> >   */
> >  ObjectClass *object_class_get_parent(ObjectClass *klass);
> >
> > +
> > +/**
> > + * object_class_get_class_data:
> > + * @klass: The class to obtain associated data.
> > + *
> > + * Returns: the class_data given when registering the type.
> > + */
> > +void *object_class_get_class_data(ObjectClass *klass);
> > +
> >  /**
> >   * object_class_get_name:
> >   * @klass: The class to obtain the QOM typename for.
> > diff --git a/qom/object.c b/qom/object.c
> > index aa6f3a2a71..bbc6fbbc01 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -867,6 +867,11 @@ const char *object_class_get_name(ObjectClass *klass)
> >      return klass->type->name;
> >  }
> >
> > +void *object_class_get_class_data(ObjectClass *klass)
> > +{
> > +    return klass->type->class_data;
> > +}
> > +
> >  ObjectClass *object_class_by_name(const char *typename)
> >  {
> >      TypeImpl *type = type_get_by_name(typename);
>
> alternatively to what's done in 16/19 which requires this helper
> you can drop it and use x86 cpu approach, see:
>
> static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data)
> {
>     X86CPUDefinition *cpudef = data;
>     X86CPUClass *xcc = X86_CPU_CLASS(oc);
>
>     xcc->cpu_def = cpudef;
>     ...
>

Indeed, that's perhaps a better alternative. I'll update the patch.

-- 
Marc-André Lureau