On 05/31/2012 11:34 AM, Igor Mitsyanko wrote:
On 05/31/2012 12:11 PM, Igor Mammedov wrote:
On 05/30/2012 07:05 PM, Igor Mitsyanko wrote:
On 05/30/2012 08:19 PM, Igor Mammedov wrote:
without assert it will crash at following point:
OBJECT_CHECK(type, obj, name) \
((type *)object_dynamic_cast_assert(OBJECT(obj), (name)))
=> object_dynamic_cast(obj, typename)
=> object_is_type(obj, target_type)
=> type_is_ancestor(obj->class->type, target_type);
^^^
so abort earlier and print nice message instead of SIGSEGV

Signed-off-by: Igor Mammedov<imamm...@redhat.com>
---
qom/object.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 00bb3b0..444e2fc 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -481,6 +481,8 @@ Object *object_dynamic_cast_assert(Object *obj,
const char *typename)
{
Object *inst;

+ g_assert(obj != NULL);
+
inst = object_dynamic_cast(obj, typename);

if (!inst) {
Makes much sense, but maybe it should be done in OBJECT() cast? Assert
when we do OBJECT(NULL).
sort grep shows that no one is casting NULLs to anything, what's the point?

No one passing NULL to OBJECT_CHECK() either, what I'm talking about is cases 
when we cast some variable foo to Object * with OBJECT(foo) when foo ==
NULL. But Markus thinks that its OK to do that, perhaps he's right, asserting 
will impose unnecessary restrictions on developers.

Ah I see, I've got confused, sorry.

--
-----
 Igor

Reply via email to