After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 687184 - Invalid instance size when inheriting from JS object
Invalid instance size when inheriting from JS object
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal major
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2012-10-30 10:37 UTC by Guillaume Desmottes
Modified: 2012-11-16 14:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
bug.js (414 bytes, application/javascript)
2012-10-30 10:37 UTC, Guillaume Desmottes
  Details
Gjs: work around GType bug with dynamic types (2.81 KB, patch)
2012-10-30 16:00 UTC, Giovanni Campagna
committed Details | Review

Description Guillaume Desmottes 2012-10-30 10:37:26 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.
Comment 1 Giovanni Campagna 2012-10-30 15:48:53 UTC
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.
Comment 2 Giovanni Campagna 2012-10-30 16:00:51 UTC
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)
Comment 3 Colin Walters 2012-10-30 16:12:52 UTC
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.
Comment 4 Giovanni Campagna 2012-10-30 16:23:19 UTC
Attachment 227649 [details] pushed as d2f67b7 - Gjs: work around GType bug with dynamic types
Comment 5 Giovanni Campagna 2012-11-16 14:36:16 UTC
*** Bug 688433 has been marked as a duplicate of this bug. ***