RESOLVED FIXED 95242
objc_msgSend and IMP should be cast appropriately before using
https://bugs.webkit.org/show_bug.cgi?id=95242
Summary objc_msgSend and IMP should be cast appropriately before using
Pratik Solanki
Reported 2012-08-28 14:08:42 PDT
Future compilers/runtimes will warn if we try to use objc_msgSend without the correct casts. We should add casts in WebKit/WebCore when we call objc_msgSend or IMP.
Attachments
Patch (23.91 KB, patch)
2012-08-28 14:25 PDT, Pratik Solanki
no flags
Patch (29.12 KB, patch)
2012-08-29 10:29 PDT, Pratik Solanki
no flags
Patch (34.56 KB, patch)
2012-08-30 11:33 PDT, Pratik Solanki
no flags
Fix for llvm-gcc (21.78 KB, patch)
2012-08-31 12:37 PDT, Pratik Solanki
no flags
Patch (1.36 KB, patch)
2012-08-31 13:41 PDT, Pratik Solanki
benjamin: review+
Pratik Solanki
Comment 1 2012-08-28 14:09:01 PDT
Pratik Solanki
Comment 2 2012-08-28 14:25:46 PDT
Benjamin Poulain
Comment 3 2012-08-28 14:54:42 PDT
Comment on attachment 161060 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=161060&action=review > Source/WebKit/mac/WebView/WebDelegateImplementationCaching.mm:87 > - return objc_msgSend(delegate, selector, self); > + return reinterpret_cast<id (*)(id, SEL, id)>(objc_msgSend)(delegate, selector, self); What about making a bunch of webkit_objc_msgSend like this?: template<typename Arg1Type, typename Arg2Type> id webkit_objc_msgSend(id target, SEL selector, Arg1Type arg1, Arg2Type arg2) { return reinterpret_cast<id (*)(id, SEL, Arg1Type, Arg2Type)>(objc_msgSend)(target, selector, arg1, arg2); }
Benjamin Poulain
Comment 4 2012-08-28 16:03:13 PDT
Maybe we should also modify the style checker to prevent bare use of objc_msgSend?
Benjamin Poulain
Comment 5 2012-08-28 22:33:08 PDT
Comment on attachment 161060 [details] Patch Clearing the review flag, Pratik has an update.
Pratik Solanki
Comment 6 2012-08-29 10:29:18 PDT
Pratik Solanki
Comment 7 2012-08-29 10:30:46 PDT
(In reply to comment #3) > (From update of attachment 161060 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=161060&action=review > > > Source/WebKit/mac/WebView/WebDelegateImplementationCaching.mm:87 > > - return objc_msgSend(delegate, selector, self); > > + return reinterpret_cast<id (*)(id, SEL, id)>(objc_msgSend)(delegate, selector, self); > > What about making a bunch of webkit_objc_msgSend like this?: > template<typename Arg1Type, typename Arg2Type> > id webkit_objc_msgSend(id target, SEL selector, Arg1Type arg1, Arg2Type arg2) > { > return reinterpret_cast<id (*)(id, SEL, Arg1Type, Arg2Type)>(objc_msgSend)(target, selector, arg1, arg2); > } This was a great idea. New patch uploaded with this template code.
David Kilzer (:ddkilzer)
Comment 8 2012-08-29 12:49:42 PDT
Comment on attachment 161264 [details] Patch r=me
Benjamin Poulain
Comment 9 2012-08-29 13:56:42 PDT
Comment on attachment 161264 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=161264&action=review > Source/WebKit/mac/WebView/WebDelegateImplementationCaching.mm:86 > > +template<typename Arg1Type> > +id webkit_objc_msgSend(id target, SEL selector, Arg1Type arg1) > +{ > + return reinterpret_cast<id (*)(id, SEL, Arg1Type)>(objc_msgSend)(target, selector, arg1); > +} I would put the templates in a new header in WTF. Then I would ban the use of objc_msgSend through the style checker. I am afraid new code with objc_msgSend might come without the reviewer knowing about this change.
Alexey Proskuryakov
Comment 10 2012-08-29 14:20:25 PDT
This template is limited in what it can do - specifically, it assumes that the functions returns an id.
WebKit Review Bot
Comment 11 2012-08-29 18:56:59 PDT
Comment on attachment 161264 [details] Patch Attachment 161264 [details] did not pass chromium-ews (chromium-xvfb): Output: http://queues.webkit.org/results/13686455 New failing tests: CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread
Pratik Solanki
Comment 12 2012-08-30 10:33:30 PDT
How did this fail? Searching for CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread on the log linked to above, I see [----------] 1 test from CCLayerTreeHostTestAtomicCommitWithPartialUpdate [ RUN ] CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread [ OK ] CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread (120 ms) [----------] 1 test from CCLayerTreeHostTestAtomicCommitWithPartialUpdate (120 ms total) What failed?
Benjamin Poulain
Comment 13 2012-08-30 10:41:06 PDT
(In reply to comment #12) > How did this fail? Searching for CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread on the log linked to above, I see > > [----------] 1 test from CCLayerTreeHostTestAtomicCommitWithPartialUpdate > [ RUN ] CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread > [ OK ] CCLayerTreeHostTestAtomicCommitWithPartialUpdate.runMultiThread (120 ms) > [----------] 1 test from CCLayerTreeHostTestAtomicCommitWithPartialUpdate (120 ms total) > > What failed? It is likely a sick bot. You patch does not touch anything on Linux.
Pratik Solanki
Comment 14 2012-08-30 11:33:34 PDT
Benjamin Poulain
Comment 15 2012-08-30 12:14:50 PDT
Comment on attachment 161524 [details] Patch Very nice!
Pratik Solanki
Comment 16 2012-08-30 14:40:49 PDT
Pratik Solanki
Comment 17 2012-08-31 10:18:39 PDT
Looks like llvm-gcc doesn't like my patch. From <http://webkit-commit-queue.appspot.com/results/13724238> In file included from /Volumes/Data/WebKit/Source/WebCore/page/mac/EventHandlerMac.mm:53: /Volumes/Data/WebKit/WebKitBuild/Release/usr/local/include/wtf/ObjcRuntimeExtras.h:29: error: default template arguments may not be used in function templates /Volumes/Data/WebKit/WebKitBuild/Release/usr/local/include/wtf/ObjcRuntimeExtras.h:35: error: no default argument for 'Arg1Type' /Volumes/Data/WebKit/WebKitBuild/Release/usr/local/include/wtf/ObjcRuntimeExtras.h:35: error: default template arguments may not be used in function templates .... and more such errors like this. I'm looking into it.
Pratik Solanki
Comment 18 2012-08-31 10:56:27 PDT
Ok. I can reproduce the build failure by switching to llvm-gcc-4.2 on Mountain Lion (and removing a few -W arguments to the compiler). The template format is template<typename RetType = id, typename Arg1Type> RetType wtfObjcMsgSend(id target, SEL selector, Arg1Type arg1) { return reinterpret_cast<RetType (*)(id, SEL, Arg1Type)>(objc_msgSend)(target, selector, arg1); } If I remove the " = id" part, it's happy. I could do that. And then have each call site explicitly specify the return type. Alternatively, what are the chances we can get the EWS bot updated with a more recent toolchain?
Benjamin Poulain
Comment 19 2012-08-31 11:50:52 PDT
> If I remove the " = id" part, it's happy. I could do that. And then have each call site explicitly specify the return type. Alternatively, what are the chances we can get the EWS bot updated with a more recent toolchain? I am afraid we have to support the old compilers. If the EWS have an old SDK, chances are many people do too. I think the best is add an explanation in a FIXME and remove the default arg :( :(
Jessie Berlin
Comment 20 2012-08-31 12:04:43 PDT
(In reply to comment #19) > > If I remove the " = id" part, it's happy. I could do that. And then have each call site explicitly specify the return type. Alternatively, what are the chances we can get the EWS bot updated with a more recent toolchain? > > I am afraid we have to support the old compilers. > If the EWS have an old SDK, chances are many people do too. > > I think the best is add an explanation in a FIXME and remove the default arg :( :( I agree with Benjamin. Please either do that soon or roll out http://trac.webkit.org/changeset/127193 (it is causing the mac-ews queue to get clogged).
Pratik Solanki
Comment 21 2012-08-31 12:06:32 PDT
Working on this now. I should have a patch soon.
Pratik Solanki
Comment 22 2012-08-31 12:37:03 PDT
Reopening to attach new patch.
Pratik Solanki
Comment 23 2012-08-31 12:37:06 PDT
Created attachment 161752 [details] Fix for llvm-gcc
Benjamin Poulain
Comment 24 2012-08-31 12:41:18 PDT
Comment on attachment 161752 [details] Fix for llvm-gcc Looks good. I think we should land this so we can take the EWS back online for everyone. Then we fix the EWS and we can eventually revert the patch.
Pratik Solanki
Comment 25 2012-08-31 13:11:40 PDT
Pratik Solanki
Comment 26 2012-08-31 13:41:55 PDT
Reopening to attach new patch.
Pratik Solanki
Comment 27 2012-08-31 13:41:57 PDT
Benjamin Poulain
Comment 28 2012-08-31 13:45:24 PDT
Comment on attachment 161762 [details] Patch Damn GCC.
Pratik Solanki
Comment 29 2012-08-31 13:48:23 PDT
Note You need to log in before you can comment on or make changes to this bug.