The strdup family of functions rely on malloc to be implemented.
Its presence in the string_utils.h header meant that compiling many of
the string functions relied on malloc being implementated as well.
This patch simply moves the implementation into a new file to avoid
including stdlib.h from the other string functions. This was a barrier
for compiling string functions for the GPU where there is no malloc
currently.
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
I would think that GPU is one example of a platform where malloc isn't (yet) available. So, the mechanical aspects of this patch LGTM. I think we should do a few things more:
- At the least, add comments warning developers that allocators should not be called from string_utils.h. Likewise, add comments explaining what exactly is string_utils_malloc.h (or whatever it will be called) for.
- Does not have to be done in this patch, but would be nice if a developer mistake/mixup can be caught during build + test cycle. Worst case, the GPU builder will catch it I believe, but would be nice to be able to do it during a normal host build + test development cycle.
libc/src/string/string_utils_malloc.h | ||
---|---|---|
1 ↗ | (On Diff #477594) | malloc is one among a bunch of standard allocator functions. So, may be call this allocating_string_utils.h? |
Comment Actions
You should add another header library for the new header file like this: https://github.com/llvm/llvm-project/blob/main/libc/src/string/CMakeLists.txt#L3. Otherwise LGTM.