JS CTypes prints function types incorrectly

RESOLVED FIXED in mozilla13

Status

()

defect
RESOLVED FIXED
8 years ago
8 years ago

People

(Reporter: jimb, Assigned: jimb)

Tracking

Trunk
mozilla13
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 2 obsolete attachments)

CTypes prints function types incorrectly. For example:

js> ctypes.FunctionType(ctypes.default_abi, ctypes.int).toString()
"type int()()"
js> 

It should return "type int()".
Attachment #594054 - Flags: review?(jones.chris.g)
Flags: in-testsuite+
I thought Chris had helped work on CTypes, and thus r?'d him; if that's not correct, apologies; who is best?
Attachment #594054 - Flags: review?(jones.chris.g) → review?(bobbyholley+bmo)
Comment on attachment 594054 [details] [diff] [review]
Make JavaScript CTypes print function types correctly.

>-      // Wrap the entire expression so far with parens.
>-      PrependString(result, "(");
>-      AppendString(result, ")");
>+      // Function application binds more tightly than dereferencing, so
>+      // wrap pointer types in parens.
>+      if (prevGrouping == TYPE_pointer) {
>+        PrependString(result, "(");
>+        AppendString(result, ")");
>+      }

Good catch. :-)

Could be worth making a note here that pointers are the only modifiers that can directly wrap functions (since you can't have arrays of functions or functions returning functions), so the only thing we're guarding against here is function types as the outermost modifier. But it's not super crucial.


>diff --git a/js/src/jit-test/tests/basic/CTypes-toString.js b/js/src/jit-test/tests/basic/CTypes-toString.js

Awesome tests! These should go in toolkit/components/ctypes/tests though.

r=bholley with the tests moved.
Attachment #594054 - Flags: review?(bobbyholley+bmo) → review+
Revised per bholley's review comments.
Attachment #594054 - Attachment is obsolete: true
Backed out due to test failures on all Windows boxes in test_ctypes.js and test_ctypes.xul.

Fwiw, Try didn't really look good ;)
(In reply to Marco Bonardo [:mak] from comment #6)
> Fwiw, Try didn't really look good ;)

I suck. Thanks, Marco.
Revised to fix Win32 tests (bad spacing for __stdcall and WINAPI qualifiers).
Attachment #594854 - Attachment is obsolete: true
(In reply to Jim Blandy :jimb from comment #9)
> New try run: https://tbpl.mozilla.org/?tree=Try&rev=c327706ed342

That showed up some more xpcshell test failures. This one is clean:
https://tbpl.mozilla.org/?tree=Try&rev=cc27c2c3fa1a
https://hg.mozilla.org/mozilla-central/rev/f80c406b902a
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.