[PATCH-for-10.1 1/6] qom: Factor object_class_dynamic_cast_ambiguous() out

Philippe Mathieu-Daudé posted 6 patches 1 week, 5 days ago
[PATCH-for-10.1 1/6] qom: Factor object_class_dynamic_cast_ambiguous() out
Posted by Philippe Mathieu-Daudé 1 week, 5 days ago
In order to allow matching ambiguous types in the next commit,
factor object_class_dynamic_cast_ambiguous() out of
object_class_dynamic_cast().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 qom/object.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 01618d06bd8..1620a87ef44 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -940,8 +940,9 @@ out:
     return obj;
 }
 
-ObjectClass *object_class_dynamic_cast(ObjectClass *class,
-                                       const char *typename)
+static ObjectClass *object_class_dynamic_cast_ambiguous(ObjectClass *class,
+                                                        const char *typename,
+                                                        bool *ambiguous)
 {
     ObjectClass *ret = NULL;
     TypeImpl *target_type;
@@ -977,6 +978,9 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
             }
          }
 
+        if (ambiguous) {
+            *ambiguous = found > 0;
+        }
         /* The match was ambiguous, don't allow a cast */
         if (found > 1) {
             ret = NULL;
@@ -988,6 +992,12 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
     return ret;
 }
 
+ObjectClass *object_class_dynamic_cast(ObjectClass *class,
+                                       const char *typename)
+{
+    return object_class_dynamic_cast_ambiguous(class, typename, NULL);
+}
+
 ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
                                               const char *typename,
                                               const char *file, int line,
-- 
2.47.1