GNOME Bugzilla – Bug 687184
Invalid instance size when inheriting from JS object
Last modified: 2012-11-16 14:36:16 UTC
Created attachment 227623 [details] bug.js See the trivial example attached. Most of the time it executes all fine, but sometimes it raises this error: (gjs:4693): GLib-GObject-WARNING **: specified instance size for type `Gjs_Mushroom' is smaller than `GTypeInstance' size The good thing is that error is almost always reproducible using valgrind: GJS_PATH=$(pwd) G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --tool=memcheck gjs ./bug.js ==6524== Conditional jump or move depends on uninitialised value(s) ==6524== at 0x56A75BF: check_type_info_I (gtype.c:904) ==6524== by 0x56A83DC: type_data_ref_Wm (gtype.c:1220) ==6524== by 0x56AC24A: g_type_class_ref (gtype.c:2914) ==6524== by 0x4C43413: gjs_define_object_class (object.c:1745) ==6524== by 0x4C4484A: ??? (object.c:2324) ==6524== by 0x3980ACB945: js::Interpret(JSContext*, JSStackFrame*, unsigned int, JSInterpMode) (jscntxtinlines.h:701) ==6524== by 0x3980AD56BE: js::RunScript(JSContext*, JSScript*, JSStackFrame*) (jsinterp.cpp:653) ==6524== by 0x3980AD7631: js::Invoke(JSContext*, js::CallArgs const&, unsigned int) (jsinterp.cpp:740) ==6524== by 0x3980AAB75C: js_fun_apply(JSContext*, unsigned int, js::Value*) (jsfun.cpp:2205) ==6524== by 0x3980ACB945: js::Interpret(JSContext*, JSStackFrame*, unsigned int, JSInterpMode) (jscntxtinlines.h:701) ==6524== by 0x3980AD56BE: js::RunScript(JSContext*, JSScript*, JSStackFrame*) (jsinterp.cpp:653) ==6524== by 0x3980AD7631: js::Invoke(JSContext*, js::CallArgs const&, unsigned int) (jsinterp.cpp:740) ==6524== ==6524== Conditional jump or move depends on uninitialised value(s) ==6524== at 0x56A760C: check_type_info_I (gtype.c:910) ==6524== by 0x56A83DC: type_data_ref_Wm (gtype.c:1220) ==6524== by 0x56AC24A: g_type_class_ref (gtype.c:2914) ==6524== by 0x4C43413: gjs_define_object_class (object.c:1745) ==6524== by 0x4C4484A: ??? (object.c:2324) ==6524== by 0x3980ACB945: js::Interpret(JSContext*, JSStackFrame*, unsigned int, JSInterpMode) (jscntxtinlines.h:701) ==6524== by 0x3980AD56BE: js::RunScript(JSContext*, JSScript*, JSStackFrame*) (jsinterp.cpp:653) ==6524== by 0x3980AD7631: js::Invoke(JSContext*, js::CallArgs const&, unsigned int) (jsinterp.cpp:740) ==6524== by 0x3980AAB75C: js_fun_apply(JSContext*, unsigned int, js::Value*) (jsfun.cpp:2205) ==6524== by 0x3980ACB945: js::Interpret(JSContext*, JSStackFrame*, unsigned int, JSInterpMode) (jscntxtinlines.h:701) ==6524== by 0x3980AD56BE: js::RunScript(JSContext*, JSScript*, JSStackFrame*) (jsinterp.cpp:653) ==6524== by 0x3980AD7631: js::Invoke(JSContext*, js::CallArgs const&, unsigned int) (jsinterp.cpp:740) ==6524== ==6524== Conditional jump or move depends on uninitialised value(s) ==6524== at 0x56A766D: check_type_info_I (gtype.c:922) ==6524== by 0x56A83DC: type_data_ref_Wm (gtype.c:1220) ==6524== by 0x56AC24A: g_type_class_ref (gtype.c:2914) ==6524== by 0x4C43413: gjs_define_object_class (object.c:1745) ==6524== by 0x4C4484A: ??? (object.c:2324) ==6524== by 0x3980ACB945: js::Interpret(JSContext*, JSStackFrame*, unsigned int, JSInterpMode) (jscntxtinlines.h:701) ==6524== by 0x3980AD56BE: js::RunScript(JSContext*, JSScript*, JSStackFrame*) (jsinterp.cpp:653) ==6524== by 0x3980AD7631: js::Invoke(JSContext*, js::CallArgs const&, unsigned int) (jsinterp.cpp:740) ==6524== by 0x3980AAB75C: js_fun_apply(JSContext*, unsigned int, js::Value*) (jsfun.cpp:2205) ==6524== by 0x3980ACB945: js::Interpret(JSContext*, JSStackFrame*, unsigned int, JSInterpMode) (jscntxtinlines.h:701) ==6524== by 0x3980AD56BE: js::RunScript(JSContext*, JSScript*, JSStackFrame*) (jsinterp.cpp:653) ==6524== by 0x3980AD7631: js::Invoke(JSContext*, js::CallArgs const&, unsigned int) (jsinterp.cpp:740) ==6524== (gjs:6524): GLib-GObject-WARNING **: specified instance size for type `Gjs_Mushroom' is smaller than `GTypeInstance' size I did some digging and it looks like info->class_size is invalid and so doesn't contain a meaningfull size.
Ugh. The problem is that the GType system doesn't allow g_type_query() for dynamic types. We need to revert back to static types (and work around the tests failing at context destruction), or workaround by querying the first non gjs ancestor.
Created attachment 227649 [details] [review] Gjs: work around GType bug with dynamic types g_type_query() only works with static types, so it fails when inheriting from another JS class. Work around that by using the first static parent for GJS custom type (as we never override the instance or class type)
Review of attachment 227649 [details] [review]: One really minor comment, otherwise looks good to commit. ::: gi/object.c @@ +870,3 @@ +static void +g_type_query_dynamic_safe (GType type, This function could really use a comment. Just a link to to this bug at least.
Attachment 227649 [details] pushed as d2f67b7 - Gjs: work around GType bug with dynamic types
*** Bug 688433 has been marked as a duplicate of this bug. ***