Closed
Bug 786533
Opened 12 years ago
Closed 12 years ago
Convert usages of NS_MIN to std::min and remove NS_MIN
Categories
(Core :: MFBT, defect)
Tracking
()
RESOLVED
FIXED
mozilla21
People
(Reporter: ehsan.akhgari, Assigned: MatsPalmgren_bugz)
References
Details
(Whiteboard: [mentor=ehsan][lang=c++])
Attachments
(8 files, 2 obsolete files)
953.18 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
33.66 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
9.19 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
5.51 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
879 bytes,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
1.19 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
40.08 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
9.45 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
This bug is about converting everywhere in our tree where we use NS_MIN to use std::min instead (and potentially #include <algorithm> if needed) and remove NS_MIN.
Reporter | ||
Comment 1•12 years ago
|
||
Bug 785542 needs to be fixed before we want to work on this.
Depends on: 785542
Comment 2•12 years ago
|
||
I found 29 uses in comm-central as well, including a definition that looks like this:
inline uint32_t NS_MIN(uint32_t a, uint64_t b);
(blame bug 215450 for that, apparently).
If you expand the scope to include NS_MAX, we have another 8 matches.
Surprisingly, no PR_MIN/PR_MAX usage, though.
Reporter | ||
Comment 3•12 years ago
|
||
Good point. This needs to happen for comm-central at the same time.
Comment 4•12 years ago
|
||
I like to work on this. What needs to be done?
Reporter | ||
Comment 5•12 years ago
|
||
Venkatesh, please first let's wait for bug 785542 to get fixed. Once that happens, you need to go through the code using NS_MIN and NS_MAX in mozilla-central and comm-central and replace those with std::min and std::max, respectively. Since those two functions are defined in the <algorithm> header, you might need to #include that header where needed.
Are you familiar with the steps to build Firefox? That would be a good first step.
Comment 6•12 years ago
|
||
Alright Ehsan, we wait for it to be fixed. I have built a Firefox a few times and tried xpcshell and mochitest to see how to use them as well.
Reporter | ||
Comment 7•12 years ago
|
||
(In reply to comment #6)
> Alright Ehsan, we wait for it to be fixed. I have built a Firefox a few times
> and tried xpcshell and mochitest to see how to use them as well.
That sounds great. FWIW, that bug is very close to getting fixed, feel free to CC yourself on that bug to get notified when it gets fixed.
Reporter | ||
Comment 8•12 years ago
|
||
Venkatesh, if you're still interested, you can start working on this with the latest changeset on mozilla-central.
Comment 9•12 years ago
|
||
Thanks Ehsan, I started replacing the occurrences a few files at a time so that I know where to look when an error occurs. I shouldn't be long before asking you to comment on a diff.
Reporter | ||
Comment 10•12 years ago
|
||
(In reply to comment #9)
> Thanks Ehsan, I started replacing the occurrences a few files at a time so
> that I know where to look when an error occurs. I shouldn't be long before
> asking you to comment on a diff.
Sounds great, thanks a lot!
Comment 11•12 years ago
|
||
All occurrences of NS_MIN and NS_MAX are replaced except the definitions, and some comments that refer to NS_MIN and NS_MAX.
Comment 12•12 years ago
|
||
Ehsan, the attached diff returned some fails on mochitest and one on xpcshell. Please comment on the diff.
Here is the xpcshell fail:
-- BEGIN PASTE --
TEST-UNEXPECTED-FAIL | /home/venk/mozilla-central/obj-x86_64-unknown-linux-gnu/_tests/xpcshell/netwerk/test/unit/test_bug455311.js | [xpconnect wrapped nsIURI] == [xpconnect wrapped nsIURI] - See following stack:
JS frame :: /home/venk/mozilla-central/testing/xpcshell/head.js :: do_throw :: line 451
JS frame :: /home/venk/mozilla-central/testing/xpcshell/head.js :: _do_check_eq :: line 545
JS frame :: /home/venk/mozilla-central/testing/xpcshell/head.js :: do_check_eq :: line 566
JS frame :: /home/venk/mozilla-central/obj-x86_64-unknown-linux-gnu/_tests/xpcshell/netwerk/test/unit/test_bug455311.js :: run_test :: line 122
JS frame :: /home/venk/mozilla-central/testing/xpcshell/head.js :: _execute_test :: line 315
JS frame :: -e :: <TOP_LEVEL> :: line 1
native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0
-- END PASTE --
Reporter | ||
Comment 13•12 years ago
|
||
(In reply to comment #12)
> Ehsan, the attached diff returned some fails on mochitest and one on xpcshell.
> Please comment on the diff.
Do you get these failures every time you run the tests?
Comment 14•12 years ago
|
||
(In reply to Ehsan Akhgari [:ehsan] from comment #13)
> Do you get these failures every time you run the tests?
Yes, I get same fails every time.
Reporter | ||
Updated•12 years ago
|
Attachment #667666 -
Attachment is patch: true
Reporter | ||
Comment 15•12 years ago
|
||
Hmm, it's very hard to find the problem by looking at the patch as it's very large. Can you please break it down into smaller pieces and see which one is causing the problem? You can bisect the patch by taking its first half and applying only that and see if you can reproduce the error. If yes, take the applied half and cut it in half itself. Otherwise, the the non-applied half and cut that in half and try to continue doing this until the patch is small enough that we can debug it sanely.
Thanks!
Comment 16•12 years ago
|
||
Sure, I will find out.
Assignee | ||
Comment 17•12 years ago
|
||
+++ b/content/base/src/nsCrossSiteListenerProxy.cpp
@@ -3,6 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include <algorithm>
+
#include "nsCrossSiteListenerProxy.h"
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
I think we want to keep #include X.h first in X.cpp, so please add
the new #include after it, like so:
#include "nsCrossSiteListenerProxy.h"
+#include <algorithm>
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
Comment 18•12 years ago
|
||
Mochitest and xpcshell tests fail on same cases with and without this patch. No new failures are introduced due to this patch. All occurrences of NS_MIN, NS_MAX and their definitions are removed and replaced with std::min, std::max respectively.
Attachment #667666 -
Attachment is obsolete: true
Reporter | ||
Comment 19•12 years ago
|
||
(In reply to comment #18)
> Created attachment 668969 [details] [diff] [review]
> --> https://bugzilla.mozilla.org/attachment.cgi?id=668969&action=edit
> full replace of NS_MIN, NS_MAX with std::min and std::max respectively, removed
> defnition of NS_MIN, NS_MAX
>
> Mochitest and xpcshell tests fail on same cases with and without this patch.
> No new failures are introduced due to this patch. All occurrences of NS_MIN,
> NS_MAX and their definitions are removed and replaced with std::min, std::max
> respectively.
Can you please link to a try server run for this patch? Also, is it ready for review? :-)
Comment 20•12 years ago
|
||
(In reply to Ehsan Akhgari [:ehsan] from comment #19)
> Can you please link to a try server run for this patch? Also, is it ready
> for review? :-)
Sorry, I don't understand, what is link to a try server run for this patch?
Ans, yes, please review. (Note to self: Remember to ask! :) )
Reporter | ||
Comment 21•12 years ago
|
||
(In reply to Venkatesh from comment #20)
> (In reply to Ehsan Akhgari [:ehsan] from comment #19)
> > Can you please link to a try server run for this patch? Also, is it ready
> > for review? :-)
>
> Sorry, I don't understand, what is link to a try server run for this patch?
Oh, sorry, please see https://wiki.mozilla.org/ReleaseEngineering/TryServer to get familiar with the try server. I can push your patch to the try server to get build and test results across all platforms. Actually, I tried to do that, but it seems like your patch was based on an older version of mozilla-central and I got a lot of conflicts when trying to apply it. Can you please update your patch to try to get it to apply cleanly on the current tip of mozilla-central?
> Ans, yes, please review. (Note to self: Remember to ask! :) )
No problem, I'll review your patch once you attach an updated version of it as I mentioned above.
Comment 22•12 years ago
|
||
I got the url: https://tbpl.mozilla.org/?tree=Try&rev=9c48fe2fb6cf after pushing to the try server. Is this the link to the try server you were talking about?
Comment 23•12 years ago
|
||
Try run for 9c48fe2fb6cf is complete.
Detailed breakdown of the results available here:
https://tbpl.mozilla.org/?tree=Try&rev=9c48fe2fb6cf
Results (out of 75 total builds):
success: 59
warnings: 4
failure: 12
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/venkateshpitta@gmail.com-9c48fe2fb6cf
Comment 24•12 years ago
|
||
Try run for 9c48fe2fb6cf is complete.
Detailed breakdown of the results available here:
https://tbpl.mozilla.org/?tree=Try&rev=9c48fe2fb6cf
Results (out of 76 total builds):
success: 59
warnings: 4
failure: 13
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/venkateshpitta@gmail.com-9c48fe2fb6cf
Reporter | ||
Comment 25•12 years ago
|
||
(In reply to Venkatesh from comment #22)
> I got the url: https://tbpl.mozilla.org/?tree=Try&rev=9c48fe2fb6cf after
> pushing to the try server. Is this the link to the try server you were
> talking about?
Yes, precisely. If you look at the logs for the red build (B) jobs there, you can see the compilation errors.
Updated•12 years ago
|
Attachment #668969 -
Attachment is patch: true
Comment 26•12 years ago
|
||
Try run for 48802890bd51 is complete.
Detailed breakdown of the results available here:
https://tbpl.mozilla.org/?tree=Try&rev=48802890bd51
Results (out of 143 total builds):
success: 116
warnings: 12
failure: 15
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/venkateshpitta@gmail.com-48802890bd51
Comment 27•12 years ago
|
||
Incremental build was not complaining, but this time I did clean and then make. ~/mozilla-central/xpcom/string/public/* and ~/mozilla-central/xpcom/glue/* don't compile. The error messages always point to algorithm. nsVersionComparator.cpp returns error: #error "STL code can only be used with infallible ::operator new()" when using std::min/max. The other messages, I think, mean this same thing.
I found https://bugzilla.mozilla.org/show_bug.cgi?id=779473 when looking around. The error message is same.
I don't know how to get the build/test on try server pass on OS X and Windows. What can be done?
Assignee | ||
Comment 28•12 years ago
|
||
I'm guessing the error comes from line 36 here:
http://dxr.mozilla.org/mozilla-central/--GENERATED--/dist/stl_wrappers/algorithm.html
I don't think we can include <algorithm> in those files... the problem is
(I think) some files are compiled twice, once with the condition on line
33 true, and once false, to build different DLLs.
We probably need to continue using NS_MAX in those files, but we should
#ifdef them in nsAlgorithm.h in that case to prevent accidental use.
Reporter | ||
Comment 29•12 years ago
|
||
Yeah I agree with comment 28.
Assignee | ||
Comment 30•12 years ago
|
||
Venkatesh, are you still working on this? How can we help?
Assignee | ||
Comment 31•12 years ago
|
||
Assignee: nobody → matspal
Attachment #668969 -
Attachment is obsolete: true
Attachment #691116 -
Flags: review?(ehsan)
Assignee | ||
Comment 32•12 years ago
|
||
Attachment #691118 -
Flags: review?(ehsan)
Assignee | ||
Comment 33•12 years ago
|
||
Attachment #691119 -
Flags: review?(ehsan)
Assignee | ||
Comment 34•12 years ago
|
||
Attachment #691120 -
Flags: review?(ehsan)
Assignee | ||
Comment 35•12 years ago
|
||
Attachment #691123 -
Flags: review?(ehsan)
Assignee | ||
Comment 36•12 years ago
|
||
I guess we could also use std::min/max in some xpcom/ files that doesn't
trigger the error described in comment 28. But it was simpler to just
let xpcom/ continue to use our own template for now (renamed). We can
convert those files later if we want.
Reporter | ||
Comment 37•12 years ago
|
||
Comment on attachment 691116 [details] [diff] [review]
part 1, (scripted) Replace NS_MIN/NS_MAX with std::min/std::max and #include <algorithm> where needed
Review of attachment 691116 [details] [diff] [review]:
-----------------------------------------------------------------
r=me if this builds! :-)
(I didn't review this very carefully, please let me know if you want me to.)
Attachment #691116 -
Flags: review?(ehsan) → review+
Reporter | ||
Comment 38•12 years ago
|
||
Comment on attachment 691118 [details] [diff] [review]
part 2, (scripted) Replace NS_MIN/NS_MAX in xpcom/ with XPCOM_MIN/XPCOM_MAX to prevent accidental use
Review of attachment 691118 [details] [diff] [review]:
-----------------------------------------------------------------
This seems like a necessary evil...
Attachment #691118 -
Flags: review?(ehsan) → review+
Reporter | ||
Comment 39•12 years ago
|
||
Comment on attachment 691119 [details] [diff] [review]
part 3, On OSX, one of the system header files (exception_defines.h) defines 'try' and 'catch' as macros which breaks @try/@catch
Review of attachment 691119 [details] [diff] [review]:
-----------------------------------------------------------------
</sigh>
Attachment #691119 -
Flags: review?(ehsan) → review+
Reporter | ||
Comment 40•12 years ago
|
||
Comment on attachment 691120 [details] [diff] [review]
part 4, On Windows, windef.h defines 'min' and 'max' as macros which breaks any use of std::min/std::max
Review of attachment 691120 [details] [diff] [review]:
-----------------------------------------------------------------
I guess we can modify the build system to pass that flag unconditionally but I don't feel very strongly (and this won't be the first place in our code where we do this anyways.)
r=me
Attachment #691120 -
Flags: review?(ehsan) → review+
Reporter | ||
Updated•12 years ago
|
Attachment #691123 -
Flags: review?(ehsan) → review+
Assignee | ||
Comment 41•12 years ago
|
||
(In reply to Ehsan Akhgari [:ehsan] from comment #37)
> r=me if this builds! :-)
I had a full green run earlier today:
https://tbpl.mozilla.org/?tree=Try&rev=31f918566284
I updated the tree and re-ran the scripted parts just before asking
for review - just a quick build+crashtest to verify it's still green:
https://tbpl.mozilla.org/?tree=Try&rev=deb3828a1ee6
(looks good so far)
> (I didn't review this very carefully, please let me know if you want me to.)
You can skip most of it, but please review js/xpconnect/src/qsgen.py
and confirm that std::max (and "#include <algorithm>") makes sense for
the js/xpconnect/ files.
(btw, I'll attached a comm-central patch soon too...)
Reporter | ||
Comment 42•12 years ago
|
||
(In reply to Mats Palmgren [:mats] from comment #41)
> > (I didn't review this very carefully, please let me know if you want me to.)
>
> You can skip most of it, but please review js/xpconnect/src/qsgen.py
> and confirm that std::max (and "#include <algorithm>") makes sense for
> the js/xpconnect/ files.
Yeah they're fine.
Assignee | ||
Comment 43•12 years ago
|
||
(In reply to Ehsan Akhgari [:ehsan] from comment #40)
> I guess we can modify the build system to pass that flag unconditionally
I actually tried that approach first... but we use the min/max macros
in a few places, and unfortunately (at least) one of those hit the #error
in our wrapped <algorithm> as described in comment 28.
But yeah, I agree that a global "OS_CXXFLAGS += -DNOMINMAX" and working
around that in a few places would be better. (I'll file a follow-up bug)
Assignee | ||
Comment 44•12 years ago
|
||
Attachment #692780 -
Flags: review?(ehsan)
Assignee | ||
Comment 45•12 years ago
|
||
(scripted, no need to review in detail)
Attachment #692781 -
Flags: review?(ehsan)
Assignee | ||
Comment 46•12 years ago
|
||
Attachment #692783 -
Flags: review?(ehsan)
Reporter | ||
Updated•12 years ago
|
Attachment #692780 -
Flags: review?(ehsan) → review+
Reporter | ||
Updated•12 years ago
|
Attachment #692781 -
Flags: review?(ehsan) → review+
Reporter | ||
Updated•12 years ago
|
Attachment #692783 -
Flags: review?(ehsan) → review+
Reporter | ||
Comment 47•12 years ago
|
||
Mats, are you waiting on me for something here?
Assignee | ||
Comment 48•12 years ago
|
||
No thanks, I figured it would be better to land it after the next uplift to avoid
bit-rotting peoples patches, especially since I was away over the holidays.
I'll try to land it towards the end of the week (Jan 11th or so).
Assignee | ||
Comment 49•12 years ago
|
||
Assignee | ||
Comment 50•12 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/037363fa0258
https://hg.mozilla.org/integration/mozilla-inbound/rev/b9d9fc98561b
https://hg.mozilla.org/integration/mozilla-inbound/rev/04fb583963dc
https://hg.mozilla.org/integration/mozilla-inbound/rev/b59c92bc4059
https://hg.mozilla.org/integration/mozilla-inbound/rev/c26871bd5f5e
I'll announce this change in dev.platform as soon as the build looks green.
Assignee | ||
Comment 51•12 years ago
|
||
Filed bug 830801 on (maybe) making -DNOMINMAX the default on Windows.
Comment 52•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/037363fa0258
https://hg.mozilla.org/mozilla-central/rev/b9d9fc98561b
https://hg.mozilla.org/mozilla-central/rev/04fb583963dc
https://hg.mozilla.org/mozilla-central/rev/b59c92bc4059
https://hg.mozilla.org/mozilla-central/rev/c26871bd5f5e
https://hg.mozilla.org/mozilla-central/rev/9a7f61363efe
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla21
Comment 53•12 years ago
|
||
Comment on attachment 692783 [details] [diff] [review]
c-c: part 3, Sprinkle a few -DNOMINMAX and fix uses of std::min with mixed 32/64-bit types
[Surprised this doesn't give you any 64->32bit truncation warnings]
>+ rv = aOutStream->WriteFrom(mInStream, std::min(avail, uint64_t(4096)), &bytesWritten);
4096ULL?
Assignee | ||
Comment 54•12 years ago
|
||
(In reply to neil@parkwaycc.co.uk from comment #53)
> [Surprised this doesn't give you any 64->32bit truncation warnings]
I don't see any in my Clang/Linux64 build. File a new bug if you see them.
> 4096ULL?
nsMsgProtocol.cpp:1086:72: error: no matching function for call to ‘min(uint64_t&, long long unsigned int)’
You need to log in
before you can comment on or make changes to this bug.
Description
•