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 611529 - functions with out arguments have wrong argument indexing
functions with out arguments have wrong argument indexing
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2010-03-01 21:58 UTC by Johan Bilien
Modified: 2010-03-01 22:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gi: Do not increment argument counter for OUT arguments (870 bytes, patch)
2010-03-01 22:01 UTC, Johan Bilien
accepted-commit_now Details | Review
Add a test function with an out argument and some other after that (2.40 KB, patch)
2010-03-01 22:33 UTC, Johan Bilien
accepted-commit_now Details | Review
test: Add a (failing) test with an "out" argument followed by another (1010 bytes, patch)
2010-03-01 22:36 UTC, Johan Bilien
committed Details | Review
gi: Do not increment argument counter for OUT arguments (1.46 KB, patch)
2010-03-01 22:36 UTC, Johan Bilien
committed Details | Review

Description Johan Bilien 2010-03-01 21:58:59 UTC
Functions with "out" arguments lead to an of by one error in the arguments following arguments.

I believe the problem is that the index pointing to the arguments passed to JavaScript is incremented even if the function argument is 'out', though in that case the argument should not have been passed to JS.

We found this out with g_file_replace_contents, where the cancellable argument gets passed a value at argv[argc].
Comment 1 Johan Bilien 2010-03-01 22:01:50 UTC
Created attachment 154980 [details] [review]
gi: Do not increment argument counter for OUT arguments

OUT arguments are not passed in JS, so do not increment the index in the
argv array when dealing with an OUT argument.
Comment 2 Havoc Pennington 2010-03-01 22:10:15 UTC
Review of attachment 154980 [details] [review]:

Looks correct
Comment 3 Johan (not receiving bugmail) Dahlin 2010-03-01 22:15:51 UTC
Ideally we should add a test here, can you do that Johan?
Comment 4 Johan Bilien 2010-03-01 22:21:50 UTC
(In reply to comment #3)
> Ideally we should add a test here, can you do that Johan?

Will do
Comment 5 Tommi Komulainen 2010-03-01 22:24:40 UTC
Review of attachment 154980 [details] [review]:

::: gi/function.c
@@ +632,1 @@
         ++in_args_pos;

shouldn't this be moved as well? (based on name it has similar semantics and is relevant only for in arguments...)
Comment 6 Tommi Komulainen 2010-03-01 22:31:23 UTC
Also, maybe adding asserts for argv_pos < argc and in_args_pos and friends might be in order so that suchs out of bounds accesses don't go silently unnoticed.
Comment 7 Johan Bilien 2010-03-01 22:33:19 UTC
Created attachment 154981 [details] [review]
Add a test function with an out argument and some other after that

Useful to debug case
Comment 8 Johan Bilien 2010-03-01 22:36:48 UTC
Created attachment 154982 [details] [review]
test: Add a (failing) test with an "out" argument followed by another
Comment 9 Johan Bilien 2010-03-01 22:36:51 UTC
Created attachment 154983 [details] [review]
gi: Do not increment argument counter for OUT arguments

OUT arguments are not passed in JS, so do not increment the index in the
argv array when dealing with an OUT argument.
Comment 10 Johan Bilien 2010-03-01 22:42:49 UTC
(In reply to comment #5)
> Review of attachment 154980 [details] [review]:
> 
> ::: gi/function.c
> @@ +632,1 @@
>          ++in_args_pos;
> 
> shouldn't this be moved as well? (based on name it has similar semantics and is
> relevant only for in arguments...)

in_args_pos seems to be an index in in_arg_cvalues, which has one item per argument to the C function, not the JS one. So it seems correct to increment it even for 'out' arguments