Closed Bug 1238121 Opened 8 years ago Closed 8 years ago

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

Categories

(Core :: Gecko Profiler, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED
mozilla47
Tracking Status
firefox47 --- fixed

People

(Reporter: chutten, Assigned: chutten)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 obsolete file)

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 ))
Attachment #8712275 - Flags: review?(michael)
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+
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+
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+
Keywords: checkin-needed
Ahh right, makes sense, thanks! Land away.
https://hg.mozilla.org/mozilla-central/rev/65624d4c4a65
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla47
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 → ---
Looking at the hazards list, it isn't likely that this caused them. Back to checkin-needed.
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/3f74294e5797
Status: REOPENED → RESOLVED
Closed: 8 years ago8 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: