Closed
Bug 255792
Opened 21 years ago
Closed 20 years ago
nsSmallVoidArray::ReplaceElementAt does not work in the same way as nsVoidArray::ReplaceElementAt
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: smaug, Assigned: dougt)
Details
Attachments
(2 files, 3 obsolete files)
2.76 KB,
patch
|
jesup
:
review+
|
Details | Diff | Splinter Review |
1.19 KB,
patch
|
jesup
:
review+
alecf
:
superreview+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040616
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040616
nsSmallVoidArray::ReplaceElementAt does not work in the same way as
nsVoidArray::ReplaceElementAt. It should grow the array size if needed.
Patch coming.
Reproducible: Always
Steps to Reproduce:
Reporter | ||
Comment 1•21 years ago
|
||
Reporter | ||
Comment 2•21 years ago
|
||
Comment on attachment 156293 [details] [diff] [review]
proposed patch
I'm not sure who should review this.
Attachment #156293 -
Flags: review?(dougt)
Reporter | ||
Updated•21 years ago
|
Attachment #156293 -
Flags: review?(dougt) → review?(rjesup)
Comment 3•21 years ago
|
||
The reason it doesn't work the same way is that the API's defined before I
rewrote both classes had different semantics for ReplaceElementAt. Yes it's
annoying. You'd have to prove that no usage of ReplaceElementAt that depends on
the current behavior.
Also review the commentary in bug 90545. There are a bunch of historical
weirdnesses in the array classes that I didn't dare remove.
Reporter | ||
Comment 4•21 years ago
|
||
I checked all the cases were nsSmallVoidArray is used
and ReplaceElementAt is not used at all.
http://lxr.mozilla.org/seamonkey/search?string=nsSmallVoidArray
http://lxr.mozilla.org/seamonkey/search?string=ReplaceElementAt
Comment 5•21 years ago
|
||
(In reply to comment #4)
> I checked all the cases were nsSmallVoidArray is used
> and ReplaceElementAt is not used at all.
> http://lxr.mozilla.org/seamonkey/search?string=nsSmallVoidArray
> http://lxr.mozilla.org/seamonkey/search?string=ReplaceElementAt
You're _probably_ right, but a you need to look at each ReplaceElementAt()
instance and determine that it's not operating on a SmallVoidArray. You can't
just look at the two lists and say that without at least some code examination.
If you did verify each one (and verified it can't get indirectly invoked or
invoked by something external like a plugin - and it is exported I think) then
we could consider changing it.
Reporter | ||
Comment 6•21 years ago
|
||
hmm, of course I can't check all possible plugins etc.
Comment 7•21 years ago
|
||
Your other option is to create ReplaceElementAt2() or some equivalent, or
otherwise cause old uses (plugins for example) to use the old function, but cause
anything else to use the new one.
Changing API's once they're in the wild for a while is tough and dangerous.
Typically you need to support the old one. You could also create
nsNewSmallVoidArray/whatever that differs only in that one routine (and would
probably make nsSmallVoidArray a subclass of it that overrides
ReplaceElementAt()). That's your safest bet - nothing would get the new API
without some source mods.
Reporter | ||
Comment 8•21 years ago
|
||
So something like this perhaps.
Attachment #156293 -
Attachment is obsolete: true
Reporter | ||
Updated•21 years ago
|
Attachment #157331 -
Flags: review?(rjesup)
Reporter | ||
Updated•21 years ago
|
Attachment #156293 -
Flags: review?(rjesup)
Comment 9•21 years ago
|
||
Comment on attachment 157331 [details] [diff] [review]
v2
review + with two caveats before checkin:
Add some comments in the .cpp file about how the new ReplaceElementAt differs
from the original one (a line or two).
Nit: Change
+ if (HasSingleChild())
+ {
+ if (aIndex == 0)
+ {
+ SetSingleChild(aElement);
+ return PR_TRUE;
+ }
+ }
+ else
+ {
+ vector = GetChildVector();
+ }
to
+ if (HasSingleChild())
+ {
+ if (aIndex == 0)
+ {
+ SetSingleChild(aElement);
+ return PR_TRUE;
+ }
+ }
+ vector = GetChildVector();
Attachment #157331 -
Flags: review?(rjesup) → review+
Reporter | ||
Comment 10•21 years ago
|
||
Attachment #157331 -
Attachment is obsolete: true
Reporter | ||
Updated•21 years ago
|
Attachment #157331 -
Flags: review+
Reporter | ||
Comment 11•21 years ago
|
||
Comment on attachment 157425 [details] [diff] [review]
v2 + comments
If this patch is ok, could someone check it in?
Attachment #157425 -
Flags: superreview?(dougt)
Attachment #157425 -
Flags: review?(rjesup)
Comment 12•21 years ago
|
||
Comment on attachment 157425 [details] [diff] [review]
v2 + comments
Looks ok from a code perspective, so review=+.
Now comes the question: _should_ this be done? I agree certainly this is a
better API to start with. However, given the problems (previously stated) in
rooting out older nsSmallVoidArray() uses, what do we gain by adding this? How
many of the nsSmallVoidArray uses can/will be changed over? And how much does
the better interface help compared to the added complexity of
yet-another-slightly-different-class? While an annoyance, this behavioral
difference between nsVoidArray/etc and nsSmallVoidArray isn't a huge problem,
and alternatively could be dealt with by better comments/documentation/debugs.
We could mark nsSmallVoidArray as effectively obsolete, but with certain uses
that require it to stick around (due to plugins/extensions that might access
it).
Luckily, as reviewer, I won't be making that choice. :-)
Attachment #157425 -
Flags: review?(rjesup) → review+
Comment 13•21 years ago
|
||
Plug-ins and extensions are be a moot point. They are not allowed to use
non-frozen private classes like this. If they do, we are likely to break them
again and again (as happened when the string classes changed).
Reporter | ||
Comment 14•21 years ago
|
||
I'd really like to use the new version of the ReplaceElementAt for bug 51444.
Blocks: 51444
Comment 15•21 years ago
|
||
Well, I'm ok with the code, and if it eases solving another bug, that's a good
reason to consider putting it in. Using smallvoidarray2 avoids a lot of work
and worries about tracing through all the usages of this (direct and indirect).
Once this is committed, file a bug (or bugs) to convert over old uses.
Confirming, BTW, in case unconf status keeps it off people's radar.
You might want to add a comment to the effect that nsSmallVoidArray has been
superceded by nsSmallVoidArray2.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Comment 16•21 years ago
|
||
here are the places where nsSmallVoidArray is used today. maybe it would be
better to audit each of these cases to determine if it would be possible to
change the implementation on nsSmallVoidArray::ReplaceElementAt instead of
introducing a new class. This doesn't look like an unwieldy list of places to
check, right?
/content/base/src/nsDocument.cpp, line 160 -- nsSmallVoidArray mRadioButtons;
/content/base/src/nsDocument.h, line 562 -- nsSmallVoidArray mPresShells;
/content/html/content/src/nsHTMLFormElement.cpp, line 339 -- nsSmallVoidArray
mNotInElements; // Holds WEAK references
/content/svg/content/src/nsSVGValue.h, line 44 -- #include "nsGenericElement.h"
// for nsSmallVoidArray
/content/svg/content/src/nsSVGValue.h, line 81 -- nsSmallVoidArray mObservers;
/content/xul/document/src/nsXULDocument.cpp, line 342 -- nsSmallVoidArray
mListeners; // [OWNING] of BroadcastListener objects
/content/xul/document/src/nsXULDocument.cpp, line 806 -- // constructed the
nsSmallVoidArray object in-place.
/content/xul/document/src/nsXULDocument.cpp, line 807 --
entry->mListeners.~nsSmallVoidArray();
/content/xul/document/src/nsXULDocument.cpp, line 944 -- // N.B. placement new
to construct the nsSmallVoidArray object
/content/xul/document/src/nsXULDocument.cpp, line 946 -- new
(&entry->mListeners) nsSmallVoidArray();
/layout/html/base/src/nsReflowPath.h, line 227 -- nsSmallVoidArray mChildren;
![]() |
||
Comment 17•21 years ago
|
||
Note that all those users are in XP code. So assuming non-gecko consumers can't
use nsSmallVoidArray (is that true?) just commenting out this function and
checking all places that fail to compile should work.
Reporter | ||
Comment 18•21 years ago
|
||
I commented out the nsSmallVoidArray::ReplaceElementAt and the compilation
was still ok. So afaik nsSmallVoidArray::ReplaceElementAt is not
used at all. I think r=rjesup, but who would give the sr?
Reporter | ||
Comment 19•21 years ago
|
||
Reporter | ||
Updated•21 years ago
|
Attachment #159020 -
Attachment is obsolete: true
Reporter | ||
Comment 20•21 years ago
|
||
So which one would be better
https://bugzilla.mozilla.org/attachment.cgi?id=157425&action=view
or
https://bugzilla.mozilla.org/attachment.cgi?id=159021&action=view ?
Who could make the decision?
Assignee | ||
Comment 21•21 years ago
|
||
rjesup, can you review?
Reporter | ||
Updated•21 years ago
|
Attachment #159021 -
Flags: superreview?(dougt)
Attachment #159021 -
Flags: review?(rjesup)
Comment 22•21 years ago
|
||
Comment on attachment 159021 [details] [diff] [review]
sorry, this is for nsSmallVoidArray::ReplaceElementAt
If we've verified it's not currently depended on, r=rjesup@wgate.com
Attachment #159021 -
Flags: review?(rjesup) → review+
Assignee | ||
Comment 23•21 years ago
|
||
Comment on attachment 159021 [details] [diff] [review]
sorry, this is for nsSmallVoidArray::ReplaceElementAt
alec, got time to sr this?
Attachment #159021 -
Flags: superreview?(dougt) → superreview?(alecf)
Assignee | ||
Updated•21 years ago
|
Attachment #157425 -
Flags: superreview?(dougt) → superreview?(alecf)
Comment 24•21 years ago
|
||
Comment on attachment 159021 [details] [diff] [review]
sorry, this is for nsSmallVoidArray::ReplaceElementAt
sr=alecf - yes, lets do this way, not the other. I'll "approve" it. assuming
you guys have done the work - thanks darin for listing out the cases to make
that easier!
Attachment #159021 -
Flags: superreview?(alecf) → superreview+
Assignee | ||
Comment 25•21 years ago
|
||
rjesup, can you check this into the trunk?
Reporter | ||
Comment 26•20 years ago
|
||
checked in.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Comment 27•20 years ago
|
||
Comment on attachment 157425 [details] [diff] [review]
v2 + comments
clearing out old review
Attachment #157425 -
Flags: superreview?(alecf)
You need to log in
before you can comment on or make changes to this bug.
Description
•