diff mbox

[1/2] qom: add object_new_with_class()

Message ID 20161005133530.5702-2-rkrcmar@redhat.com
State New
Headers show

Commit Message

Radim Krčmář Oct. 5, 2016, 1:35 p.m. UTC
object_new_with_object_class() was a close contender for the name, but
it is longer, the type system will catch possible errors, and the only
reasonable replacement would be a polymorphic function that would not
break existing users.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 include/qom/object.h | 12 ++++++++++++
 qom/object.c         |  5 +++++
 2 files changed, 17 insertions(+)

Comments

Eduardo Habkost Oct. 5, 2016, 2:44 p.m. UTC | #1
On Wed, Oct 05, 2016 at 03:35:29PM +0200, Radim Krčmář wrote:
> object_new_with_object_class() was a close contender for the name, but
> it is longer, the type system will catch possible errors, and the only
> reasonable replacement would be a polymorphic function that would not
> break existing users.
> 
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Alistair Francis Oct. 5, 2016, 3:54 p.m. UTC | #2
On Wed, Oct 5, 2016 at 7:44 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> On Wed, Oct 05, 2016 at 03:35:29PM +0200, Radim Krčmář wrote:
>> object_new_with_object_class() was a close contender for the name, but
>> it is longer, the type system will catch possible errors, and the only
>> reasonable replacement would be a polymorphic function that would not
>> break existing users.
>>
>> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
>
> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>

Thanks,

Alistair

>
> --
> Eduardo
>
diff mbox

Patch

diff --git a/include/qom/object.h b/include/qom/object.h
index 5ecc2d166d08..e50012237ce4 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -599,6 +599,18 @@  Object *object_new(const char *typename);
 Object *object_new_with_type(Type type);
 
 /**
+ * object_new_with_class:
+ * @class: The object class of the object to instantiate.
+ *
+ * This function will initialize a new object using heap allocated memory.
+ * The returned object has a reference count of 1, and will be freed when
+ * the last reference is dropped.
+ *
+ * Returns: The newly allocated and instantiated object.
+ */
+Object *object_new_with_class(ObjectClass *class);
+
+/**
  * object_new_with_props:
  * @typename:  The name of the type of the object to instantiate.
  * @parent: the parent object
diff --git a/qom/object.c b/qom/object.c
index 8166b7dace61..be75d6efc464 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -481,6 +481,11 @@  Object *object_new_with_type(Type type)
     return obj;
 }
 
+Object *object_new_with_class(ObjectClass *class)
+{
+    return object_new_with_type(class->type);
+}
+
 Object *object_new(const char *typename)
 {
     TypeImpl *ti = type_get_by_name(typename);