Skip to contentSkip to conversation

qom/object: pass (Object *) to object_initialize_with_type()

PATCH Applied Masahiro Yamada 3 participants 4 messages May 12, 2020 – May 21, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qom/object: pass (Object *) to object_initialize_with_type()

object_new_with_type() already passes (Object *) pointer. Avoid casting back and forth.

---

 qom/object.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
qom/object.c +1 -3
index e4085d8ae2..9d1a918e42 100644
@@ -495,10 +495,8 @@ static void object_class_property_init_all(Object *obj)
     }
 }
 
-static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
+static void object_initialize_with_type(Object *obj, size_t size, TypeImpl *type)
 {
-    Object *obj = data;
-
     type_initialize(type);
 
     g_assert(type->instance_size >= sizeof(Object));
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Masahiro Yamada

object_new_with_type() already passes (Object *) pointer. Avoid casting back and forth.

But object_initialize() doesn't...

Quoted 24 lines

---

  qom/object.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
qom/object.c +1 -3
index e4085d8ae2..9d1a918e42 100644
@@ -495,10 +495,8 @@ static void object_class_property_init_all(Object *obj)
      }
  }
 
-static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
+static void object_initialize_with_type(Object *obj, size_t size, TypeImpl *type)
  {
-    Object *obj = data;
-
      type_initialize(type);
 
      g_assert(type->instance_size >= sizeof(Object));
#2 lore raw
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Masahiro Yamada

object_new_with_type() already passes (Object *) pointer. Avoid casting back and forth.

But object_initialize() doesn't...

That is no problem.

A caller can pass an opaque pointer
to a function that takes (Object *).

There is no explicit cast for it.

Quoted 23 lines
Quoted 23 lines

---

  qom/object.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
qom/object.c +1 -3
index e4085d8ae2..9d1a918e42 100644
@@ -495,10 +495,8 @@ static void object_class_property_init_all(Object *obj)
      }
  }
 
-static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
+static void object_initialize_with_type(Object *obj, size_t size, TypeImpl *type)
  {
-    Object *obj = data;
-
      type_initialize(type);
 
Quoted 3 lines

qom/object.c static void object_class_property_init_all(Object *obj) · line 502

Quoted 2 lines
qom/object.c +0 -0
      g_assert(type->instance_size >= sizeof(Object));

--
Best Regards
Masahiro Yamada

#3 lore raw
In reply to Masahiro Yamada
Quoted 16 lines · Masahiro Yamada

object_new_with_type() already passes (Object *) pointer. Avoid casting back and forth.

---

 qom/object.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
qom/object.c +0 -0
index e4085d8ae2..9d1a918e42 100644
@@ -495,10 +495,8 @@ static void object_class_property_init_all(Object *obj)
     }

qom/object.c static void object_class_property_init_all(Object *obj) · line 502

Quoted 10 lines
qom/object.c +1 -3
 }
 
-static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
+static void object_initialize_with_type(Object *obj, size_t size, TypeImpl *type)
 {
-    Object *obj = data;
-
     type_initialize(type);
 
     g_assert(type->instance_size >= sizeof(Object));

Queued, thanks.

Paolo