apache / arrow

Apache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics
https://arrow.apache.org/
Apache License 2.0
14.66k stars 3.56k forks source link

[C++] Better handling `mem*` api that behave sanely on NULL input #44814

Open mapleFU opened 4 days ago

mapleFU commented 4 days ago
          I think we take a systematic approach to this and make wrappers to `mem*` functions that behave sanely on `NULL` input.

This article [1] discusses the issue in detail and points to approaches taken by projects like boringssl. [2] There is also a proposal from prolific LLVM contributors for fixing this at the C standard level. [3]

[1] https://davidben.net/2024/01/15/empty-slices.html [2] https://boringssl.googlesource.com/boringssl/+/17cf2cb1d226b0ba2401304242df7ddd3b6f1ff2%5E%21/ [3] https://docs.google.com/document/d/1guH_HgibKrX7t9JfKGfWX2UCPyZOTLsnRfR6UleD1F8/edit?tab=t.0

Originally posted by @felipecrv in https://github.com/apache/arrow/issues/44794#issuecomment-2494059369

felipecrv commented 4 days ago

Make the wrappers inlineable (defined in a header) so the checks can be elided by the compiler when it can be proven at the callsite that the pointer is not null already.

felipecrv commented 4 days ago

Another idea (suggest the wrappers with clang-tidy warnings): https://github.com/apache/arrow/pull/44794#issuecomment-2494959680

mapleFU commented 2 days ago

They can all be applied, let me try this later