Skip to content

Add missing malloc.h include - #131

Open
CaiB wants to merge 1 commit into
cntools:masterfrom
CaiB:master
Open

Add missing malloc.h include#131
CaiB wants to merge 1 commit into
cntools:masterfrom
CaiB:master

Conversation

@CaiB

@CaiB CaiB commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

CNFGOGL.c uses alloca on line 235, however does not import malloc.h, where that is defined. This causes issues in downstream applications like colorchord, where it surfaces as a call to an undeclared function. This PR just adds the missing include.

@CaiB

CaiB commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

So apparently malloc.h effectively doesn't exist on macOS, alloca is defined in alloca.h on Linux and macOS systems, or you can implicitly get it via stdlib.h when using glibc (GCC) or macOS. On Windows, it's in malloc.h, not in stdlib.h, and alloca.h doesn't exist. What an absolute mess.

I'm going to back away slowly and let someone else handle this...

@whyvn

whyvn commented Aug 11, 2026

Copy link
Copy Markdown

I'm going to back away slowly and let someone else handle this...

lol yea it does seem messy but it kinda makes sense since alloca isnt standardized at all. at least the unixy systems have it bundled with stdlib.h. this resolves my confusion as to why you got that compile error before and i didnt (because i assume you are on windows and im on linux).

i guess its fine for it to be messy since it shouldnt be used for platform independent code anyway, and im not too sure why its used here but if it must be kept then maybe a simple preprocessor branch for if the platform os is windows or macos or linux to include the correct libraries? the best solution would be to remove calls to alloca entirely though

@CaiB

CaiB commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

That's pretty unfortunate for such a basic and useful function. I understand it requires compiler-specific implementation, but no standardization at all is rough. I use the equivalent in C# all the dang time, and plenty in C as well (on the odd occasion I find myself writing C).

I'm guessing an #ifdef-based platform-gated header include is the way this'll go, but I'll let @cnlohr decide that since I don't really involve myself in rawdraw much, and he's got much better insight into where and how it's used to inform tradeoffs.

@whyvn

whyvn commented Aug 11, 2026

Copy link
Copy Markdown

ok so ive looked at all the call sites of alloca and it seems like most of the times its using alloca to avoid being dependent on malloc. i think maybe there could be a toggleable USE_MALLOC macro then switch out calls to alloca and malloc (and free) accordingly.

the other calls to alloca (the ones that werent used to avoid the reliance on malloc) they can be replaced by normal c array declaration syntax

@whyvn

whyvn commented Aug 11, 2026

Copy link
Copy Markdown

That's pretty unfortunate for such a basic and useful function. I understand it requires compiler-specific implementation, but no standardization at all is rough. I use the equivalent in C# all the dang time, and plenty in C as well (on the odd occasion I find myself writing C).

I'm guessing an #ifdef-based platform-gated header include is the way this'll go, but I'll let @cnlohr decide that since I don't really involve myself in rawdraw much, and he's got much better insight into where and how it's used to inform tradeoffs.

ah i didnt see your reply before sending my reply sorry lol. but yea im with you

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.

2 participants