<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
</head>
<body dir="ltr">
<div dir="auto" style="direction:ltr; margin:0; padding:0; font-family:sans-serif; font-size:11pt; color:black">
> vasprintf have different return codes on different systems.<br>
<br>
</div>
<div dir="auto" style="direction:ltr; margin:0; padding:0; font-family:sans-serif; font-size:11pt; color:black">
Forget this. I was mixing up with the other  function that calculates how many chars a xxxprintf function would write, which we use to implement vasprintf.<br>
<br>
</div>
<div dir="auto" style="direction:ltr; margin:0; padding:0; font-family:sans-serif; font-size:11pt; color:black">
Jose</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Jose Fonseca<br>
<b>Sent:</b> Wednesday, November 21, 2018 8:16:35 PM<br>
<b>To:</b> Ian Romanick; Eric Engestrom; mesa-dev@lists.freedesktop.org<br>
<b>Cc:</b> Brian Paul; Roland Scheidegger; Neha Bhende; Charmaine Lee<br>
<b>Subject:</b> Re: [Mesa-dev] [PATCH mesa 00/13] Make standard function available on non-standard platforms</font>
<div> </div>
</div>
<div>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0; margin-bottom:0">>   util: use standard name for strncat()<br>
</p>
<p style="margin-top:0; margin-bottom:0">>   util: use standard name for strncmp()<br style="">
>   util: use standard name for strcmp()<br style="">
>   util: use standard name for strchr()<br style="">
>   util: use standard name for sprintf()<br style="">
>   util: use standard name for vasprintf()<br style="">
>   util: use standard name for vsprintf()<br style="">
>   util: use standard name for snprintf()<br style="">
>   util: use standard name for vsnprintf()<br>
</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"></p>
<p style="">Generally I agree with the principle of using standard functions, and provide drop-in replacements for the systems where they are broken.  It leads to less friction, less need to learn new things.</p>
<p style=""><br>
</p>
<p style="">But C string functions is IMO a special case, because the standard functions are so poorly designed, and make writing correct and secure code so dawm difficult:</p>
<p style="">- <span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">snprintf doesn't write the null char</span></p>
<p style=""><span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">- <span>strncat n parameter is awkard to use</span></span></p>
<p style=""><span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">-  </span>vasprintf have different return codes on different systems. 
 According to GNU manpages, it's not even C or POSIX.<span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px"></span></p>
<div><br>
</div>
<p></p>
<p></p>
<p style="margin-top:0; margin-bottom:0"></p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">
And a standard for the sake of standard is just silly.</p>
<div><br>
</div>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">
</p>
<p style="margin-top:0; margin-bottom:0"><span style="font-size:12pt">So IMO, if people care and have the time to uniformize these things, I think they should move away standard C functions, and write some sane C string manipulation abstraction/helpers.  And
 we should make GCC throw warnings every time people try to use the standard C string </span><span style="font-size:12pt">functions.</span></p>
<p></p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">> All of these functions appear to have been added by 131a1fbc91725.  I've<br style="">
added Jose to CC since he wrote it.  [...]  </p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">> That doesn't give much insight. :(<br>
</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">> :(</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">*sigh*</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">The reason for adding was in <span>b1922de9f3478869c6788ef4e954c06c20e7aa9c .  We needed those because XP kernel driver environment didn't provide a complete  CRT.  But we</span> dropped XP kernel support long time ago,
 so that's no longer relevant.</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">I believe the reason these functions became widespread since then was<span style="font-size:12pt"> the fact that MSVC functions didn't follow</span><span style="font-size:12pt"> C99 (e.g., ll), but that might no longer
 be an issue with MSVC 2017 runtime.  This needs to be verified.</span></p>
<p style="margin-top:0; margin-bottom:0"><span></span></p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">Finally there's also the fact that standard snprintf is sensitive to current locale, which is a bad idea for driver code.   I suppose this is not an issue for Linux, which has always used <span>snprintf underneath. 
 But we need to double check all other util_snprintf .  It's possible that the mere fact we statically link CRT is sufficient to protect us from that (since it ends up being like a completely different CRT instant from the application), but I'm not 100% sure.</span></p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">Jose</p>
<br>
<div style="color:rgb(0,0,0)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Ian Romanick <idr@freedesktop.org><br>
<b>Sent:</b> Wednesday, November 21, 2018 18:47<br>
<b>To:</b> Eric Engestrom; mesa-dev@lists.freedesktop.org<br>
<b>Cc:</b> Jose Fonseca<br>
<b>Subject:</b> Re: [Mesa-dev] [PATCH mesa 00/13] Make standard function available on non-standard platforms</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">On 11/20/2018 05:11 AM, Eric Engestrom wrote:<br>
> ... instead of making standard platforms use non-standard functions.<br>
<br>
I haven't looked at the specific patches, so this comment may not apply.<br>
 When we first headed down the path of adding a billion wrapper<br>
functions, I campaigned pretty strongly to give them the standard names.<br>
 The problem is that some platforms have functions with the standard<br>
