Skip to content
  • René Scharfe's avatar
    date: make DATE_MODE thread-safe · 9720d23e
    René Scharfe authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    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.
    
    Reduce the cost of passing struct date_mode around on 64-bit systems
    by reordering its members to close the hole between the 32-bit wide
    .type and the 64-bit aligned .strftime_fmt as well as the alignment
    hole at the end.  sizeof reports 24 before and 16 with this change
    on x64.  Keep .type at the top to still allow initialization without
    designator -- though that's only done in a single location, in
    builtin/blame.c.
    
    Signed-off-by: default avatarRené Scharfe <l.s.r@web.de>
    Acked-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    9720d23e