Closed
Bug 355463
Opened 19 years ago
Closed 18 years ago
nsCOMPtr::get() should not return a nsDerivedSafe
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
People
(Reporter: sicking, Assigned: sicking)
Details
Attachments
(1 file, 2 obsolete files)
17.65 KB,
patch
|
Details | Diff | Splinter Review |
Currently mycomptr.get() returns an nsDerivedSafe. This makes it very clunky to upcast such a variable. The result is something like
nsCOMPtr<nsINode> node;
....
nsIContent* cont = NS_STATIC_CAST(nsIContent*, NS_STATIC_CAST(nsINode*, node));
It would be much cleaner if it was possible to do
nsIContent* cont = NS_STATIC_CAST(nsIContent*, node.get());
Additionally, it's safer in situations where someone uses c-style casts.
nsCOMPtr<nsIFormControl> fc = ...;
nsHTMLInputElement* input = (nsHTMLInputElement*)fc.get();
compiles but fails (it will be a reinterpret cast, whereas what you want is a static cast). Granted, noone should be doing c-style casts.
![]() |
||
Comment 1•19 years ago
|
||
We don't really want people doing foo.get()->AddRef(), though...
Assignee | ||
Comment 2•19 years ago
|
||
Personally, I don't think it's likely that anyone will do that accidentally, nor NS_ADDREF(foo.get()). I've never seen anyone do
NS_ADDREF(NS_STATIC_CAST(nsINode*, foo)) for example so I don't think they'll start using .get() get around nsDerivedSafe.
Assignee | ||
Comment 3•19 years ago
|
||
I searched content/ and layout/ for ".get()))" and simplified the places i found.
Attachment #241270 -
Flags: superreview?(dbaron)
Attachment #241270 -
Flags: review?(dbaron)
Comment 4•19 years ago
|
||
> upcast such a variable
you mean downcast?
Assignee | ||
Comment 5•19 years ago
|
||
No, downcast is easy and works implicitly. I.e. the following compiles:
nsCOMPtr<nsIContent> cont = ...
nsINode* node = cont;
Upcasting is very clunky though. The following does _not_ compile
nsCOMPtr<nsINode> node = ...
nsIContent* cont = NS_STATIC_CAST(nsIContent*, node);
Nor does
nsCOMPtr<nsINode> node = ...
nsIContent* cont = NS_STATIC_CAST(nsIContent*, node.get());
You currently have to do
nsCOMPtr<nsINode> node = ...
nsIContent* cont = NS_STATIC_CAST(nsIContent*,
NS_STATIC_CAST(nsINode*, node.get()));
(Not sure if the last .get() is needed or not, but people seem to use it)
Assignee | ||
Comment 6•19 years ago
|
||
There was a compile error in xpcom/tests with the previous patch.
Attachment #241270 -
Attachment is obsolete: true
Attachment #241794 -
Flags: superreview?(dbaron)
Attachment #241794 -
Flags: review?(dbaron)
Attachment #241270 -
Flags: superreview?(dbaron)
Attachment #241270 -
Flags: review?(dbaron)
Comment on attachment 241794 [details] [diff] [review]
Compile tests
>Index: xpcom/glue/nsCOMPtr.h
>+ nsDerivedSafe<T>*
>+ get_DerivedSafe() const
>+ {
>+ return NS_REINTERPRET_CAST(nsDerivedSafe<T>*, mRawPtr);
>+ }
Do you want this to be private? With that, r+sr=dbaron.
I think there are some unneeded NS_CONST_CASTs floating around, but probably better to only try one source of build bustage at a time.
Attachment #241794 -
Flags: superreview?(dbaron)
Attachment #241794 -
Flags: superreview+
Attachment #241794 -
Flags: review?(dbaron)
Attachment #241794 -
Flags: review+
Assignee | ||
Comment 8•18 years ago
|
||
This is the patch I checked in. It addresses dbarons review comment and also fixes nsCOMPtr<nsISupports> to get the same changes as nsCOMPtr<T>
Attachment #241794 -
Attachment is obsolete: true
Assignee | ||
Updated•18 years ago
|
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•