Re: [PATCH 2/9] trace2: convert tr2tls_thread_ctx.thread_name from strbuf to char*
- From
- Jeff Hostetler <git@jeffhostetler.com>
- Date
- Dec 22, 2021, 16:32 UTC
- Message-ID
- <5d8f9882-fca7-ccfd-7430-d73a856cad39@jeffhostetler.com>
- In-Reply-To
- <211220.86ilvjt5y8.gmgdl@evledraar.gmail.com>
On 12/20/21 2:35 PM, Ævar Arnfjörð Bjarmason wrote:
Show 21 quoted lines
> > On Mon, Dec 20 2021, Jeff Hostetler wrote: > >> On 12/20/21 11:31 AM, Ævar Arnfjörð Bjarmason wrote: >>> On Mon, Dec 20 2021, Jeff Hostetler via GitGitGadget wrote: >>> >>>> From: Jeff Hostetler <jeffhost@microsoft.com> >>>> >> >> Yes, it was. To me a "const char *" in a structure means that >> the structure does not own the pointer and must not free it. >> Whereas as "char *" means that the structure might own it and >> should maybe free it when the structure is freed. My usage here >> is that the structure does own it (because it took it from the >> temporary strbuf using strbuf_detach()) and so it must free it. >> Therefore it should not be "const". This has nothing to do with >> whether or not we allow the thread name to be changed after the >> fact. (We don't, but that is a different issue). > > We use the pattern of having a "const char *" that's really a "char *" > with a cast to free() in many existing APIs for this scenario.
As I mention later in this thread, I'm going to convert the field into a flex-array, so most of the discussion in this part of the thread no longer applies.