Re: [RFC][PATCH] t-prio-queue: simplify using compound literals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Apr 05, 2024 at 07:44:59PM +0200, René Scharfe wrote:

> Am 02.04.24 um 22:41 schrieb Jeff King:
> >
> > I don't have a
> > strong opinion on compound literals in general, but if we did allow
> > them, we could clean up the horrible non-reentrant DATE_MODE().
> 
> We can easily make them reentrant without compound literals.  It just
> requires simple changes to lots of places.  Patch below.
> 
> --- >8 ---
> Subject: [PATCH] date: make DATE_MODE thread-safe
> 
> date_mode_from_type() modifies a static variable and returns a pointer
> to it.  This is not thread-safe.  Most callers of date_mode_from_type()
> use it via the macro DATE_MODE and pass its result on to functions like
> show_date(), which take a const pointer and don't modify the struct.
> 
> Avoid the static storage by putting the variable on the stack and
> returning the whole struct date_mode.  Change functions that take a
> constant pointer to expect the whole struct instead.

Yeah, this seems pretty reasonable. I think we've traditionally been
hesitant to pass or return structs by value, but that's mostly
superstition. IIRC it was illegal before C89, but that's long enough ago
that we can presumably ignore it.

-Peff




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux