Bug 59470

Summary: Prohibit the use of OwnPtr<T*>
Product: WebKit Reporter: Adrienne Walker <enne>
Component: New BugsAssignee: Adrienne Walker <enne>
Status: RESOLVED WONTFIX    
Severity: Normal CC: abarth, buildbot, dglazkov, enne, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Other   
OS: OS X 10.5   
Bug Depends on: 59469, 59489, 59559    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Adrienne Walker
Reported 2011-04-26 11:03:38 PDT
Prohibit the use of OwnPtr<T*>
Attachments
Patch (2.64 KB, patch)
2011-04-26 11:04 PDT, Adrienne Walker
no flags
Patch (2.56 KB, patch)
2011-04-26 12:13 PDT, Adrienne Walker
no flags
Patch (2.56 KB, patch)
2011-04-26 16:23 PDT, Adrienne Walker
no flags
Adrienne Walker
Comment 1 2011-04-26 11:04:47 PDT
Adrienne Walker
Comment 2 2011-04-26 11:09:51 PDT
There may be some better way to implement this, but I think it would be an excellent idea to prevent somebody accidentally using OwnPtr<T*> when they intended OwnPtr<T>. I can't think of any usage for the former. (Also, I'm a little unsure of who to CC on this bug, so please add others.)
WebKit Review Bot
Comment 3 2011-04-26 11:26:49 PDT
Build Bot
Comment 4 2011-04-26 12:07:53 PDT
WebKit Review Bot
Comment 5 2011-04-26 12:11:43 PDT
Adrienne Walker
Comment 6 2011-04-26 12:13:51 PDT
Adrienne Walker
Comment 7 2011-04-26 12:14:30 PDT
Let's try this again now that the blocking bugfix has landed.
WebKit Review Bot
Comment 8 2011-04-26 12:57:47 PDT
Adrienne Walker
Comment 9 2011-04-26 13:23:57 PDT
Comment on attachment 91144 [details] Patch Oops. Need to touch up DRT as well.
WebKit Review Bot
Comment 10 2011-04-26 13:54:35 PDT
Build Bot
Comment 11 2011-04-26 14:01:35 PDT
WebKit Review Bot
Comment 12 2011-04-26 15:34:52 PDT
Adrienne Walker
Comment 13 2011-04-26 16:23:33 PDT
Adrienne Walker
Comment 14 2011-04-26 16:23:59 PDT
Third time's a charm for fixing all the build errors.
Geoffrey Garen
Comment 15 2011-04-26 16:59:51 PDT
Comment on attachment 91177 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=91177&action=review r=me > Source/JavaScriptCore/wtf/OwnPtr.h:179 > + template<typename T> class OwnPtr<T*> { > + // Prevent usage as a real OwnPtr by not defining any functions. > + }; > +#endif I believe you can do even better here by just using a declaration with no definition.
Adrienne Walker
Comment 16 2011-04-26 17:03:50 PDT
(In reply to comment #15) > (From update of attachment 91177 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=91177&action=review > > r=me Thanks for all the reviews today. :) > > Source/JavaScriptCore/wtf/OwnPtr.h:179 > > + template<typename T> class OwnPtr<T*> { > > + // Prevent usage as a real OwnPtr by not defining any functions. > > + }; > > +#endif > > I believe you can do even better here by just using a declaration with no definition. That would be cleaner. I'll do that before landing.
Build Bot
Comment 17 2011-04-26 17:05:00 PDT
Adrienne Walker
Comment 18 2011-04-26 17:25:08 PDT
(In reply to comment #16) > (In reply to comment #15) > > > Source/JavaScriptCore/wtf/OwnPtr.h:179 > > > + template<typename T> class OwnPtr<T*> { > > > + // Prevent usage as a real OwnPtr by not defining any functions. > > > + }; > > > +#endif > > > > I believe you can do even better here by just using a declaration with no definition. > > That would be cleaner. I'll do that before landing. After some study, I think an empty class rather than an incomplete declaration is better. If the class is incomplete, then it's harder to #ifdef out this error because every class that is-a or has-a class with an OwnPtr<T*> needs the ALLOW_RAW_POINTER_IN_OWNPTR define. Hopefully that should go away soon, but in the short term MediaPlayer.h is used in a number of places. Also, the error message points to OwnPtr.h in the former case where somebody might see the comment, but just says the slightly more obscure "incomplete declaration" in the latter.
WebKit Review Bot
Comment 19 2011-04-26 18:22:01 PDT
Adrienne Walker
Comment 20 2011-04-27 11:11:10 PDT
Oh, yuck. It looks like the Windows port is set up to handle OwnPtr<HBITMAP> (which is a void*), but has a deleteOwnPtr(HBITMAP) function which will properly clean up its resources. So, I can't disallow all OwnPtr<T*>, just all except any except the 10 or so port-specific pointer types listed in OwnPtrCommon.h. I'll have to take another look at this patch to account for that while still disallowing the general case.
Darin Adler
Comment 21 2011-06-18 12:46:21 PDT
Comment on attachment 91177 [details] Patch Clearing review flag because we need to rework this for Windows’ sake. Best possibility would probably be to change Windows to use to something other than OwnPtr. It’s not safe to have it using OwnPtr with void*!
Adrienne Walker
Comment 22 2011-06-20 09:41:40 PDT
(In reply to comment #21) > (From update of attachment 91177 [details]) > Clearing review flag because we need to rework this for Windows’ sake. Best possibility would probably be to change Windows to use to something other than OwnPtr. It’s not safe to have it using OwnPtr with void*! Ack. I thought I had closed this bug. It turns out that I was just mistaken. All the Windows-specific versions of OwnPtr like OwnPtr<HBITMAP> have their own specialized delete function which gets called. And thanks to template magic, for the general case of T, it turns out that OwnPtr<T*> is identical to OwnPtr<T> in terms of what gets stored in the OwnPtr and which delete function gets called.
Note You need to log in before you can comment on or make changes to this bug.