Closed Bug 1407494 Opened 8 years ago Closed 8 years ago

Some Preferences clean-ups

Categories

(Core :: Preferences: Backend, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla58
Tracking Status
firefox58 --- fixed

People

(Reporter: n.nethercote, Assigned: n.nethercote)

References

Details

Attachments

(10 files)

59 bytes, text/x-review-board-request
glandium
: review+
Details
59 bytes, text/x-review-board-request
glandium
: review+
Details
59 bytes, text/x-review-board-request
glandium
: review+
Details
59 bytes, text/x-review-board-request
glandium
: review+
Details
59 bytes, text/x-review-board-request
glandium
: review+
Details
59 bytes, text/x-review-board-request
glandium
: review+
Details
59 bytes, text/x-review-board-request
glandium
: review+
Details
59 bytes, text/x-review-board-request
glandium
: review+
Details
59 bytes, text/x-review-board-request
glandium
: review+
Details
1.88 KB, patch
glandium
: review+
Details | Diff | Splinter Review
There's some stuff that can be cleaned up.
Attachment #8917633 - Flags: review?(mh+mozilla) → review+
Attachment #8917634 - Flags: review?(mh+mozilla) → review+
Comment on attachment 8917635 [details] Bug 1407494 (part 3) - Remove PR_ALIGN_OF_WORD and WORD_ALIGN_MASK. . https://reviewboard.mozilla.org/r/188580/#review193886 ::: commit-message-c9184:3 (Diff revision 1) > +Bug 1407494 (part 3) - Remove PR_ALIGN_OF_WORD and WORD_ALIGN_MASK. r=glandium. > + > +They're unused. For funz, you may want to add that the only use of WORD_ALIGN_MASK was removed in bug 200524, 14.5 years ago. And PR_ALIGN_OF_WORD was only there for its definition, and only in case NSPR didn't have the define.
Attachment #8917635 - Flags: review?(mh+mozilla) → review+
Comment on attachment 8917636 [details] Bug 1407494 (part 4) - Remove have_PrefChangedFunc_typedef. . https://reviewboard.mozilla.org/r/188582/#review193888
Attachment #8917636 - Flags: review?(mh+mozilla) → review+
Comment on attachment 8917637 [details] Bug 1407494 (part 5) - Replace uses of NS_strdup(), PL_strdup(), PL_strfree() with more standard functions. . https://reviewboard.mozilla.org/r/188584/#review193890 ::: modules/libpref/Preferences.cpp:864 (Diff revision 1) > } else { > stringVal = pref->mUserPref.mStringVal; > } > > if (stringVal) { > - *aValueOut = NS_strdup(stringVal); > + *aValueOut = strdup(stringVal); NS_strdup is infallible. stdup is fallible. You can't change this like that. Either you keep NS_strdup, or you return an OOM error when strdup failed. ::: modules/libpref/Preferences.cpp:2593 (Diff revision 1) > { > nsresult rv = GetCharPref(aPrefName, aRetVal); > > if (NS_FAILED(rv) && aArgc == 1) { > NS_ENSURE_ARG(aDefaultValue); > - *aRetVal = NS_strdup(aDefaultValue); > + *aRetVal = strdup(aDefaultValue); likewise
Attachment #8917637 - Flags: review?(mh+mozilla)
Comment on attachment 8917638 [details] Bug 1407494 (part 6) - Remove GetContentChild(). . https://reviewboard.mozilla.org/r/188586/#review193892 ::: commit-message-1efd8:3 (Diff revision 1) > +Bug 1407494 (part 6) - Remove GetContentChild(). r=glandium. > + > +We can just use XRE_IsContentProcess() instead. Might be worth indicating that its result was never used more than as a bool, so XRE_IsContentProcess fulfils the same need.
Attachment #8917638 - Flags: review?(mh+mozilla) → review+
Comment on attachment 8917639 [details] Bug 1407494 (part 7) - Replace malloc uses with operator new. . https://reviewboard.mozilla.org/r/188588/#review193894 ::: modules/libpref/Preferences.cpp:3121 (Diff revision 1) > - outArray = (char**)moz_xmalloc(numPrefs * sizeof(char*)); > + outArray = new char*[numPrefs]; > - if (!outArray) { funny one, calling infallible malloc and testing the result.
Attachment #8917639 - Flags: review?(mh+mozilla) → review+
Comment on attachment 8917640 [details] Bug 1407494 (part 8) - Remove forward declaration of PrefSetting. . https://reviewboard.mozilla.org/r/188590/#review193896
Attachment #8917640 - Flags: review?(mh+mozilla) → review+
Comment on attachment 8917641 [details] Bug 1407494 (part 9) - Merge PREF_RegisterCallback() and PREF_RegisterPriorityCallback. . https://reviewboard.mozilla.org/r/188592/#review193898 ::: modules/libpref/Preferences.cpp:1326 (Diff revision 1) > -} > - > + } else { > + // Add to the start of the non-priority part of the list. > -// Adds a node to the end of the callback list. > -void > -PREF_RegisterCallback(const char* aPrefNode, > - PrefChangedFunc aCallback, > - void* aData) > -{ > - NS_PRECONDITION(aPrefNode, "aPrefNode must not be nullptr"); > - NS_PRECONDITION(aCallback, "aCallback must not be nullptr"); > - > - auto node = new CallbackNode(); > - node->mDomain = strdup(aPrefNode); > - node->mFunc = aCallback; > - node->mData = aData; > - if (gLastPriorityNode) { > + if (gLastPriorityNode) { > - node->mNext = gLastPriorityNode->mNext; > + node->mNext = gLastPriorityNode->mNext; > - gLastPriorityNode->mNext = node; > + gLastPriorityNode->mNext = node; > - } else { > + } else { > - node->mNext = gFirstCallback; > + node->mNext = gFirstCallback; > - gFirstCallback = node; > + gFirstCallback = node; > - } > + } > -} > + } } else if () { } else { } instead of } else { if () { } else { } }
Attachment #8917641 - Flags: review?(mh+mozilla) → review+
> } else if () { > } else { > } > > instead of > > } else { > if () { > } else { > } > } I'd prefer to keep it as is, because there's a comment that applies the the outer `else`.
I changed part 5 to use moz_xstrdup().
Comment on attachment 8917637 [details] Bug 1407494 (part 5) - Replace uses of NS_strdup(), PL_strdup(), PL_strfree() with more standard functions. . https://reviewboard.mozilla.org/r/188584/#review194268
Attachment #8917637 - Flags: review?(mh+mozilla) → review+
Depends on: 1408275
https://hg.mozilla.org/integration/mozilla-inbound/rev/d9b156e30219d2c4c83db2457b2cef81b7c53253 Bug 1407494 (part 1) - Remove C-isms. r=glandium. https://hg.mozilla.org/integration/mozilla-inbound/rev/ec1612180aeb371e6cd35f68bfdc0df3e59c1f90 Bug 1407494 (part 2) - Remove TEST_PREFREAD. r=glandium. https://hg.mozilla.org/integration/mozilla-inbound/rev/60c539b7c035c9abaa4dcdd9eb88ec1a1e057237 Bug 1407494 (part 3) - Remove PR_ALIGN_OF_WORD and WORD_ALIGN_MASK. r=glandium. https://hg.mozilla.org/integration/mozilla-inbound/rev/40efac89e219dbd0daa18b7c68fb4c837bc46767 Bug 1407494 (part 4) - Remove have_PrefChangedFunc_typedef. r=glandium. https://hg.mozilla.org/integration/mozilla-inbound/rev/10a071e84601a3c8cf7c1c3fda216939d25b530f Bug 1407494 (part 5) - Replace uses of NS_strdup(), PL_strdup(), PL_strfree() with more standard functions. r=glandium. https://hg.mozilla.org/integration/mozilla-inbound/rev/06ad4faaa205ba4eab7e48735f9ccd287a0e4007 Bug 1407494 (part 6) - Remove GetContentChild(). r=glandium. https://hg.mozilla.org/integration/mozilla-inbound/rev/39b4ec7b889a6a99b79693c87dbac08cad2c5448 Bug 1407494 (part 7) - Replace malloc uses with operator new. r=glandium. https://hg.mozilla.org/integration/mozilla-inbound/rev/312ea2b713c074ca7f0fb184a7ea788ad48bb2a9 Bug 1407494 (part 8) - Remove forward declaration of PrefSetting. r=glandium. https://hg.mozilla.org/integration/mozilla-inbound/rev/d3d210f0c178d1b81816cf54b520a04a003f55b5 Bug 1407494 (part 9) - Merge PREF_RegisterCallback() and PREF_RegisterPriorityCallback. r=glandium.
Hi Nicholas, could you tell me whether I should do some similar clean-up in comm-central. I could replace NS_strdup(), PL_strdup() and PL_strfree().
Flags: needinfo?(n.nethercote)
(In reply to Jorg K (GMT+2) from comment #31) > Hi Nicholas, could you tell me whether I should do some similar clean-up in > comm-central. I could replace NS_strdup(), PL_strdup() and PL_strfree(). Those functions still have quite a few uses in mozilla-central. I replaced them in this file while changing a bunch of other things, but I'm not sure it's worth the effort of getting rid of all of them, since you won't be able to remove their definitions.
Flags: needinfo?(n.nethercote)
I was asking because NS_Free() and NS_Alloc() disappeared the other day and left us busted (bug 1408196). At least NS_strdup() looks like it could suffer a similar fate, but then, the "strdup" is lower-case.
The PL_* ones won't disappear because they're in NSPR. As for NS_strdup(), there are two variants, an 8-bit one and a 16-bit one. The 16-bit one is unlikely to disappear because there's no equivalent. And because it's unlikely to disappear, the 8-bit one is probably also unlikely to disappear.
Coverity complained about mismatched new/free for one of these.
Attachment #8919595 - Flags: review?(mh+mozilla)
Assignee: nobody → n.nethercote
Attachment #8919595 - Flags: review?(mh+mozilla) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/14cfc090780e0da71712fbbc0267dd94166d75b8 Bug 1407494 (follow-up) - Revert operator new use to malloc(), to pair with free(). r=glandium.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: