From: Alexander Barabash <alexander_barabash@mentor.com>
To: <qemu-trivial@nongnu.org>, qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-trivial] [PATCH] [TRIVIAL] Replace object_delete() with object_unref().
Date: Thu, 16 Feb 2012 19:38:46 +0200 [thread overview]
Message-ID: <4F3D3F26.8010402@mentor.com> (raw)
Replace object_delete() with object_unref().
In the existing implementation, object_delete()
calls object_unref(), then frees the object's storage.
Running object_delete() on an object with reference count
different from one (1) causes program failure.
In the existing implementation, object_unref()
finalizes the object when its reference count becomes zero (0).
In the new implementation, object_unref()
finalizes and frees the object's storage when the reference count
becomes zero (0).
One usage of object_delete() replaced by object_unref().
Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com>
diff --git a/hw/qdev.c b/hw/qdev.c
index f0eb3a7..891981a 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -247,7 +247,7 @@ void qdev_init_nofail(DeviceState *dev)
/* Unlink device from bus and free the structure. */
void qdev_free(DeviceState *dev)
{
- object_delete(OBJECT(dev));
+ object_unref(OBJECT(dev));
}
void qdev_machine_creation_done(void)
diff --git a/include/qemu/object.h b/include/qemu/object.h
index 69cc2ab..e7e32fe 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -415,8 +415,9 @@ struct InterfaceInfo
* object_new:
* @typename: The name of the type of the object to instantiate.
*
- * This function will initialize a new object using heap allocated
memory. This
- * function should be paired with object_delete() to free the resources
+ * This function will initialize a new object using heap allocated memory.
+ * The object's reference count will be set to one (1) upon successful
completion.
+ * This function should be paired with object_unref() to free the resources
* associated with the object.
*
* Returns: The newly allocated and instantiated object.
@@ -427,8 +428,9 @@ Object *object_new(const char *typename);
* object_new_with_type:
* @type: The type of the object to instantiate.
*
- * This function will initialize a new object using heap allocated
memory. This
- * function should be paired with object_delete() to free the resources
+ * This function will initialize a new object using heap allocated memory.
+ * The object's reference count will be set to one (1) upon successful
completion.
+ * This function should be paired with object_unref() to free the resources
* associated with the object.
*
* Returns: The newly allocated and instantiated object.
@@ -436,15 +438,6 @@ Object *object_new(const char *typename);
Object *object_new_with_type(Type type);
/**
- * object_delete:
- * @obj: The object to free.
- *
- * Finalize an object and then free the memory associated with it.
This should
- * be paired with object_new() to free the resources associated with an
object.
- */
-void object_delete(Object *obj);
-
-/**
* object_initialize_with_type:
* @obj: A pointer to the memory to be used for the object.
* @type: The type of the object to instantiate.
@@ -573,8 +566,10 @@ void object_ref(Object *obj);
* qdef_unref:
* @obj: the object
*
- * Decrease the reference count of a object. A object cannot be freed
as long
+ * Decrease the reference count of a object. A object is not freed as long
* as its reference count is greater than zero.
+ * Once an object's reference count gets to zero (0),
+ * the object is finalized and the memory associated with it is freed.
*/
void object_unref(Object *obj);
diff --git a/qom/object.c b/qom/object.c
index 0cbd9bb..2de6eaf 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -328,7 +328,7 @@ static void object_deinit(Object *obj, TypeImpl *type)
while (obj->interfaces) {
Interface *iface_obj = obj->interfaces->data;
obj->interfaces = g_slist_delete_link(obj->interfaces,
obj->interfaces);
- object_delete(OBJECT(iface_obj));
+ object_unref(OBJECT(iface_obj));
}
if (type_has_parent(type)) {
@@ -369,13 +369,6 @@ Object *object_new(const char *typename)
return object_new_with_type(ti);
}
-void object_delete(Object *obj)
-{
- object_unref(obj);
- g_assert(obj->ref == 0);
- g_free(obj);
-}
-
static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
{
assert(target_type);
@@ -583,6 +576,7 @@ void object_unref(Object *obj)
/* parent always holds a reference to its children */
if (obj->ref == 0) {
object_finalize(obj);
+ g_free(obj);
}
}
WARNING: multiple messages have this Message-ID (diff)
From: Alexander Barabash <alexander_barabash@mentor.com>
To: qemu-trivial@nongnu.org, qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH] [TRIVIAL] Replace object_delete() with object_unref().
Date: Thu, 16 Feb 2012 19:38:46 +0200 [thread overview]
Message-ID: <4F3D3F26.8010402@mentor.com> (raw)
Replace object_delete() with object_unref().
In the existing implementation, object_delete()
calls object_unref(), then frees the object's storage.
Running object_delete() on an object with reference count
different from one (1) causes program failure.
In the existing implementation, object_unref()
finalizes the object when its reference count becomes zero (0).
In the new implementation, object_unref()
finalizes and frees the object's storage when the reference count
becomes zero (0).
One usage of object_delete() replaced by object_unref().
Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com>
diff --git a/hw/qdev.c b/hw/qdev.c
index f0eb3a7..891981a 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -247,7 +247,7 @@ void qdev_init_nofail(DeviceState *dev)
/* Unlink device from bus and free the structure. */
void qdev_free(DeviceState *dev)
{
- object_delete(OBJECT(dev));
+ object_unref(OBJECT(dev));
}
void qdev_machine_creation_done(void)
diff --git a/include/qemu/object.h b/include/qemu/object.h
index 69cc2ab..e7e32fe 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -415,8 +415,9 @@ struct InterfaceInfo
* object_new:
* @typename: The name of the type of the object to instantiate.
*
- * This function will initialize a new object using heap allocated
memory. This
- * function should be paired with object_delete() to free the resources
+ * This function will initialize a new object using heap allocated memory.
+ * The object's reference count will be set to one (1) upon successful
completion.
+ * This function should be paired with object_unref() to free the resources
* associated with the object.
*
* Returns: The newly allocated and instantiated object.
@@ -427,8 +428,9 @@ Object *object_new(const char *typename);
* object_new_with_type:
* @type: The type of the object to instantiate.
*
- * This function will initialize a new object using heap allocated
memory. This
- * function should be paired with object_delete() to free the resources
+ * This function will initialize a new object using heap allocated memory.
+ * The object's reference count will be set to one (1) upon successful
completion.
+ * This function should be paired with object_unref() to free the resources
* associated with the object.
*
* Returns: The newly allocated and instantiated object.
@@ -436,15 +438,6 @@ Object *object_new(const char *typename);
Object *object_new_with_type(Type type);
/**
- * object_delete:
- * @obj: The object to free.
- *
- * Finalize an object and then free the memory associated with it.
This should
- * be paired with object_new() to free the resources associated with an
object.
- */
-void object_delete(Object *obj);
-
-/**
* object_initialize_with_type:
* @obj: A pointer to the memory to be used for the object.
* @type: The type of the object to instantiate.
@@ -573,8 +566,10 @@ void object_ref(Object *obj);
* qdef_unref:
* @obj: the object
*
- * Decrease the reference count of a object. A object cannot be freed
as long
+ * Decrease the reference count of a object. A object is not freed as long
* as its reference count is greater than zero.
+ * Once an object's reference count gets to zero (0),
+ * the object is finalized and the memory associated with it is freed.
*/
void object_unref(Object *obj);
diff --git a/qom/object.c b/qom/object.c
index 0cbd9bb..2de6eaf 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -328,7 +328,7 @@ static void object_deinit(Object *obj, TypeImpl *type)
while (obj->interfaces) {
Interface *iface_obj = obj->interfaces->data;
obj->interfaces = g_slist_delete_link(obj->interfaces,
obj->interfaces);
- object_delete(OBJECT(iface_obj));
+ object_unref(OBJECT(iface_obj));
}
if (type_has_parent(type)) {
@@ -369,13 +369,6 @@ Object *object_new(const char *typename)
return object_new_with_type(ti);
}
-void object_delete(Object *obj)
-{
- object_unref(obj);
- g_assert(obj->ref == 0);
- g_free(obj);
-}
-
static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
{
assert(target_type);
@@ -583,6 +576,7 @@ void object_unref(Object *obj)
/* parent always holds a reference to its children */
if (obj->ref == 0) {
object_finalize(obj);
+ g_free(obj);
}
}
next reply other threads:[~2012-02-16 17:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-16 17:38 Alexander Barabash [this message]
2012-02-16 17:38 ` [Qemu-devel] [PATCH] [TRIVIAL] Replace object_delete() with object_unref() Alexander Barabash
2012-02-16 18:12 ` [Qemu-trivial] " Peter Maydell
2012-02-16 18:12 ` Peter Maydell
2012-02-17 10:57 ` [Qemu-trivial] " Stefan Hajnoczi
2012-02-17 10:57 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F3D3F26.8010402@mentor.com \
--to=alexander_barabash@mentor.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.