Closed Bug 1998636 Opened 4 months ago Closed 4 months ago

Evaluate using std::unique_ptr instead of mozilla::StaticAutoPtr

Categories

(Core :: XPCOM, task)

task

Tracking

()

RESOLVED FIXED
147 Branch
Tracking Status
firefox147 --- fixed

People

(Reporter: sergesanspaille, Assigned: sergesanspaille)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

Attachments

(1 file)

StaticAutoPtr is equivalent to std::unique_ptr as the latter has a constexpr default constructor

No longer blocks: 1982662
No longer depends on: 1973598, 1973941
Depends on: 1998637
Depends on: 1998692

StaticAutoPtr is XPCOM, not MFBT.

Component: MFBT → XPCOM
Depends on: 1998727
Depends on: 1998733
Depends on: 1998737

(In reply to [:sergesanspaille] from comment #0)

StaticAutoPtr is equivalent to std::unique_ptr as the latter has a constexpr default constructor

This is not true, as std::unique_ptr has a destructor, which StaticAutoPtr does not. If you are converting to std::unique_ptr, you need to make a NeverDestroyed<std::unique_ptr> to disable the static destructor so we don't introduce new static destructors.

Static destructors like this waste memory by adding new entries, and can cause weird bugs in code which doesn't fast-exit, as they'll run as the process exits.

I do not think that a straight replacement of StaticAutoPtr with std::unique_ptr is a good idea, in fact I would prefer to do the opposite, and convert more static std::unique_ptr instances to remove the static destructors.

Flags: needinfo?(sguelton)

In particular make it clear that it behaves differently from
std::unique_ptr in termes of destructor.

Assignee: nobody → sguelton
Status: NEW → ASSIGNED

Indeed! I updated the internal documentation and cancelled the associated child bugs.

Flags: needinfo?(sguelton)
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 147 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: