SamplerStackFrameRAII classes aren't MOZ_RAII and don't prevent you from misusing them

RESOLVED FIXED in Firefox 47

Status

()

--
minor
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: chutten, Assigned: chutten)

Tracking

(Blocks: 1 bug)

unspecified
mozilla47
Points:
---

Firefox Tracking Flags

(firefox47 fixed)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

3 years ago
GeckoProfilerImpl.h has two RAII classes that don't prevent you from accidentally creating them in a way that it self-deletes at the end of the statement.

According to https://developer.mozilla.org/en-US/docs/Mozilla/RAII_classes there are ways to fix this so that others do not have to suffer the same shame as I have.

(( Will fix a small portion of bug 1204239 when complete ))
(Assignee)

Comment 1

3 years ago
Created attachment 8712275 [details] [diff] [review]
0001-bug-1238121-Properly-guard-Profiler-s-RAII-classes-r.patch
Attachment #8712275 - Flags: review?(michael)

Comment 2

3 years ago
Comment on attachment 8712275 [details] [diff] [review]
0001-bug-1238121-Properly-guard-Profiler-s-RAII-classes-r.patch

Review of attachment 8712275 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM as a use of MOZ_RAII, but I don't think I'm the person to talk to for changes in the profiler.
Attachment #8712275 - Flags: review?(michael) → feedback+
(Assignee)

Comment 3

3 years ago
Comment on attachment 8712275 [details] [diff] [review]
0001-bug-1238121-Properly-guard-Profiler-s-RAII-classes-r.patch

Tapping :BenWa as he knows profiler stuff (at least enough to point this r? at the correct person if he isn't it).
Attachment #8712275 - Flags: review?(bgirard)
Comment on attachment 8712275 [details] [diff] [review]
0001-bug-1238121-Properly-guard-Profiler-s-RAII-classes-r.patch

Review of attachment 8712275 [details] [diff] [review]:
-----------------------------------------------------------------

Other than not adding a guard to PrintfRAII it looks good.

::: tools/profiler/public/GeckoProfilerImpl.h
@@ +429,5 @@
>    void* mHandle;
>  };
>  
>  static const int SAMPLER_MAX_STRING = 128;
> +class MOZ_RAII SamplerStackFramePrintfRAII {

Why not add the guard here too?
Attachment #8712275 - Flags: review?(bgirard) → review+
(Assignee)

Comment 5

3 years ago
Created attachment 8713241 [details] [diff] [review]
0001-bug-1238121-Properly-guard-Profiler-s-RAII-classes-r.patch

It occurs to me that the lovely commit messages I've been writing don't show up too prominently in bugzilla reviews :(

Basically, the GUARD_OBJECT stuff makes use of default args. PrintfRAII uses va_list. The two just don't work together. At all. And the trick that GUARD_OBJECT uses (I wrote a blog post about it: https://chuttenblog.wordpress.com/2016/01/11/c-today-i-learned-how-to-use-dtor-order-to-detect-temporaries/) seems to require the default arg, so I can't see a way around it.
Attachment #8712275 - Attachment is obsolete: true
Attachment #8713241 - Flags: review+
(Assignee)

Updated

3 years ago
Keywords: checkin-needed
Ahh right, makes sense, thanks! Land away.

Comment 8

3 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/65624d4c4a65
Status: ASSIGNED → RESOLVED
Last Resolved: 3 years ago
status-firefox47: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla47

Comment 9

3 years ago
backoutbugherderlanding
Backed out to see if it fixes the intermittent hazard build failures like https://treeherder.mozilla.org/logviewer.html#?job_id=20736122&repo=mozilla-inbound
https://hg.mozilla.org/integration/mozilla-inbound/rev/8fb056fcecd0
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
(Assignee)

Comment 10

3 years ago
Looking at the hazards list, it isn't likely that this caused them. Back to checkin-needed.
Keywords: checkin-needed

Comment 12

3 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/3f74294e5797
Status: REOPENED → RESOLVED
Last Resolved: 3 years ago3 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.