Closed
Bug 1411893
Opened 7 years ago
Closed 7 years ago
Introduce nsStaticAtom
Categories
(Core :: XPCOM, enhancement)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla58
Tracking | Status | |
---|---|---|
firefox58 | --- | fixed |
People
(Reporter: n.nethercote, Assigned: n.nethercote)
References
(Depends on 2 open bugs)
Details
Attachments
(2 files)
nsAtom covers both static and dynamic atoms. But there are quite a few places where we deal exclusively with static atoms, and so we can use raw pointers without worrying about refcounting.
This bug will introduce nsStaticAtom, a trivial sub-class of nsAtom that can be used for these cases.
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Comment 3•7 years ago
|
||
mozreview-review |
Comment on attachment 8922252 [details]
Bug 1411893 - Introduce nsStaticAtom. .
https://reviewboard.mozilla.org/r/193288/#review198502
C/C++ static analysis found 1 defect in this patch.
You can run this analysis locally with: `./mach static-analysis check path/to/file.cpp`
If you see a problem in this automated review, please report it here: http://bit.ly/2y9N9Vx
::: layout/style/CounterStyleManager.cpp:584
(Diff revision 1)
> : CounterStyle(aStyle)
> , mName(aName)
> {
> }
>
> - virtual nsAtom* GetStyleName() const final;
> + virtual nsStaticAtom* GetStyleName() const final;
Warning: 'virtual' is redundant since the function is already declared 'final' [clang-tidy: modernize-use-override]
Comment 4•7 years ago
|
||
mozreview-review |
Comment on attachment 8922252 [details]
Bug 1411893 - Introduce nsStaticAtom. .
https://reviewboard.mozilla.org/r/193288/#review198510
Clearing review because I don't know how this can pass tests, but the general idea makes sense to me, thanks a lot for cleaning up this stuff!
::: layout/style/nsCSSParser.cpp:7956
(Diff revision 1)
> if (ExpectSymbol(',', true)) {
> if (!ParseCounterStyleNameValue(type) && !ParseSymbols(type)) {
> break;
> }
> } else {
> - type.SetAtomIdentValue(do_AddRef(nsGkAtoms::decimal));
> + type.SetAtomIdentValue(
You could add an `nsStaticAtom*` overload of this function if you want, instead of this. Though given there's only one caller it's perhaps not a big deal.
::: servo/components/style/gecko/media_queries.rs:640
(Diff revision 1)
> nsMediaExpression_Range::eMax
> } else {
> nsMediaExpression_Range::eEqual
> };
>
> let atom = Atom::from(feature_name);
`feature_name` comes directly from the CSS parser, and there's nothing to guarantee that this is a static atom. So I'd just use `atom.as_ptr() == *f.mName as *mut _` instead.
Are there really no tests that caught this?
::: servo/components/style/gecko_string_cache/mod.rs:181
(Diff revision 1)
>
> + /// Returns the atom as a mutable nsStaticAtom pointer.
> + #[inline]
> + pub fn as_static_ptr(&self) -> *mut nsStaticAtom {
> + assert!(self.is_static());
> + let const_ptr: *const nsAtom = &self.0;
nit: `self.as_ptr() as *mut nsStaticAtom`? But I don't think this is needed given the above.
::: servo/components/style/gecko_string_cache/mod.rs:406
(Diff revision 1)
> + #[inline]
> + fn from(ptr: *mut nsStaticAtom) -> Atom {
> + assert!(!ptr.is_null());
> + unsafe {
> + let ret = Atom(WeakAtom::new(ptr as *mut nsAtom));
> + assert!(!ret.is_static());
Huh, what? Shouldn't you assert that it _is_ static here?
But I think that we shouldn't add this if it's not needed actually (I don't see any use of it in this patch).
::: servo/components/style/gecko_string_cache/mod.rs:407
(Diff revision 1)
> + fn from(ptr: *mut nsStaticAtom) -> Atom {
> + assert!(!ptr.is_null());
> + unsafe {
> + let ret = Atom(WeakAtom::new(ptr as *mut nsAtom));
> + assert!(!ret.is_static());
> + ret
Err, I lie, there's one use in the media queries code I see. The comment about the assertion still applies though.
::: xpcom/ds/nsAtom.h:114
(Diff revision 1)
> +// nsICSSPseudoElement, which are trivial subclasses used to ensure only
> +// certain atoms are passed to certain functions.
> +class nsStaticAtom : public nsAtom
> +{
> + // This will detect if RefPtr<nsStaticAtom> is used.
> + MozExternalRefCountType AddRef() { MOZ_CRASH("don't refcnt nsStaticAtom"); }
nit: I think you can use `= delete;` and have a compiler error instead.
Attachment #8922252 -
Flags: review?(emilio)
![]() |
||
Comment 5•7 years ago
|
||
mozreview-review |
Comment on attachment 8922252 [details]
Bug 1411893 - Introduce nsStaticAtom. .
https://reviewboard.mozilla.org/r/193288/#review198584
Thanks, I think this makes a couple of places clearer.
Attachment #8922252 -
Flags: review?(nfroyd) → review+
![]() |
||
Comment 6•7 years ago
|
||
mozreview-review |
Comment on attachment 8922251 [details]
Bug 1411893 - Remove some unnecessary (nsAtom***) casts. .
https://reviewboard.mozilla.org/r/193286/#review198586
Much nicer, thank you.
Attachment #8922251 -
Flags: review?(nfroyd) → review+
![]() |
Assignee | |
Comment 7•7 years ago
|
||
> Clearing review because I don't know how this can pass tests, but the
> general idea makes sense to me, thanks a lot for cleaning up this stuff!
I haven't run proper tests yet :) Thanks for spotting the logic errors.
> > + MozExternalRefCountType AddRef() { MOZ_CRASH("don't refcnt nsStaticAtom"); }
>
> nit: I think you can use `= delete;` and have a compiler error instead.
Ah yes! I was going to try that but I forgot about it. I will do that.
![]() |
Assignee | |
Comment 8•7 years ago
|
||
> Thanks, I think this makes a couple of places clearer.
BTW, we have all these static arrays that contains nsGkAtoms, and they're all stored as nsAtom** instead of nsAtom*. That's how we end up with nsAtom*** in some places. AFAICT the double-pointer is not necessary; I'm going to try to convert them to single-pointers.
![]() |
Assignee | |
Comment 9•7 years ago
|
||
(In reply to Nicholas Nethercote [:njn] from comment #8)
> > Thanks, I think this makes a couple of places clearer.
>
> BTW, we have all these static arrays that contains nsGkAtoms, and they're
> all stored as nsAtom** instead of nsAtom*. That's how we end up with
> nsAtom*** in some places. AFAICT the double-pointer is not necessary; I'm
> going to try to convert them to single-pointers.
Oh, it is necessary, because these are static lists but nsGkAtoms aren't defined statically. Bug 1411469 is needed for that to work.
![]() |
Assignee | |
Comment 10•7 years ago
|
||
Try push for my updates patches looks good: https://treeherder.mozilla.org/#/jobs?repo=try&revision=6b868b65cf62ffb126a3dbb266c4c7d29a99a18a
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Comment 13•7 years ago
|
||
mozreview-review |
Comment on attachment 8922252 [details]
Bug 1411893 - Introduce nsStaticAtom. .
https://reviewboard.mozilla.org/r/193288/#review198884
C/C++ static analysis found 1 defect in this patch.
You can run this analysis locally with: `./mach static-analysis check path/to/file.cpp`
If you see a problem in this automated review, please report it here: http://bit.ly/2y9N9Vx
::: layout/style/CounterStyleManager.cpp:584
(Diff revision 2)
> : CounterStyle(aStyle)
> , mName(aName)
> {
> }
>
> - virtual nsAtom* GetStyleName() const final;
> + virtual nsStaticAtom* GetStyleName() const final;
Warning: 'virtual' is redundant since the function is already declared 'final' [clang-tidy: modernize-use-override]
Comment 14•7 years ago
|
||
mozreview-review |
Comment on attachment 8922252 [details]
Bug 1411893 - Introduce nsStaticAtom. .
https://reviewboard.mozilla.org/r/193288/#review198900
Attachment #8922252 -
Flags: review?(emilio) → review+
Comment 15•7 years ago
|
||
Pushed by ecoal95@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/afb8a71fc972
Remove some unnecessary (nsAtom***) casts. r=froydnj.
https://hg.mozilla.org/integration/autoland/rev/42eb6d46aa30
Introduce nsStaticAtom. r=emilio,froydnj.
![]() |
Assignee | |
Comment 16•7 years ago
|
||
Thank you for doing the autoland of the Gecko-side patches, Emilio.
![]() |
Assignee | |
Comment 17•7 years ago
|
||
https://github.com/servo/servo/pull/19035 was the Servo-side PR.
![]() |
||
Comment 18•7 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/afb8a71fc972
https://hg.mozilla.org/mozilla-central/rev/42eb6d46aa30
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla58
![]() |
Assignee | |
Updated•7 years ago
|
Assignee: nobody → n.nethercote
You need to log in
before you can comment on or make changes to this bug.
Description
•