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
git_array_alloc: return objects of correct type #6008
Conversation
(((a).size >= (a).asize) ? \ | ||
git_array_grow(&(a), sizeof(*(a).ptr)) : \ | ||
((a).ptr ? &(a).ptr[(a).size++] : (void *)NULL)) | ||
(((a).size < (a).asize || git_array_grow(&(a), sizeof(*(a).ptr)) == 0) ? \ |
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.
wow this macro is getting unwieldly 😛
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.
Functionally it would be possible to move the first size-comparison into the the grow-function now, then it will be pretty close to the other macros.
But since inlining relies on compiler extensions for C89 I'd rather keep it where it is since that will prevent git_array_grow from being called most of the time when inlining doesn't work.
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.
Sorry, that was more a comment than a criticism. 😁 Thanks for tackling this, these are nice improvements.
I think that this makes sense. I'm a little surprised that there's only the one user of |
Everyone calls |
(fixes issue libgit2#6008) Signed-off-by: Sven Strickroth <email@cs-ware.de>
(fixes issue libgit2#6008) Signed-off-by: Sven Strickroth <email@cs-ware.de>
(fixes issue libgit2#6008) Signed-off-by: Sven Strickroth <email@cs-ware.de>
Unlike other array macros git_array_alloc would return a void pointer when an object needed to be allocated.
By changing git_array_grow to only grow the array and make the actual allocation in the git_array_alloc macro the returned type will always be correct.