Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert _str() from inline to a macro and make it return
(const str *), not (str *). This is to limit potential damage from its (mis)use in non-testing modules code by first making its value stored locally at point of use (which should allow compiler to throw it away when used properly) and also provide at least some protection from any function from messing with its fields. Fix any fallout where str * has been passed around.
- Loading branch information
Showing
7 changed files
with
20 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0147baa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "which should allow compiler to throw it away when used properly"? What's a proper way to use a simple string casting macro, after all?
I agree that it's helpful to prevent programmer mistakes going in the future, where someone may abuse
_str()
and run into tough-to-debug, weird bugs. However, note how this comes with a cost, too. By re-defining a static holder on each invocation of the macro, we are increasing the size of various binaries. For example, this commit immediately causes a 0.06% increase in the size of the usrloc.so binary (from 1565672 bytes to 1566720).All in all, I think it's better to do the commit and live with the size penalty, than to keep the current, hyper-optimized, error-prone version of it. Long-live OpenSIPS development! :)
0147baa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @liviuchircu for a feedback! I will probably retract my comment on "when used properly", it does not hold water. The compiler is still storing that pointer even if it clearly not used anywhere. :(
With regards to the size increase, don't worry about it much. It will actually go down once those _str() calls are converted into str_const. Consider the following code blocks for example:
It compiles into almost identical code, except foo_const() does not have any memory operarions to store reference to "abcdedf1" or its length! That's what I am saying as "compiler throws it away". So by changing your usrloc code to use const_str() instead you would not only produce smaller code but it also would run considerably faster!