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

STBDS_FREE is used outside of STB_DS_IMPLEMENTATION causing custom implementation to be replaced by free(). #1632

Open
guifes opened this issue Apr 13, 2024 · 1 comment

Comments

@guifes
Copy link

guifes commented Apr 13, 2024

Describe the bug
I've tried replacing STBDS_REALLOC and STBDS_FREE as instructed in the comments but I think I found a tiny bug. Since STBDS_FREE is used in stb_ds.h outside of the implementation code, it gets replaced by <stdlib.h> free instead of my custom replacement for the other source files that don't have STB_DS_IMPLEMENTATION defined.

To Reproduce
Steps to reproduce the behavior:

  1. Add stb_ds.h to a project overriding STBDS_FREE and STB_DS_IMPLEMENTATION in a source file
  2. On another source file, #include "stb_ds.h" and try to use arrfree in a context where it makes sense.
  3. Check the intermediary .i file and see that arrfree is gonna be replaced with an expression that contains <stdlib.h> free instead of your custom implementation.

Expected behavior
Since the point of redefining STBDS_REALLOC and STBDS_FREE is to have your custom allocation code be run always, there should be no exceptions such as this one.

@guifes guifes changed the title [stb_ds.h] STBDS_FREE is used outside of STBDS_IMPLEMENTATION causing custom implementation to be replaced by free(). [stb_ds.h] STBDS_FREE is used outside of STB_DS_IMPLEMENTATION causing custom implementation to be replaced by free(). Apr 13, 2024
@nothings
Copy link
Owner

Yes, looking at the code this does seem to be a bug.

@guifes guifes changed the title [stb_ds.h] STBDS_FREE is used outside of STB_DS_IMPLEMENTATION causing custom implementation to be replaced by free(). STBDS_FREE is used outside of STB_DS_IMPLEMENTATION causing custom implementation to be replaced by free(). Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants