Message ID | 20200512173104.2293073-1-masahiroy@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | qom/object: pass (Object *) to object_initialize_with_type() | expand |
On 5/12/20 7:31 PM, Masahiro Yamada wrote: > object_new_with_type() already passes (Object *) pointer. > Avoid casting back and forth. But object_initialize() doesn't... > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > --- > > qom/object.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/qom/object.c b/qom/object.c > index e4085d8ae2..9d1a918e42 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -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)); >
On Wed, May 13, 2020 at 3:17 AM Philippe Mathieu-Daudé <philmd@redhat.com> wrote: > > On 5/12/20 7:31 PM, Masahiro Yamada wrote: > > 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. > > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > --- > > > > qom/object.c | 4 +--- > > 1 file changed, 1 insertion(+), 3 deletions(-) > > > > diff --git a/qom/object.c b/qom/object.c > > index e4085d8ae2..9d1a918e42 100644 > > --- a/qom/object.c > > +++ b/qom/object.c > > @@ -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)); > > > -- Best Regards Masahiro Yamada
On 12/05/20 19:31, Masahiro Yamada wrote: > object_new_with_type() already passes (Object *) pointer. > Avoid casting back and forth. > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > --- > > qom/object.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/qom/object.c b/qom/object.c > index e4085d8ae2..9d1a918e42 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -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)); > Queued, thanks. Paolo
diff --git a/qom/object.c b/qom/object.c index e4085d8ae2..9d1a918e42 100644 --- a/qom/object.c +++ b/qom/object.c @@ -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));
object_new_with_type() already passes (Object *) pointer. Avoid casting back and forth. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> --- qom/object.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)