Closed Bug 372971 Opened 18 years ago Closed 6 years ago

Convert macros to inline functions

Categories

(Core :: General, defect)

x86
All
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: taras.mozilla, Assigned: taras.mozilla)

References

Details

Attachments

(2 files, 5 obsolete files)

PR_MAX|MIN, and similar functions can cause unintended code expansion and make automated analysis more difficult. Other macros contain large amounts of code and also prevent parsing tools from refactoring code.
Assignee: tglek → nobody
Product: Firefox → Core
QA Contact: general → general
Can't you define some additional PR_MIN/PR_MAX overloads so that (float,int) combinations work without requiring caller changes?
Attached file Overloaded min/max functions (obsolete) —
The patch is a bit smaller after providing the overloads. It would be even smaller if there were overloads to mix signed/unsigned types, but that seems like a bad idea.
Assignee: nobody → tglek
Attachment #257705 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Use constructor-style casts instead of C-style casts. + PRInt32 beginIn = PR_MAX(0ll, blockOffset - p->mOffset); + PRInt32 beginOut = PR_MAX(0ll, p->mOffset - blockOffset); Could you use constructor casts here instead? 0ll looks really strange to me and looks a lot like 011. The only other thing I'm worried about is whether we can change stuff in nsprpub. I'm not sure who owns that actually.
0LL is more legible. /be
I still don't have a good idea on how to deal with the NS_IMPL_HTMLBODY_COLOR_ATTR macro in nsHtmlBodyElement.cpp. Should we just leave it and hope that squash doesn't run into problems with it?
It gets used 4 times. Why don't you just create the 8 generated functions explicitly. For the Get versions, you can use a helper function that takes the attribute nsIAtom* and the default nsColor, so each Get implementation is just NS_IMETHODIMP nsHTMLBodyElement::GetVLink(nsAString& aColor) { return GetColorHelper(nsGkAtoms::vlink, GetPresContext()->DefaultVisitedLinkColor(), aColor); }
Comment on attachment 257712 [details] [diff] [review] Overloaded min|max. used -u this time If this patch requires adding the typecasts to some of the arguments to PR_MAX and PR_MIN, this will break "source compatibility". Many products other than the Mozilla clients use NSPR, and some of them are also C++ applications. Could you come up with a patch that maintain source compatibility?
That's not really possible as far as I know. Can we have some kind of configure option that enables this feature for Mozilla but is off by default?
Use 0LL instead of 0ll, static casts. Changed PR_ABS to be a function too. Using typedefs instead of underlying types in the definitions.
Attachment #257712 - Attachment is obsolete: true
(In reply to comment #10) > That's not really possible as far as I know. Can we have some kind of configure > option that enables this feature for Mozilla but is off by default? > Or we could change PR_MAX|MIN in the source code to call a function with a new name instead... Such as the std:: C++ one. But I guess that's more of a Mozilla 2 scope.
Not sure if the helper method needs to be private too.
Comment on attachment 257776 [details] [diff] [review] nsHTMLBodyElement macro expansion + if (!aElement->GetAttr(kNameSpaceID_None, aAtom, color)) { + NS_RGBToHex(defaultAttrColor, aColor); Fix indent Make GetColorHelper just be a nonvirtual method that returns nsresult, not an NS_IMETHOD (that makes it virtual which is unnecessary). Yes, make it private too.
Attachment #257776 - Flags: superreview+
Attachment #257776 - Flags: review+
Fixed indent, changed signature. I accidentally left an extra parameter in the last patch, that's gone now.
Attachment #257776 - Attachment is obsolete: true
Landed attachment 257778 [details] [diff] [review] on the trunk. mozilla/content/html/content/src/nsHTMLBodyElement.cpp 1.162
Depends on: 373589
Attached patch missing null check (obsolete) — Splinter Review
Missed a null check
Attachment #257778 - Attachment is obsolete: true
Comment on attachment 258470 [details] [diff] [review] missing null check This is very wrong
Attachment #258470 - Attachment is obsolete: true
Probably not relevant anymore (and the wrong component)
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: