Bug 59470 - Prohibit the use of OwnPtr<T*>
Summary: Prohibit the use of OwnPtr<T*>
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Adrienne Walker
URL:
Keywords:
Depends on: 59469 59489 59559
Blocks:
  Show dependency treegraph
 
Reported: 2011-04-26 11:03 PDT by Adrienne Walker
Modified: 2011-06-20 09:41 PDT (History)
5 users (show)

See Also:


Attachments
Patch (2.64 KB, patch)
2011-04-26 11:04 PDT, Adrienne Walker
no flags Details | Formatted Diff | Diff
Patch (2.56 KB, patch)
2011-04-26 12:13 PDT, Adrienne Walker
no flags Details | Formatted Diff | Diff
Patch (2.56 KB, patch)
2011-04-26 16:23 PDT, Adrienne Walker
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adrienne Walker 2011-04-26 11:03:38 PDT
Prohibit the use of OwnPtr<T*>
Comment 1 Adrienne Walker 2011-04-26 11:04:47 PDT
Created attachment 91129 [details]
Patch
Comment 2 Adrienne Walker 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.)
Comment 3 WebKit Review Bot 2011-04-26 11:26:49 PDT
Attachment 91129 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/8509701
Comment 4 Build Bot 2011-04-26 12:07:53 PDT
Attachment 91129 [details] did not build on win:
Build output: http://queues.webkit.org/results/8508728
Comment 5 WebKit Review Bot 2011-04-26 12:11:43 PDT
Attachment 91129 [details] did not build on mac:
Build output: http://queues.webkit.org/results/8505948
Comment 6 Adrienne Walker 2011-04-26 12:13:51 PDT
Created attachment 91144 [details]
Patch
Comment 7 Adrienne Walker 2011-04-26 12:14:30 PDT
Let's try this again now that the blocking bugfix has landed.
Comment 8 WebKit Review Bot 2011-04-26 12:57:47 PDT
Attachment 91144 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/8509721
Comment 9 Adrienne Walker 2011-04-26 13:23:57 PDT
Comment on attachment 91144 [details]
Patch

Oops.  Need to touch up DRT as well.
Comment 10 WebKit Review Bot 2011-04-26 13:54:35 PDT
Attachment 91129 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/8510701
Comment 11 Build Bot 2011-04-26 14:01:35 PDT
Attachment 91144 [details] did not build on win:
Build output: http://queues.webkit.org/results/8509734
Comment 12 WebKit Review Bot 2011-04-26 15:34:52 PDT
Attachment 91144 [details] did not build on mac:
Build output: http://queues.webkit.org/results/8508780
Comment 13 Adrienne Walker 2011-04-26 16:23:33 PDT
Created attachment 91177 [details]
Patch
Comment 14 Adrienne Walker 2011-04-26 16:23:59 PDT
Third time's a charm for fixing all the build errors.
Comment 15 Geoffrey Garen 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.
Comment 16 Adrienne Walker 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.
Comment 17 Build Bot 2011-04-26 17:05:00 PDT
Attachment 91177 [details] did not build on win:
Build output: http://queues.webkit.org/results/8507775
Comment 18 Adrienne Walker 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.
Comment 19 WebKit Review Bot 2011-04-26 18:22:01 PDT
Attachment 91144 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/8510781
Comment 20 Adrienne Walker 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.
Comment 21 Darin Adler 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*!
Comment 22 Adrienne Walker 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.