Closed Bug 802473 Opened 13 years ago Closed 13 years ago

NS_FAILED returns values other than 0 and 1; NS_FAILED/NS_SUCCEEDED should use branch prediction macros

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla19

People

(Reporter: MatsPalmgren_bugz, Assigned: MatsPalmgren_bugz)

References

Details

(Keywords: perf, regression)

Attachments

(1 file, 1 obsolete file)

Bug 768865 removed "defined(NS_STATIC_CHECKING)" so that a faulty version of NS_FAILED is now used for all C++ code. There are two problems: 1. Assigning NS_FAILED(an_error) to an integral type gives the wrong result. Assigning to a variable of narrower type results in zero, assigning to a same or wider type it's non-zero but still wrong (0x80000000). The result should be 1, as documented in the file. 2. Since the result of NS_FAILED/NS_SUCCEEDED is very likely to be 0/1 we should use NS_LIKELY/NS_UNLIKELY to indicate so. I'm surprised bug 768865 didn't cause a performance regression, but perhaps PGO wallpapers over it? Since NS_LIKELY/NS_UNLIKELY returns exactly 0 or 1, we get point 1 for free.
Attached patch fix (obsolete) — Splinter Review
This fixes point 1 and 2 above, and still keeps the desirable type check that bug 768865 was after, IIUC. It appears to be green on Try: https://tbpl.mozilla.org/?tree=Try&rev=d715a0990034
Attachment #672149 - Flags: review?(ayg)
Comment on attachment 672149 [details] [diff] [review] fix >-inline int NS_FAILED(nsresult _nsresult) { >+inline int _NS_FAILED(nsresult _nsresult) { Don't use underscore + uppercase. It is always reserved in C/C++.
Comment on attachment 672149 [details] [diff] [review] fix Review of attachment 672149 [details] [diff] [review]: ----------------------------------------------------------------- stealing the review. Please call the underlying function/macro something like NS_FAILED_impl.
Attachment #672149 - Flags: review?(ayg) → review+
Also, out of curiosity, how did you find out about this?
Why is this an int and not a bool return value?
It shouldn't be. I thought I changed it to bool in some patch of mine somewhere along the line, but it seems I didn't.
ok, can you make them bools?
Attached patch fix, v2Splinter Review
> Please call the underlying function/macro something like NS_FAILED_impl. Fixed. > ok, can you make them bools? Fixed. NS_FAILED_impl isn't supposed to be called directly so I made it return uint32_t to avoid any unnecessary cycles spent before giving the value to NS_LIKELY.
Assignee: nobody → matspal
Attachment #672301 - Flags: review?(benjamin)
Attachment #672301 - Flags: review?(benjamin) → review+
(In reply to Ehsan Akhgari [:ehsan] from comment #4) > Also, out of curiosity, how did you find out about this? The background is that I investigated this exact problem with assigning the result of NS_FAILED in bug 340244 a few years back. It caused a test to fail because of an assignment to a PRUint8 (see bug 340244 comment 5 for all the gory details). Then I stumbled over bug 801464 and got curious what NS_FAILED looked like nowadays after the nsresult enum changes, and when I saw it I knew instantly that it was broken.
Attachment #672149 - Attachment is obsolete: true
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: