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 729554 - Incorrect JS types in callback signatures cause testsuite and gnome-shell crashes on some architectures
Incorrect JS types in callback signatures cause testsuite and gnome-shell cra...
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
1.40.x
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2014-05-05 09:06 UTC by Michel Dänzer
Modified: 2014-08-27 01:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix JS types in callback signatures (29.72 KB, patch)
2014-05-05 09:06 UTC, Michel Dänzer
none Details | Review
Patch against master (30.04 KB, patch)
2014-05-05 09:12 UTC, Michel Dänzer
needs-work Details | Review
[PATCH v2 master] Fix JS types in callback signatures (30.03 KB, patch)
2014-05-12 06:45 UTC, Michel Dänzer
none Details | Review
[PATCH v2 gnome-3-12] Fix JS types in callback signatures (29.71 KB, patch)
2014-05-12 06:46 UTC, Michel Dänzer
none Details | Review
Fix JS types in more callback signatures (6.05 KB, patch)
2014-08-23 04:18 UTC, Michel Dänzer
none Details | Review

Description Michel Dänzer 2014-05-05 09:06:06 UTC
Created attachment 275875 [details] [review]
Fix JS types in callback signatures

After upgrading my PowerBook to gnome-shell 3.12 / gjs 1.40 / mozjs24, gnome-shell and a lot of gjs tests crashed.

After a lot of head scratching (for a good part of what was supposed to be a long weekend), I noticed that the *_new_resolve callbacks didn't use the same addresses for JS objects as the JS code calling them. This turned out to be due to the callback signatures using the wrong JS types.

The attached patch fixes this for the gnome-3-12 branch. It allows me to run gnome-shell and fixes the gjs testsuite[0].

[0] Up to commit d6078d7786c43b2e0fbf551e686be6175810c333, which introduces a failure of the GIMarshalling test for reasons I don't understand yet. But I can still run gnome-shell with the 1.40.1 release plus this patch.
Comment 1 Michel Dänzer 2014-05-05 09:12:03 UTC
Created attachment 275876 [details] [review]
Patch against master
Comment 2 Giovanni Campagna 2014-05-05 14:41:14 UTC
Review of attachment 275876 [details] [review]:

Same comments on pretty much all files, only repeating them once.

::: gjs/importer.cpp
@@ -867,3 @@
 
-    *objp = NULL;
-

This should be replaced with objp.set(0), not removed.

@@ +882,1 @@
+    gjs_debug_jsprop(GJS_DEBUG_IMPORTER, "Resolve prop '%s' hook obj %p priv %p", name, obj, priv);

Here we want the object, not the handle (which I'm not even sure how it gets promoted to varargs), so *obj is correct.
Comment 3 Michel Dänzer 2014-05-07 10:01:48 UTC
(In reply to comment #2)
> ::: gjs/importer.cpp
> @@ -867,3 @@
> 
> -    *objp = NULL;
> -
> 
> This should be replaced with objp.set(0), not removed.

From the jsapi.h comment about the JSNewResolveOp hook:

 * [...] The hook may assume *objp is null on entry.

So setting it to NULL in the hook is a no-op.


> @@ +882,1 @@
> +    gjs_debug_jsprop(GJS_DEBUG_IMPORTER, "Resolve prop '%s' hook obj %p priv
> %p", name, obj, priv);
> 
> Here we want the object, not the handle (which I'm not even sure how it gets
> promoted to varargs), so *obj is correct.

Thanks, I'll attach new patches with that fixed, hopefully tomorrow.
Comment 4 Michel Dänzer 2014-05-12 06:45:11 UTC
Created attachment 276359 [details] [review]
[PATCH v2 master] Fix JS types in callback signatures

v2: Don't change gjs_debug_jsprop() lines.
Comment 5 Michel Dänzer 2014-05-12 06:46:08 UTC
Created attachment 276360 [details] [review]
[PATCH v2 gnome-3-12] Fix JS types in callback signatures
Comment 6 Michel Dänzer 2014-05-12 06:46:43 UTC
BTW, I didn't check for similar problems with other hooks.
Comment 7 Michel Dänzer 2014-08-23 02:17:47 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > ::: gjs/importer.cpp
> > @@ -867,3 @@
> > 
> > -    *objp = NULL;
> > -
> > 
> > This should be replaced with objp.set(0), not removed.
> 
> From the jsapi.h comment about the JSNewResolveOp hook:
> 
>  * [...] The hook may assume *objp is null on entry.
> 
> So setting it to NULL in the hook is a no-op.

Are you insisting on this anyway, or why hasn't the fix been applied after over three months?
Comment 8 Jasper St. Pierre (not reading bugmail) 2014-08-23 02:36:20 UTC
Nah, it's just that we forgot more than anything. Pushed now, thanks for the patch.
Comment 9 Michel Dänzer 2014-08-23 04:18:39 UTC
Created attachment 284275 [details] [review]
Fix JS types in more callback signatures

This patch fixes more instances of the same problem which have crept in in the meantime.
Comment 10 Michel Dänzer 2014-08-23 04:28:01 UTC
Thanks, please push the followup patch I just attached as well.

Basically, whenever a JS callback assignment needs a cast to (JS*Op), the callback signature needs to be checked carefully against the definition in jsapi.h. Please keep this in mind.

The GIMarshalling test still fails for me, no idea why yet:

Gjs-Message: JS LOG: running test testCArray
Gjs-Message: JS LOG: running test testGArray
Gjs-Message: JS LOG: running test testByteArray
Gjs-Message: JS LOG: running test testGBytes
Gjs-Message: JS LOG: running test testPtrArray
Gjs-Message: JS LOG: running test testGValue
Gjs-Message: JS LOG: running test testGType
Gjs-Message: JS WARNING: [testGIMarshalling.js 246]: "name" is read-only
Gjs-Message: JS LOG: running test testGTypePrototype
Gjs-Message: JS LOG: running test testGValueGType
Gjs-Message: JS LOG: running test testCallbacks
Gjs-Message: JS LOG: running test testVFuncs
Gjs-Message: JS LOG: running test testInterfaces

(lt-gjs-console:16404): Gjs-WARNING **: JS ERROR: TypeError: GIMarshallingTests.InterfaceImpl is not a constructor
testInterfaces@testGIMarshalling.js:405
gjstestRun@resource:///org/gnome/gjs/modules/jsUnit.js:438
gjstestRun@testGIMarshalling.js:3
@testGIMarshalling.js:411

JS_EvaluateScript() failed
Comment 11 Jasper St. Pierre (not reading bugmail) 2014-08-25 19:36:10 UTC
Pushed this one too.
Comment 12 darkxst 2014-08-27 01:29:48 UTC
Michel, that test failure is caused by a missing g-i patch

https://git.gnome.org/browse/gobject-introspection/commit/?h=gnome-3-12&id=21e51026d74bca48b814ace73eb588e6542a27cd