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

stb_ds: Fix arrfree when custom allocators are used. #1228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

travisdoor
Copy link

Originally STBDS_FREE macro was used directly in arrfree definition,
this leads to invalid replacement in case custom realloc and free
are specified and arrfree is not used in "implementation" unit.

Originally STBDS_FREE macro was used directly in arrfree definition,
this leads to invalid replacement in case custom realloc and free
are specified and arrfree is not used in "implementation" unit.
@nothings
Copy link
Owner

I don't see any harm in the change, but I don't understand the purpose, as arrfreef is not meant to be replaceable. What is the failure mode?

@travisdoor
Copy link
Author

travisdoor commented Oct 12, 2021

Maybe I used it wrong, my configuration looks like this:

common.c

#define STB_DS_IMPLEMENTATION
#define STBDS_REALLOC(context, ptr, size) bl_realloc(ptr, size)
#define STBDS_FREE(context, ptr) bl_free(ptr)
#include "stb_ds.h"

Now when I use arrfree in common.c file, everything is OK, the original free is replaced with bl_free, however, in other files only including stb_ds.h without any additional defines, I get default free instead of bl_free. So i.e. an array allocated from common.c and freed from a different file causes failure (bl_realloc vs default free).
My small change is just to replace STBDS_FREE in arrfree macro with a function call (having correct free in its implementation).

@nothings
Copy link
Owner

oh, yes. this was fixed before, but i guess it got lost? https://github.com/nothings/stb/pull/1144/files

@travisdoor
Copy link
Author

hmm seems to be lost, or not being present in master

stb/stb_ds.h

Line 551 in af1a5bc

#define stbds_arrfree(a) ((void) ((a) ? STBDS_FREE(NULL,stbds_header(a)) : (void)0), (a)=NULL)

@nothings
Copy link
Owner

yep, it's clear from the diff for your PR (in the "files changed" tab) that it's missing now

@aschuhardt
Copy link

Can this be merged?

@nothings
Copy link
Owner

yes, it will be, sorry, i don't update very often since the pandemic started

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants