nsAutoTArray doesn't have a copy-constructor.

RESOLVED FIXED in mozilla9

Status

()

Core
XPCOM
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: Justin Lebar (not reading bugmail), Assigned: Justin Lebar (not reading bugmail))

Tracking

unspecified
mozilla9
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

6 years ago
In bug 682735 comment 52, we noticed that nsAutoTArray doesn't have a copy-constructor.  The following code:

  nsAutoTArray<E, 16> foo;
  // put some elements in foo
  nsAutoTArray<E, 16> bar(foo);

effectively makes |bar| a nsTArray; |bar| will never use its auto storage.

We can fix this simply by adding copy constructors.
(Assignee)

Updated

6 years ago
Assignee: nobody → justin.lebar+bug
(Assignee)

Updated

6 years ago
Depends on: 677571
(Assignee)

Comment 1

6 years ago
Luke pointed out that js vectors don't have copy constructors -- if you want to copy a vector, you need to do so explicitly.

I'm going to see whether we can just do that here.
(Assignee)

Comment 2

6 years ago
Well, nsTArray has a copy-constructor, and I'm not sure we're ready to get rid of that.  So maybe nsAutoTArray should also have one.
(Assignee)

Comment 3

6 years ago
Created attachment 560281 [details] [diff] [review]
Add a copy constructor to nsAutoTArray and friends.

I need to test that this fixes the issues we saw in bug 682735 comment 52, but unfortunately my instrumentation doesn't work on mac.  I think this should work...
Attachment #560281 - Flags: review?(bzbarsky)

Comment 4

6 years ago
Comment on attachment 560281 [details] [diff] [review]
Add a copy constructor to nsAutoTArray and friends.

>+++ b/xpcom/glue/nsTArray.h
>+  nsAutoArrayBase(const nsAutoArrayBase<TArrayBase, N> &aOther) {

Any reason to not make that argument |const TArrayBase &aOther|?

r=me either way.
Attachment #560281 - Flags: review?(bzbarsky) → review+
(Assignee)

Comment 5

6 years ago
(In reply to Boris Zbarsky (:bz) from comment #4)
> >+++ b/xpcom/glue/nsTArray.h
> >+  nsAutoArrayBase(const nsAutoArrayBase<TArrayBase, N> &aOther) {
> 
> Any reason to not make that argument |const TArrayBase &aOther|?

I think just to emphasize that the constructor shouldn't be called except by nsAutoArrayBase's children's copy-constructors.

But in that case, maybe it should be protected...
OS: Mac OS X → Windows Mobile 6 Professional
(Assignee)

Updated

6 years ago
OS: Windows Mobile 6 Professional → All
Hardware: x86 → All
(Assignee)

Comment 6

6 years ago
Created attachment 560504 [details] [diff] [review]
Patch v2

Making the constructors protected.
Attachment #560504 - Flags: review?(bzbarsky)
(Assignee)

Updated

6 years ago
Attachment #560281 - Attachment is obsolete: true

Comment 7

6 years ago
Comment on attachment 560504 [details] [diff] [review]
Patch v2

r=me
Attachment #560504 - Flags: review?(bzbarsky) → review+
https://hg.mozilla.org/mozilla-central/rev/304a0a282365
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla9
You need to log in before you can comment on or make changes to this bug.