WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED WONTFIX
37046
Create a class that can be extended to prevent objects from being placed on the heap
https://bugs.webkit.org/show_bug.cgi?id=37046
Summary
Create a class that can be extended to prevent objects from being placed on t...
Andy Estes
Reported
Friday, April 2, 2010 10:42:38 PM UTC
Classes that wish to prohibit clients from allocating them on the heap can extend a class that will make operator new and operator delete private, thereby preventing heap and placement new allocation.
Attachments
patch
(8.87 KB, patch)
2010-04-02 14:55 PDT
,
Andy Estes
no flags
Details
Formatted Diff
Diff
patch (v2)
(8.87 KB, patch)
2010-04-02 15:16 PDT
,
Andy Estes
no flags
Details
Formatted Diff
Diff
patch (v3)
(8.86 KB, patch)
2010-04-02 15:19 PDT
,
Andy Estes
no flags
Details
Formatted Diff
Diff
patch (v4)
(8.86 KB, patch)
2010-04-02 15:29 PDT
,
Andy Estes
ggaren
: review-
Details
Formatted Diff
Diff
patch (v5)
(9.36 KB, patch)
2010-04-02 15:56 PDT
,
Andy Estes
mjs
: review-
Details
Formatted Diff
Diff
patch (v6)
(9.38 KB, patch)
2010-04-02 16:32 PDT
,
Andy Estes
no flags
Details
Formatted Diff
Diff
Show Obsolete
(5)
View All
Add attachment
proposed patch, testcase, etc.
Andy Estes
Comment 1
Friday, April 2, 2010 10:55:49 PM UTC
Created
attachment 52452
[details]
patch
Joseph Pecoraro
Comment 2
Friday, April 2, 2010 11:15:02 PM UTC
> + * Copyright (C) 2010 Apple Computer, Inc.
I've seen people remove "Computer" and make this just "Apple, Inc."
Andy Estes
Comment 3
Friday, April 2, 2010 11:16:56 PM UTC
Created
attachment 52456
[details]
patch (v2) Changed comments to be grammatically correct.
Andy Estes
Comment 4
Friday, April 2, 2010 11:19:45 PM UTC
Created
attachment 52457
[details]
patch (v3) Corrected copyright line in NonHeapAllocatable.h.
Andy Estes
Comment 5
Friday, April 2, 2010 11:20:12 PM UTC
(In reply to
comment #2
)
> > + * Copyright (C) 2010 Apple Computer, Inc. > > I've seen people remove "Computer" and make this just "Apple, Inc."
Good catch, thanks.
Alexey Proskuryakov
Comment 6
Friday, April 2, 2010 11:26:55 PM UTC
We normally use BSD license for new code. I think that canonical text is at <
http://webkit.org/coding/bsd-license.html
> now, but very few files follow it exactly at the moment.
Andy Estes
Comment 7
Friday, April 2, 2010 11:29:52 PM UTC
Created
attachment 52459
[details]
patch (v4) Fourth time's a charm. I had a typo in one of the build files.
Geoffrey Garen
Comment 8
Friday, April 2, 2010 11:33:21 PM UTC
Comment on
attachment 52459
[details]
patch (v4) r=me
Geoffrey Garen
Comment 9
Friday, April 2, 2010 11:34:21 PM UTC
Comment on
attachment 52459
[details]
patch (v4) Oops! I think you still have the LGPL license instead of BSD.
Andy Estes
Comment 10
Friday, April 2, 2010 11:56:00 PM UTC
Created
attachment 52461
[details]
patch (v5) Use BSD license in NonHeapAllocatable.h
Maciej Stachowiak
Comment 11
Saturday, April 3, 2010 12:30:07 AM UTC
Comment on
attachment 52461
[details]
patch (v5) I'm not sure this class is a good idea. It can't stop an object from being a data member of another object, including one being allocated on the heap. So it doesn't truly prevent heap allocation.
Andy Estes
Comment 12
Saturday, April 3, 2010 12:32:17 AM UTC
Created
attachment 52464
[details]
patch (v6) Fixed up the copyright line.
Maciej Stachowiak
Comment 13
Saturday, April 3, 2010 12:44:12 AM UTC
Comment on
attachment 52464
[details]
patch (v6) r- for same reasons as previous patch and per discussion w/ Andy.
Mark Rowe (bdash)
Comment 14
Saturday, April 3, 2010 9:16:19 AM UTC
Comment on
attachment 52464
[details]
patch (v6)
> +class NonHeapAllocatable { > + private: > + // Prohibit new and delete. > + void* operator new(size_t); > + void operator delete(void*); > + > + // Prohibit array new and delete. > + void* operator new[](size_t); > + void operator delete[](void*); > + > + // Prohibit placement new and delete. > + void* operator new(size_t, void*); > + void* operator new[](size_t, void*); > + void operator delete(void*, void*); > + void operator delete[](void*, void*); > +};
We typically don’t indent the “private:” like this. The body of the class should be shifted left by one indentation level.
Eric Seidel (no email)
Comment 15
Sunday, May 9, 2010 10:39:35 PM UTC
Comment on
attachment 52464
[details]
patch (v6) Patch looks good to me. Mark is right about the indent though, meaning we can't cq this as-is. You can use webkit-patch land-safely once you've modified locally to have it automatically fill in the reviewer and upload a patch for the commit-queue (if you're a committer). If you're not a committer, you'll have to just post it for review/commit again or get someone to land it for you.
Darin Adler
Comment 16
Sunday, May 9, 2010 10:47:53 PM UTC
Comment on
attachment 52464
[details]
patch (v6) Does this actually work? I tried something like this a while back for the class RenderStyle and the technique failed. Have you tried deriving from this and then using new and delete on that class? I also don't entirely understand what placement new and delete have to do with heap allocation.
Andy Estes
Comment 17
Monday, May 10, 2010 1:40:34 AM UTC
(In reply to
comment #16
)
> (From update of
attachment 52464
[details]
) > Does this actually work?
No, unfortunately not. For instance, the following heap allocation wouldn't be prevented by NonHeapAllocatable: class StackOnlyObject : public NonHeapAllocatable {} class Wrapper { StackOnlyObject obj; } Wrapper* wrapper = new Wrapper(); I moved forward with the pop-up blocking patch without this, but neglected to clear the review flag. Sorry about that!
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug