higan-emu / libco

libco is a cooperative multithreading library written in C89.
Other
125 stars 25 forks source link

Made the dependency on stdlib.h and assert.h optional #10

Closed namandixit closed 4 years ago

namandixit commented 4 years ago

This PR will make it possible for users to provide their own malloc(), free() and assert() wrappers. This means that using this library on Windows (if one plans on shipping without MSVCRT Redist) or on embedded platforms (without a libc) will be easier.

The dependency on mman.h, windows.h and unistd.h are not touched, since I can't see why one might not want to use them on the relevant platforms. stdint.h is also left in since it only provides type definitions and not any functions.

The dependencies are still mandatory in the following files:

  1. sjlj.c: setjmp/longjmp are libc features anyway
  2. ucontext.c: No reason not to link to libc on POSIX systems
  3. ppc.c: Still uses string.h for memcpy. Since memcpy is usually a compiler intrinsic with some spec-mandated magical behaviour, not sure if it's technically safe to override it.
Screwtapello commented 4 years ago

This makes sense to me, but I think the repeated stanza about #if !defined(LIBCO_...) should go into settings.h, where people who want to customise libco might look for settings.

Also, __VA_ARGS__ is apparently C99, while the rest of the codebase is (according to the README) C89. However, I don't know if that's a problem in practice. If you're working on embedded systems, you probably know more about the quirks of niche toolchains than I do.

namandixit commented 4 years ago

Oh yeah, it should go into settings.h. And you are right about __VA_ARGS__ too (we don't really need it, I guess I should stop being cheeky :)

namandixit commented 4 years ago

Should be good to go now

Screwtapello commented 4 years ago

That's a thumbs-up from me, but I'll wait a day or so to see if any other maintainers have any objections before hitting the button.

namandixit commented 4 years ago

Is there anything blocking this PR?

Kawa-oneechan commented 4 years ago

Nah, not really.