[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initi
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initialize_as_child() |
Date: |
Thu, 12 Jul 2018 18:09:21 +0100 |
On 12 July 2018 at 17:55, Thomas Huth <address@hidden> wrote:
> On 12.07.2018 18:52, Eduardo Habkost wrote:
>> On Thu, Jul 12, 2018 at 05:30:59PM +0200, Thomas Huth wrote:
>>> @@ -749,6 +749,25 @@ int object_set_propv(Object *obj,
>>> void object_initialize(void *obj, size_t size, const char *typename);
>>>
>>> /**
>>> + * object_initialize_as_child:
>>> + * @parentobj: The parent object to add a property to
>>> + * @propname: The name of the property
>>> + * @childobj: A pointer to the memory to be used for the object.
>>> + * @size: The maximum size available at @obj for the object.
>>> + * @type: The name of the type of the object to instantiate.
>>> + * @errp: If an error occurs, a pointer to an area to store the area
>>> + *
>>> + * This function will initialize an object. The memory for the object
>>> should
>>> + * have already been allocated. The object will then be added as child
>>> property
>>> + * to a parent with object_property_add_child() function. The returned
>>> object
>>> + * has a reference count of 1, and will be finalized when the last
>>> reference is
>>> + * dropped.
>>> + */
>>> +void object_initialize_as_child(Object *parentobj, const char *propname,
>>> + void *childobj, size_t size, const char
>>> *type,
>>> + Error **errp);
>>
>> Why did you use void* instead of Object*?
>
> That's the same what object_initialize() is doing (see above). Otherwise
> all the callers have to cast their pointers with OBJECT() first.
Casting with OBJECT() would not work, because it does a typecheck.
At the point where something is calling object_initialize() or
object_initialize_with_child(), the memory at 'childobj' has not
been initialized, so a typecheck is impossible.
It's only once the object has actually been initialized that
the memory is a valid Object* that you can put through OBJECT().
thanks
-- PMM
- [Qemu-devel] [PATCH v1 0/5] Fix crashes with introspection, Thomas Huth, 2018/07/12
- [Qemu-devel] [PATCH 2/5] hw/core/sysbus: Add a function for creating and attaching an object, Thomas Huth, 2018/07/12
- [Qemu-devel] [PATCH 3/5] hw/arm/bcm2836: Fix crash with device_add bcm2837 on unsupported machines, Thomas Huth, 2018/07/12
- [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initialize_as_child(), Thomas Huth, 2018/07/12
- Re: [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initialize_as_child(), Eduardo Habkost, 2018/07/12
- Re: [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initialize_as_child(), Paolo Bonzini, 2018/07/13
- Re: [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initialize_as_child(), Thomas Huth, 2018/07/13
- Re: [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initialize_as_child(), Paolo Bonzini, 2018/07/13
- Re: [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initialize_as_child(), Thomas Huth, 2018/07/13
Re: [Qemu-devel] [PATCH 1/5] qom/object: Add a new function object_initialize_as_child(), Eduardo Habkost, 2018/07/12
[Qemu-devel] [PATCH 4/5] hw/arm/armv7: Fix crash when introspecting the "iotkit" device, Thomas Huth, 2018/07/12
[Qemu-devel] [PATCH 5/5] hw/cpu/a15mpcore: Fix introspection problem with the a15mpcore_priv device, Thomas Huth, 2018/07/12
Re: [Qemu-devel] [PATCH v1 0/5] Fix crashes with introspection, Paolo Bonzini, 2018/07/12
Re: [Qemu-devel] [PATCH v1 0/5] Fix crashes with introspection, Peter Maydell, 2018/07/12