names that deviate from the standard behavior in ways that make them<br>
unusable.  I think one of the printf-like functions was the main problem<br>
here, but it was a long time ago.<br>
<br>
Either way, you can't give the wrapper the standard name in this case.<br>
Once you have to name one wrapper function _foo_standard_name, you might<br>
as well name them all like that.<br>
<br>
> This also reduces the likelihood of someone forgetting to use the<br>
> non-standard function, and reduces the fix to a simple #include.<br>
<br>
If we cared, I bet we could write a 'make check' test that would just<br>
grep through the tree for functions that are supposed to be wrapped.<br>
The test would fail if a non-wrapped version was used.  We'd probably<br>
have to use Python, so I don't know how much effort it would be.<br>
<br>
> Changes generated using this shell function for each function name:<br>
>   fix() {<br>
>     files=$(ag -lw util_$1)<br>
>     sed s/'\<util_'$1'\>'/$1/g -i $files<br>
>     git add -up $files<br>
>     git commit -sm 'util: use standard name for '$1'()'<br>
>   }<br>
> <br>
> Eric Engestrom (13):<br>
>   util: use standard name for strchrnul()<br>
>   util: use standard name for strcasecmp()<br>
>   util: use standard name for strdup()<br>
>   util: use standard name for strstr()<br>
<br>
What the... ?  strstr is part of C89.  What platform actually needs a<br>
wrapper for this?  I see zero uses in the code base of util_strstr.<br>
Ditto for strdup, strncmp, strcmp, strchr, and possibly others.  I<br>
looked, and Microsoft has strncmp at least as far back as Visual Studio<br>
2012.<br>
<br>
<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Fvisualstudio%2Fvisual-studio-2012%2Feywx8zcx(v%3Dvs.110&amp;data=02%7C01%7Cjfonseca%40vmware.com%7Cc87f73c43298407e4aeb08d64fe1bc31%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636784228289598865&amp;sdata=Gg%2B%2BlQmc4wmh7k0zohBEdUatGjdCkPDnmCOxse6NSFE%3D&amp;reserved=0">https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Fvisualstudio%2Fvisual-studio-2012%2Feywx8zcx(v%3Dvs.110&amp;data=02%7C01%7Cjfonseca%40vmware.com%7Cc87f73c43298407e4aeb08d64fe1bc31%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636784228289598865&amp;sdata=Gg%2B%2BlQmc4wmh7k0zohBEdUatGjdCkPDnmCOxse6NSFE%3D&amp;reserved=0</a>)<br>
<br>
I don't see any of these functions on the list of functions that aren't<br>
always available:<br>
<br>
<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcpp%2Fcppcx%2Fcrt-functions-not-supported-in-universal-windows-platform-apps&amp;data=02%7C01%7Cjfonseca%40vmware.com%7Cc87f73c43298407e4aeb08d64fe1bc31%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636784228289598865&amp;sdata=wcTCCWiMFwy%2BpC0aTP%2FIqWEiv4LUhK%2B0eY0RhDPvu5g%3D&amp;reserved=0">https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcpp%2Fcppcx%2Fcrt-functions-not-supported-in-universal-windows-platform-apps&amp;data=02%7C01%7Cjfonseca%40vmware.com%7Cc87f73c43298407e4aeb08d64fe1bc31%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636784228289598865&amp;sdata=wcTCCWiMFwy%2BpC0aTP%2FIqWEiv4LUhK%2B0eY0RhDPvu5g%3D&amp;reserved=0</a><br>
<br>
All of these functions appear to have been added by 131a1fbc91725.  I've<br>
added Jose to CC since he wrote it.  The whole commit message there is:<br>
<br>
    util: Alternative implementation for standard c library string<br>
    functions.<br>
<br>
That doesn't give much insight. :(<br>
<br>
Give that patch was 10 years ago, some of the wrappers that were needed<br>
in 2008 may not be needed now.  I'd prefer to see wrappers that aren't<br>
needed in 2018 be replaced with the standard functions as a first step.<br>
We can sort out the remainder after that.<br>
<br>
>   util: use standard name for strncat()<br>
>   util: use standard name for strncmp()<br>
>   util: use standard name for strcmp()<br>
>   util: use standard name for strchr()<br>
>   util: use standard name for sprintf()<br>
>   util: use standard name for vasprintf()<br>
>   util: use standard name for vsprintf()<br>
>   util: use standard name for snprintf()<br>
>   util: use standard name for vsnprintf()<br>
> <br>
>  src/amd/common/ac_debug.c                     |  2 +-<br>
>  .../glsl/ir_builder_print_visitor.cpp         |  2 +-<br>
>  src/compiler/glsl/ir_print_visitor.cpp        | 12 ++---<br>
>  src/compiler/glsl/link_interface_blocks.cpp   |  4 +-<br>
>  src/compiler/glsl/linker.cpp                  |  2 +-<br>
>  .../glsl/opt_dead_builtin_varyings.cpp        | 10 ++--<br>
>  src/compiler/glsl_types.cpp                   | 10 ++--<br>
>  src/gallium/auxiliary/draw/draw_llvm.c        | 10 ++--<br>
>  src/gallium/auxiliary/driver_ddebug/dd_util.h |  4 +-<br>
>  src/gallium/auxiliary/driver_trace/tr_dump.c  |  2 +-<br>
>  .../auxiliary/gallivm/lp_bld_arit_overflow.c  |  2 +-<br>
>  .../auxiliary/gallivm/lp_bld_debug.cpp        |  4 +-<br>
>  src/gallium/auxiliary/gallivm/lp_bld_debug.h  |  2 +-<br>
>  src/gallium/auxiliary/gallivm/lp_bld_gather.c |  2 +-<br>
>  src/gallium/auxiliary/gallivm/lp_bld_init.c   |  4 +-<br>
>  src/gallium/auxiliary/gallivm/lp_bld_intr.c   |  4 +-<br>
>  src/gallium/auxiliary/gallivm/lp_bld_printf.c |  8 +--<br>
>  .../auxiliary/gallivm/lp_bld_sample_soa.c     |  2 +-<br>
>  .../auxiliary/gallivm/lp_bld_tgsi_soa.c       |  2 +-<br>
>  src/gallium/auxiliary/hud/hud_context.c       |  4 +-<br>
>  .../auxiliary/pipe-loader/pipe_loader.c       |  6 +--<br>
>  src/gallium/auxiliary/postprocess/pp_mlaa.c   |  2 +-<br>
>  src/gallium/auxiliary/tgsi/tgsi_dump.c        |  2 +-<br>
>  src/gallium/auxiliary/util/u_async_debug.c    |  2 +-<br>
>  src/gallium/auxiliary/util/u_debug_describe.c | 22 ++++----<br>
>  src/gallium/auxiliary/util/u_debug_flush.c    |  2 +-<br>
>  src/gallium/auxiliary/util/u_debug_image.c    |  2 +-<br>
>  src/gallium/auxiliary/util/u_debug_symbol.c   | 10 ++--<br>
>  src/gallium/auxiliary/util/u_dump_state.c     |  2 +-<br>
>  src/gallium/auxiliary/util/u_log.c            |  2 +-<br>
>  src/gallium/auxiliary/util/u_network.c        |  2 +-<br>
>  src/gallium/auxiliary/util/u_simple_shaders.c |  2 +-<br>
>  src/gallium/auxiliary/util/u_tests.c          |  4 +-<br>
>  src/gallium/drivers/etnaviv/etnaviv_screen.c  |  2 +-<br>
>  .../drivers/freedreno/freedreno_batch.c       |  2 +-<br>
>  .../drivers/freedreno/freedreno_screen.c      |  2 +-<br>
>  src/gallium/drivers/i915/i915_fpc_translate.c |  2 +-<br>
>  src/gallium/drivers/i915/i915_screen.c        |  2 +-<br>
>  src/gallium/drivers/llvmpipe/lp_flush.c       |  4 +-<br>
>  src/gallium/drivers/llvmpipe/lp_rast.c        |  2 +-<br>
>  src/gallium/drivers/llvmpipe/lp_screen.c      |  2 +-<br>
>  src/gallium/drivers/llvmpipe/lp_state_fs.c    |  4 +-<br>
>  src/gallium/drivers/llvmpipe/lp_state_setup.c |  2 +-<br>
>  src/gallium/drivers/llvmpipe/lp_test_arit.c   |  2 +-<br>
>  src/gallium/drivers/llvmpipe/lp_test_format.c |  2 +-<br>
>  src/gallium/drivers/nouveau/nouveau_screen.c  |  2 +-<br>
>  src/gallium/drivers/radeonsi/si_debug.c       |  2 +-<br>
>  src/gallium/drivers/radeonsi/si_shader.c      |  2 +-<br>
>  src/gallium/drivers/softpipe/sp_flush.c       |  4 +-<br>
>  src/gallium/drivers/svga/svga_msg.c           |  2 +-<br>
>  src/gallium/drivers/svga/svga_pipe_flush.c    |  4 +-<br>
>  src/gallium/drivers/svga/svga_sampler_view.c  |  2 +-<br>
>  src/gallium/drivers/svga/svga_screen.c        |  8 +--<br>
>  src/gallium/drivers/swr/swr_screen.cpp        |  2 +-<br>
>  src/gallium/drivers/vc4/vc4_bufmgr.c          |  2 +-<br>
>  src/intel/vulkan/anv_device.c                 |  4 +-<br>
>  src/mesa/program/symbol_table.c               |  4 +-<br>
>  src/util/string_buffer.c                      |  2 +-<br>
>  src/util/u_debug.c                            | 38 +++++++-------<br>
>  src/util/u_queue.c                            |  6 +--<br>
>  src/util/u_string.h                           | 52 ++++++++-----------<br>
>  61 files changed, 154 insertions(+), 162 deletions(-)<br>
> <br>
<br>
</div>
</span></font></div>
</div>
</div>
</div>
</body>
</html>