Closed Bug 723806 Opened 11 years ago Closed 11 years ago

JS CTypes prints function types incorrectly


(Core :: js-ctypes, defect)

Not set





(Reporter: jimb, Assigned: jimb)



(1 file, 2 obsolete files)

CTypes prints function types incorrectly. For example:

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

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:

That showed up some more xpcshell test failures. This one is clean:
Closed: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.