-
Notifications
You must be signed in to change notification settings - Fork 8k
Add pmalloc API #19675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
iluuu1994
wants to merge
6
commits into
php:master
Choose a base branch
from
iluuu1994:pmalloc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+150
−139
Draft
Add pmalloc API #19675
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4f97664
Add pmalloc API
iluuu1994 7b087e5
Add pcalloc API
iluuu1994 661b01f
Add prealloc API
iluuu1994 f1a68c4
Add returns_nonnull attribute to pmalloc API
iluuu1994 ec215d6
Fix missing header
iluuu1994 8406626
Revert bison changes
iluuu1994 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we take the opportunity of the churn to also avoid repeating the type unnecessarily?
see: https://github.com/haproxy/haproxy/blob/master/dev/coccinelle/xalloc_size.cocci
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.
I don't usually use the
sizeof(*ht)
style, and I don't think most people do. I don't particularly care, but I think moving towards one style only makes sense if it becomes policy. Maybe suggest it on Slack first?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.
We are not going to change all such usage so I would prefer to stick with full types. I find it also more readable.
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 “we are not going to”?
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.
I'm not sure if you meant doing just for pmalloc of changing every single sizeof.
If former, then I don't think there is much point in creating inconsistency that is less readable. If latter, you don't get full agreement as it would be a big churn so you would probably have to go through RFC which is not exactly meant for internal changes like this. It reminds me those header includes refactoring where we ended up not having any process to decide it.
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.
This is what I'm most interested in. It's hard to remember rules, and it's even harder for everyone to remember all rules. IMO, guidelines are most useful when they are enforced, even if only for the 95% cases. At least that helps you internalize the rules.
Regardless, I think such a decision would need discussion, though I fully acknowledge there's no good channel to do so. I think Slack (e.g. #php-src) would make the most sense.
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.
But it's a still delay to check it, edit and commit for something that has no value and is not even an improvement.
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.
It depends on the change. There's a non-trivial amount of time spent in PRs discussing the same nits (e.g. prefer
/* */
over//
, though I have no idea whether these kinds of things are solvable with Coccinelle).Uh oh!
There was an error while loading. Please reload this page.
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.
That example would probably rather be clang-format. I believe Coccinelle can also deal with comments, but the intended use case is making changes to the code based on type and control-flow information with a convenient syntax that resembles a patch file and thus is easy to grok even for less experienced users.
To use
malloc()
as an example:This defines placeholders of an arbitrary type
T
and a variablex
that is a pointer toT
. It then searches for constructsx = malloc(sizeof(T))
and replaces thesizeof(T)
bysizeof(*x)
.For a C program:
running that Coccinelle patch would make the following changes:
If we now wanted to find places where the types differ, we could use the following patch:
The
*
is an indicator to just “highlight” the match and not perform any replacement. We define an additional typeU
and then define multiple alternatives. For the correct variantssizeof(T)
andsizeof(*x)
nothing is reported. Forsizeof(U)
(where U != T, since T was already handled), a report is created: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.
Coccinelle works very well and is easy to use. I've used it a few times and it's been battle tested against the Linux kernel, which isn't particularly known for it's consistent coding style and is known for it's complex macros etc.
I'm in favor to use the malloc sizeof pattern Tim proposes, and if we don't want to convert existing code (which I think we should), we should at least use that pattern for new code.