[PATCH v2 10/21] qom: Introduce type_is_registered()

Philippe Mathieu-Daudé posted 21 patches 11 months ago
There is a newer version of this series
[PATCH v2 10/21] qom: Introduce type_is_registered()
Posted by Philippe Mathieu-Daudé 11 months ago
In order to be able to check whether a QOM type has been
registered, introduce the type_is_registered() helper.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qom/object.h | 8 ++++++++
 qom/object.c         | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 9192265db76..5b5333017e0 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -898,6 +898,14 @@ Type type_register_static(const TypeInfo *info);
  */
 void type_register_static_array(const TypeInfo *infos, int nr_infos);
 
+/**
+ * type_is_registered:
+ * @typename: The @typename to check.
+ *
+ * Returns: %true if @typename has been registered, %false otherwise.
+ */
+bool type_is_registered(const char *typename);
+
 /**
  * DEFINE_TYPES:
  * @type_array: The array containing #TypeInfo structures to register
diff --git a/qom/object.c b/qom/object.c
index 01618d06bd8..be442980049 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -100,6 +100,11 @@ static TypeImpl *type_table_lookup(const char *name)
     return g_hash_table_lookup(type_table_get(), name);
 }
 
+bool type_is_registered(const char *typename)
+{
+    return !!type_table_lookup(typename);
+}
+
 static TypeImpl *type_new(const TypeInfo *info)
 {
     TypeImpl *ti = g_malloc0(sizeof(*ti));
-- 
2.47.1


Re: [PATCH v2 10/21] qom: Introduce type_is_registered()
Posted by Eric Auger 11 months ago


On 3/9/25 12:09 AM, Philippe Mathieu-Daudé wrote:
> In order to be able to check whether a QOM type has been
> registered, introduce the type_is_registered() helper.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
> ---
>  include/qom/object.h | 8 ++++++++
>  qom/object.c         | 5 +++++
>  2 files changed, 13 insertions(+)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 9192265db76..5b5333017e0 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -898,6 +898,14 @@ Type type_register_static(const TypeInfo *info);
>   */
>  void type_register_static_array(const TypeInfo *infos, int nr_infos);
>  
> +/**
> + * type_is_registered:
> + * @typename: The @typename to check.
> + *
> + * Returns: %true if @typename has been registered, %false otherwise.
> + */
> +bool type_is_registered(const char *typename);
> +
>  /**
>   * DEFINE_TYPES:
>   * @type_array: The array containing #TypeInfo structures to register
> diff --git a/qom/object.c b/qom/object.c
> index 01618d06bd8..be442980049 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -100,6 +100,11 @@ static TypeImpl *type_table_lookup(const char *name)
>      return g_hash_table_lookup(type_table_get(), name);
>  }
>  
> +bool type_is_registered(const char *typename)
> +{
> +    return !!type_table_lookup(typename);
> +}
> +
>  static TypeImpl *type_new(const TypeInfo *info)
>  {
>      TypeImpl *ti = g_malloc0(sizeof(*ti));


Re: [PATCH v2 10/21] qom: Introduce type_is_registered()
Posted by Cédric Le Goater 11 months ago
On 3/9/25 00:09, Philippe Mathieu-Daudé wrote:
> In order to be able to check whether a QOM type has been
> registered, introduce the type_is_registered() helper.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

FWIW,


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   include/qom/object.h | 8 ++++++++
>   qom/object.c         | 5 +++++
>   2 files changed, 13 insertions(+)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 9192265db76..5b5333017e0 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -898,6 +898,14 @@ Type type_register_static(const TypeInfo *info);
>    */
>   void type_register_static_array(const TypeInfo *infos, int nr_infos);
>   
> +/**
> + * type_is_registered:
> + * @typename: The @typename to check.
> + *
> + * Returns: %true if @typename has been registered, %false otherwise.
> + */
> +bool type_is_registered(const char *typename);
> +
>   /**
>    * DEFINE_TYPES:
>    * @type_array: The array containing #TypeInfo structures to register
> diff --git a/qom/object.c b/qom/object.c
> index 01618d06bd8..be442980049 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -100,6 +100,11 @@ static TypeImpl *type_table_lookup(const char *name)
>       return g_hash_table_lookup(type_table_get(), name);
>   }
>   
> +bool type_is_registered(const char *typename)
> +{
> +    return !!type_table_lookup(typename);
> +}
> +
>   static TypeImpl *type_new(const TypeInfo *info)
>   {
>       TypeImpl *ti = g_malloc0(sizeof(*ti));


Re: [PATCH v2 10/21] qom: Introduce type_is_registered()
Posted by Richard Henderson 11 months ago
On 3/8/25 15:09, Philippe Mathieu-Daudé wrote:
> In order to be able to check whether a QOM type has been
> registered, introduce the type_is_registered() helper.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   include/qom/object.h | 8 ++++++++
>   qom/object.c         | 5 +++++
>   2 files changed, 13 insertions(+)

Does the non-initialization of the type matter for your usage?
In other words, would object_class_by_name() do the job just as well?

But seems reasonable, anyway.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~