Closed
Bug 931571
Opened 11 years ago
Closed 9 years ago
Make nsDiscriminatedUnion use methods
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla42
Tracking | Status | |
---|---|---|
firefox42 | --- | fixed |
People
(Reporter: mccr8, Assigned: mccr8)
References
Details
Attachments
(15 files, 1 obsolete file)
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
nsDiscriminated union has a bunch of methods, but instead of being on nsDiscriminatedUnion, they are static methods on nsVariant. The comment on nsDU added on the initial landing of this class in bug 44675 saying "It has no methods. So, its use requires no linkage to the xpcom module." Hopefully that's not still an issue, and we can make this a regular class with a constructor, methods, and private fields.
Assignee | ||
Comment 1•11 years ago
|
||
This does most of the conversion. There are some places in XPCVariant that reach into the class that maybe could be turned into a method on nsDiscriminatedUnion, in which case we could make the data fields private. It may also make sense to move nsDiscriminatedUnion into its own file. Also, the field name "u" is not the best, so maybe that should be changed.
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → continuation
Assignee | ||
Updated•9 years ago
|
Summary: Make nsDiscriminatedUnion a less weird class → Make nsDiscriminatedUnion use methods
Assignee | ||
Comment 2•9 years ago
|
||
I dusted off my patches for this. My apologies in advance to you and your review queue, Nathan.
Assignee | ||
Comment 3•9 years ago
|
||
Assignee | ||
Comment 4•9 years ago
|
||
Try run is green.
There's no hurry on getting these reviewed, Nathan. There are a lot of patches, and they are not too small, but they consist mostly of a bunch of search and replace of nsVariant::Whatever(foo, bar) --> foo->Whatever(bar).
Attachment #8635366 -
Flags: review?(nfroyd)
Assignee | ||
Comment 5•9 years ago
|
||
Attachment #8635367 -
Flags: review?(nfroyd)
Assignee | ||
Comment 6•9 years ago
|
||
Attachment #8635368 -
Flags: review?(nfroyd)
Assignee | ||
Comment 7•9 years ago
|
||
There's more that could be done to fix the style, but this was bothering me.
Attachment #8635369 -
Flags: review?(nfroyd)
Assignee | ||
Comment 8•9 years ago
|
||
Attachment #8635370 -
Flags: review?(nfroyd)
Assignee | ||
Comment 9•9 years ago
|
||
Attachment #8635371 -
Flags: review?(nfroyd)
Assignee | ||
Comment 10•9 years ago
|
||
Attachment #8635372 -
Flags: review?(nfroyd)
Assignee | ||
Comment 11•9 years ago
|
||
Attachment #8635373 -
Flags: review?(nfroyd)
Assignee | ||
Comment 12•9 years ago
|
||
This also adds a new nsDiscriminatedUnion method SetFromDOMString, as somebody added an nsVariant method without the corresponding helper.
Attachment #8635374 -
Flags: review?(nfroyd)
Assignee | ||
Comment 13•9 years ago
|
||
Attachment #8635375 -
Flags: review?(nfroyd)
Assignee | ||
Comment 14•9 years ago
|
||
Attachment #8635376 -
Flags: review?(nfroyd)
Assignee | ||
Comment 15•9 years ago
|
||
This is not quite enough to make the data members private because
XPCVariant pokes around to do some JS array stuff.
Attachment #8635378 -
Flags: review?(nfroyd)
Assignee | ||
Comment 16•9 years ago
|
||
The existing nsDiscriminateUnions either always call Cleanup() when they
are about to go away, or they only handle scalar values so it is safe to
call Cleanup() on them without worrying about another discriminated union
having taken over any memory owned by this union.
Attachment #8635379 -
Flags: review?(nfroyd)
Assignee | ||
Comment 17•9 years ago
|
||
nsDiscriminatedUnion owns memory without using smart pointers, so implementing anything
that would copy or move around one of these will require some care. Just forbid these
for now.
Attachment #8635380 -
Flags: review?(nfroyd)
Assignee | ||
Updated•9 years ago
|
Attachment #823014 -
Attachment is obsolete: true
Updated•9 years ago
|
Attachment #8635366 -
Flags: review?(nfroyd) → review+
Updated•9 years ago
|
Attachment #8635367 -
Flags: review?(nfroyd) → review+
Updated•9 years ago
|
Attachment #8635368 -
Flags: review?(nfroyd) → review+
Updated•9 years ago
|
Attachment #8635369 -
Flags: review?(nfroyd) → review+
Comment 18•9 years ago
|
||
Comment on attachment 8635370 [details] [diff] [review]
part 5 - Turn basic ConvertTo functions into methods.
Review of attachment 8635370 [details] [diff] [review]:
-----------------------------------------------------------------
::: xpcom/ds/nsVariant.cpp
@@ +65,5 @@
> // This group results in a int32_t...
>
> #define CASE__NUMBER_INT32(type_, member_) \
> case nsIDataType :: type_ : \
> + aOutData->u.mInt32Value = u. member_ ; \
I don't think this space before |member_| is necessary...
@@ +457,5 @@
>
> /***************************************************************************/
>
> +#define TRIVIAL_DATA_CONVERTER(type_, member_, retval_) \
> + if (mType == nsIDataType :: type_) { \
...or the spaces here. If you wanted to fix them in passing (assuming it does compile, of course), I'd be OK with that.
Attachment #8635370 -
Flags: review?(nfroyd) → review+
Updated•9 years ago
|
Attachment #8635371 -
Flags: review?(nfroyd) → review+
Comment 19•9 years ago
|
||
Comment on attachment 8635372 [details] [diff] [review]
part 7 - Turn ConvertTo*String and ToString into methods.
Review of attachment 8635372 [details] [diff] [review]:
-----------------------------------------------------------------
::: js/xpconnect/src/XPCVariant.cpp
@@ +735,5 @@
>
> /* AString getAsAString (); */
> NS_IMETHODIMP XPCVariant::GetAsAString(nsAString & _retval)
> {
> + return mData.ConvertToAString(_retval);
Want to file a followup bug on s/_retval/aRetval/g?
Attachment #8635372 -
Flags: review?(nfroyd) → review+
Assignee | ||
Comment 20•9 years ago
|
||
(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #19)
> Want to file a followup bug on s/_retval/aRetval/g?
Yeah, it is pretty ugly, but this code is in XPConnect, and thus using JS style, and _retval feels a little more like JS style than aRetval.
Comment 21•9 years ago
|
||
(In reply to Andrew McCreight [:mccr8] from comment #20)
> (In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #19)
> > Want to file a followup bug on s/_retval/aRetval/g?
>
> Yeah, it is pretty ugly, but this code is in XPConnect, and thus using JS
> style, and _retval feels a little more like JS style than aRetval.
Well, the standard says Don't Do That. :) ("That" being identifiers with leading underscores.)
Assignee | ||
Comment 22•9 years ago
|
||
(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #21)
> Well, the standard says Don't Do That. :) ("That" being identifiers with
> leading underscores.)
Oh I see. Yeah, retval_ would likely be better. Also, we use _retval, specifically, in an alarmingly large number of places. I guess it was the fashion of the time.
http://mxr.mozilla.org/mozilla-central/ident?i=_retval&tree=mozilla-central&filter=
Updated•9 years ago
|
Attachment #8635373 -
Flags: review?(nfroyd) → review+
Updated•9 years ago
|
Attachment #8635374 -
Flags: review?(nfroyd) → review+
Updated•9 years ago
|
Attachment #8635375 -
Flags: review?(nfroyd) → review+
Updated•9 years ago
|
Attachment #8635376 -
Flags: review?(nfroyd) → review+
Updated•9 years ago
|
Attachment #8635378 -
Flags: review?(nfroyd) → review+
Comment 23•9 years ago
|
||
Comment on attachment 8635379 [details] [diff] [review]
part 13 - Add a destructor for nsDiscriminatedUnion.
Review of attachment 8635379 [details] [diff] [review]:
-----------------------------------------------------------------
::: xpcom/ds/nsVariant.h
@@ +31,5 @@
> {
> public:
>
> nsDiscriminatedUnion() : mType(nsIDataType::VTYPE_EMPTY) {}
> + ~nsDiscriminatedUnion() { Cleanup(); }
Does this mean we could make Cleanup private?
Attachment #8635379 -
Flags: review?(nfroyd) → review+
Comment 24•9 years ago
|
||
Comment on attachment 8635380 [details] [diff] [review]
part 14 - Delete various ways to copy or move nsDiscriminatedUnion.
Review of attachment 8635380 [details] [diff] [review]:
-----------------------------------------------------------------
::: xpcom/ds/nsVariant.h
@@ +38,3 @@
> ~nsDiscriminatedUnion() { Cleanup(); }
>
> + nsDiscriminatedUnion& operator=(const nsDiscriminatedUnion&) = delete;
No deletion of the move assignment operator? I'm pretty sure we don't want the compiler-generated one...
Attachment #8635380 -
Flags: review?(nfroyd) → review+
Assignee | ||
Comment 25•9 years ago
|
||
(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #24)
> No deletion of the move assignment operator? I'm pretty sure we don't want
> the compiler-generated one...
I just copied the list of stuff from a Wikpedia entry talking about "the rule of five".
Comment 26•9 years ago
|
||
(In reply to Andrew McCreight [:mccr8] from comment #25)
> (In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #24)
> > No deletion of the move assignment operator? I'm pretty sure we don't want
> > the compiler-generated one...
>
> I just copied the list of stuff from a Wikpedia entry talking about "the
> rule of five".
It looks like the move assignment operator is listed there?
https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)#Rule_of_5
Assignee | ||
Comment 27•9 years ago
|
||
(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #26)
> It looks like the move assignment operator is listed there?
Weird. I guess I forgot to add it, then when I went back to counting how many I had, I was incorrectly including the no-argument ctor as one of the five.
Assignee | ||
Comment 28•9 years ago
|
||
(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #23)
> Does this mean we could make Cleanup private?
No, it is needed in XPCVariant's Unlink method.
Assignee | ||
Comment 29•9 years ago
|
||
Attachment #8638020 -
Flags: review?(nfroyd)
Updated•9 years ago
|
Attachment #8638020 -
Flags: review?(nfroyd) → review+
Assignee | ||
Comment 30•9 years ago
|
||
Thanks for all of the reviews. I deleted the move assignment operator.
Comment 31•9 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/39c4a62c20a1
https://hg.mozilla.org/mozilla-central/rev/0d42e66ab791
https://hg.mozilla.org/mozilla-central/rev/68432d6b66dc
https://hg.mozilla.org/mozilla-central/rev/80dbd90c5291
https://hg.mozilla.org/mozilla-central/rev/a0528bddd48c
https://hg.mozilla.org/mozilla-central/rev/ed99b6a2c10e
https://hg.mozilla.org/mozilla-central/rev/8d0d7f5851ff
https://hg.mozilla.org/mozilla-central/rev/c015f6d6d6f8
https://hg.mozilla.org/mozilla-central/rev/22b849748747
https://hg.mozilla.org/mozilla-central/rev/26a36f6a5c36
https://hg.mozilla.org/mozilla-central/rev/91895b6135d1
https://hg.mozilla.org/mozilla-central/rev/c48aad69c171
https://hg.mozilla.org/mozilla-central/rev/9e87c9dec6f9
https://hg.mozilla.org/mozilla-central/rev/bbfac56ee224
https://hg.mozilla.org/mozilla-central/rev/e83d4dbc7dea
Comment 32•9 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/39c4a62c20a1
https://hg.mozilla.org/mozilla-central/rev/0d42e66ab791
https://hg.mozilla.org/mozilla-central/rev/68432d6b66dc
https://hg.mozilla.org/mozilla-central/rev/80dbd90c5291
https://hg.mozilla.org/mozilla-central/rev/a0528bddd48c
https://hg.mozilla.org/mozilla-central/rev/ed99b6a2c10e
https://hg.mozilla.org/mozilla-central/rev/8d0d7f5851ff
https://hg.mozilla.org/mozilla-central/rev/c015f6d6d6f8
https://hg.mozilla.org/mozilla-central/rev/22b849748747
https://hg.mozilla.org/mozilla-central/rev/26a36f6a5c36
https://hg.mozilla.org/mozilla-central/rev/91895b6135d1
https://hg.mozilla.org/mozilla-central/rev/c48aad69c171
https://hg.mozilla.org/mozilla-central/rev/9e87c9dec6f9
https://hg.mozilla.org/mozilla-central/rev/bbfac56ee224
https://hg.mozilla.org/mozilla-central/rev/e83d4dbc7dea
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox42:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
You need to log in
before you can comment on or make changes to this bug.
Description
•