[PATCH 1/5] support: don't pass to set_search_path a big struct by value

Konstantin Kharlamov hi-angel@yandex.ru
Wed Mar 27 09:13:00 GMT 2019



On Ср, Mar 27, 2019 at 09:56, Florian Weimer <fw@deneb.enyo.de> wrote:
> * Konstantin Kharlamov:
> 
>>  It matters in terms of the code as read by human: α) one would no
>>  longer wonder why "by-value" is used instead of a "by-pointer",
> 
> With by-pointer, the reader has to wonder if the called function
> retains a pointer after the call, so it is a wash in this regard.

Sorry, what you mean by "retains"? As in, "stores into a static 
variable for caching purposes"? Well, first of, if a struct contains 
pointers, then it doesn't even matter whether it was passed by-value or 
by-pointer — one could get a data race either way. Second, unless the 
function being explicit about caching a parameter, doing that behind 
the curtains sounds outright wrong as it gonna lead to hard to debug 
bugs.

So, normally I would not assume that an arbitrary function could retain 
its argument.




More information about the Libc-alpha mailing list