diff mbox

remove call to type_initialize in object_new_with_type

Message ID 1371120709-18923-3-git-send-email-hutao@cn.fujitsu.com
State New
Headers show

Commit Message

Hu Tao June 13, 2013, 10:51 a.m. UTC
Since it's called in object_initialize_with_type later.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 qom/object.c | 3 ---
 1 file changed, 3 deletions(-)

Comments

Hu Tao June 14, 2013, 7:09 a.m. UTC | #1
On Thu, Jun 13, 2013 at 06:51:49PM +0800, Hu Tao wrote:
> Since it's called in object_initialize_with_type later.
> 
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  qom/object.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 803b94b..38dc45e 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -406,9 +406,6 @@ Object *object_new_with_type(Type type)
>  {
>      Object *obj;
>  
> -    g_assert(type != NULL);
> -    type_initialize(type);
> -
>      obj = g_malloc(type->instance_size);

Well, type->instance_size has to be initialized before this.

>      object_initialize_with_type(obj, type);
>      obj->free = g_free;
> -- 
> 1.8.2.3
>
Peter Crosthwaite June 14, 2013, 1:02 p.m. UTC | #2
Hi Hu,

On Thu, Jun 13, 2013 at 8:51 PM, Hu Tao <hutao@cn.fujitsu.com> wrote:
> Since it's called in object_initialize_with_type later.
>
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  qom/object.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/qom/object.c b/qom/object.c
> index 803b94b..38dc45e 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -406,9 +406,6 @@ Object *object_new_with_type(Type type)
>  {
>      Object *obj;
>
> -    g_assert(type != NULL);
> -    type_initialize(type);
> -
>      obj = g_malloc(type->instance_size);

type->instance_size may be lazily set by type_initilize, so I think
this malloc will break for classes that inherit their instance size.
Some relevant code (qom/object.c):

228 static void type_initialize(TypeImpl *ti)
 229 {
[snip]
 236     ti->class_size = type_class_get_size(ti);
 237     ti->instance_size = type_object_get_size(ti);

 176 static size_t type_object_get_size(TypeImpl *ti)
 177 {
 178     if (ti->instance_size) {
 179         return ti->instance_size;
 180     }
 181
 182     if (type_has_parent(ti)) {
 183         return type_object_get_size(type_get_parent(ti));
 184     }
 185
 186     return 0;
 187 }

Regards,
Peter

>      object_initialize_with_type(obj, type);
>      obj->free = g_free;
> --
> 1.8.2.3
>
>
Peter Crosthwaite June 14, 2013, 1:06 p.m. UTC | #3
On Fri, Jun 14, 2013 at 5:09 PM, Hu Tao <hutao@cn.fujitsu.com> wrote:
> On Thu, Jun 13, 2013 at 06:51:49PM +0800, Hu Tao wrote:
>> Since it's called in object_initialize_with_type later.
>>
>> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
>> ---
>>  qom/object.c | 3 ---
>>  1 file changed, 3 deletions(-)
>>
>> diff --git a/qom/object.c b/qom/object.c
>> index 803b94b..38dc45e 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -406,9 +406,6 @@ Object *object_new_with_type(Type type)
>>  {
>>      Object *obj;
>>
>> -    g_assert(type != NULL);
>> -    type_initialize(type);
>> -
>>      obj = g_malloc(type->instance_size);
>
> Well, type->instance_size has to be initialized before this.
>

Missed this reply. Thanks for catching. Sorry for the noise.

Regards,
Peter

>>      object_initialize_with_type(obj, type);
>>      obj->free = g_free;
>> --
>> 1.8.2.3
>>
>
diff mbox

Patch

diff --git a/qom/object.c b/qom/object.c
index 803b94b..38dc45e 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -406,9 +406,6 @@  Object *object_new_with_type(Type type)
 {
     Object *obj;
 
-    g_assert(type != NULL);
-    type_initialize(type);
-
     obj = g_malloc(type->instance_size);
     object_initialize_with_type(obj, type);
     obj->free = g_free;