Skip to content
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

clean up genalloc implementation #128

Merged
merged 8 commits into from May 19, 2020
Merged

clean up genalloc implementation #128

merged 8 commits into from May 19, 2020

Conversation

DerDakon
Copy link
Member

@DerDakon DerDakon commented May 8, 2020

This code is best described as 90ies style function templates in C. This reduces the code duplication between the *_readyplus and *_ready functions, which only differ slightly. Then the code is a bit de-obfuscated. I have used the additional unittest now in #102 to verify that things still behave the same.

@notqmail notqmail deleted a comment from mbhangui May 9, 2020
@DerDakon DerDakon force-pushed the Dakon-genalloc-cleanup branch 5 times, most recently from 2cf90ea to aeab30e Compare May 14, 2020 16:00
@DerDakon DerDakon added this to the 1.08 milestone May 18, 2020
gen_allocdefs.h Outdated Show resolved Hide resolved
gen_allocdefs.h Outdated Show resolved Hide resolved
ipalloc.c Show resolved Hide resolved
This only moves the code blocks, but does not change any code at all.
Make sure calls to GEN_ALLOC_ready always follow GEN_ALLOC_readyplus.
Introduce an internal static helper function that does the common parts, which
both functions can use.
While at it drop the register specification.
The names of the function parameters as well as the name of the local variable
were taken from the macro arguments. Noone passed anything different than the
default names there, and doing so doesn't make any sense anyway.
stralloc_eady.c Outdated Show resolved Hide resolved
gen_allocdefs.h Show resolved Hide resolved
gen_allocdefs.h Outdated Show resolved Hide resolved
gen_allocdefs.h Outdated Show resolved Hide resolved
gen_allocdefs.h Outdated Show resolved Hide resolved
ipalloc.c Show resolved Hide resolved
Save the new length in a local variable, and only change the value in the struct
if allocation succeeds instead of changing it back on failure.
This was doing 2 assignments, a function call and a return on the same line.
This had the additional slight bug that if the allocation failed it returned 0,
but the allocation length in the struct passed in was already changed to the new
value. This would not do any harm on subsequent calls as the pointer was still
NULL and only that is checked.
alloc() is used in the generated code, so directly include it in this header
instead of all the callers.
@DerDakon DerDakon merged commit edf54c8 into master May 19, 2020
@DerDakon DerDakon deleted the Dakon-genalloc-cleanup branch May 19, 2020 13:11
mbhangui added a commit to indimail/libqmail that referenced this pull request May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants