Closed Bug 805988 Opened 13 years ago Closed 13 years ago

Assert that nsWrapperCache is the first superclass of non-nsISupport refcounted classes

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla19

People

(Reporter: mccr8, Assigned: bzbarsky)

References

Details

Attachments

(1 file, 2 obsolete files)

This will allow us to reinterpret_cast them directly to nsWrapperCache. [09:34am] bz: It would be easy to static_assert in the wrapping code that the nsWrapperCache is first [09:34am] bz: Just take your type [09:34am] bz: static_cast to nsWrapperCache [09:34am] bz: reinterpret_cast both pointers to void* and compare [09:34am] bz: if they're not equal, you fail compilation It might also be nice to have some kind of conversions to nsWrapperCache that do the appropriate checks or something, handling the various cases, though for my purposes I want both the nsWrapperCache and the "raw" pointer (which are different in the nsISupports case) which makes it trickier. I sort of do something like this in bug 777385.
Blocks: 777385
OK. Except static_cast is not OK in constant expressions. So it would be trivial to make this fail at runtime (MOZ_ASSERT), but I have yet to make it work with static asserts... :(
Yeah, I had the same trouble. Maybe throwing it into the constructor wouldn't be so terrible...
Well, I can throw the runtime assert into the binding wrapping code. That part is easy.
Actually, I have this working. Somehow SFINAE is ok with the setup, yay.
Assignee: nobody → bzbarsky
Whiteboard: [need review]
Comment on attachment 676463 [details] [diff] [review] Add a static assert that new-binding objects are either nsISupports or can be safely reinterpret_cast to nsWrapperCache, if they have an nsWrapperCache at all. that everything except IsValidForWrapNewBindingObject just got moved with no changes Hmm. On Windows and Linux this does not seem to compile, complaining about too few template arguments. I wonder what gives there. I'll try it on my Linux box, I guess.
Attachment #676463 - Flags: review?(peterv)
Yeah, looks like it working with clang is sort of a clang bug. Or something. Or maybe gcc and msvc don't implement some spec update... It doesn't matter that much. Should we just do a MOZ_ASSERT instead of a MOZ_STATIC_ASSERT here?
Summary: Statically assert that nsWrapperCache is the first superclass of non-nsISupport refcounted classes → Assert that nsWrapperCache is the first superclass of non-nsISupport refcounted classes
Attachment #676463 - Attachment is obsolete: true
Attached patch Now with more checking (obsolete) — Splinter Review
Attachment #677252 - Flags: review?(peterv)
Attachment #676748 - Attachment is obsolete: true
Attachment #676748 - Flags: review?(peterv)
Attachment #676748 - Attachment is obsolete: false
Attachment #676748 - Flags: review?(peterv)
Attachment #677252 - Attachment is obsolete: true
Attachment #677252 - Flags: review?(peterv)
Attachment #676748 - Flags: review?(peterv) → review+
Flags: in-testsuite-
Whiteboard: [need review]
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
Can't you use offsetof to make a static assertion?
I mean, I'm coming from bug 811371 where we discussed whether an assertion could guard against forgetting to put nsWrapperCache first in the list of base classes. Andrew mentioned that a runtime assertion for that was added in the present bug.
I considered using offsetof, but it would have to be done on a member, right? And it's not clear what offsetof would do, exactly, on objects with vtables. Per spec, you're not even allowed to use it on those. :(
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: