Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Cc: Git List <git@vger.kernel.org>,
	Chandra Pratap <chandrapratap3519@gmail.com>
Subject: Re: [RFC][PATCH] t-prio-queue: simplify using compound literals
Date: Sat, 6 Apr 2024 09:06:00 +0200	[thread overview]
Message-ID: <88f2063e-bddb-4479-a0c1-5bad582b9fe9@web.de> (raw)
In-Reply-To: <xmqqedbjtqnr.fsf@gitster.g>

Am 06.04.24 um 00:01 schrieb Junio C Hamano:
> Jeff King <peff@peff.net> writes:
>
>> Yeah, this seems pretty reasonable. I think we've traditionally been
>> hesitant to pass or return structs by value, but that's mostly
>> superstition.
>
> We should still be hesitant against the practice to the same degree
> that we are hesitant against struct assignment, especially when the
> struct is of nontrivial size, or the struct has a pointer member
> whose memory ownership semantics goes against shallow copying of the
> struct.
>
> In this particular case, I do not know offhand if .strftime_fmt is
> safe to be shallowly copied, but I trust you two know and/or have
> already looked at the implications.

date_mode_from_type() sets .strftime_fmt to NULL in the struct date_mode
it creates and returns.  Giving a reference to it to date_mode_release()
is a safe NOOP.

show_date() passes .strftime_fmt to strbuf_addftime() and does not
retain a copy or change it.

show_ident_date() only passes its struct date_mode parameter to
show_date().

format_person_part() only passes its struct date_mode parameter to
show_ident_date().

format_reflog_person() only passes its struct date_mode parameter to
format_person_part().

get_reflog_selector() only passes its struct date_mode parameter to
show_date().

show_reflog_message() only passes its struct date_mode parameter to
get_reflog_selector().

The patch doesn't change any other function signatures.

strbuf_addftime() scans the format string and passes it to
strbuf_expand_step(), skip_prefix() and strftime(3).  None of them
change it or retain a copy of the pointer.

In other words: This patch mostly affects the read-only side of struct
date_mode handling, and the date_mode_from_type() part is benign as
well.

René

  reply	other threads:[~2024-04-06  7:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 18:30 [RFC][PATCH] t-prio-queue: simplify using compound literals René Scharfe
2024-04-02 20:31 ` Junio C Hamano
2024-04-02 20:41 ` Jeff King
2024-04-05 17:44   ` René Scharfe
2024-04-05 19:17     ` Jeff King
2024-04-05 22:01       ` Junio C Hamano
2024-04-06  7:06         ` René Scharfe [this message]
2024-04-07  1:28         ` Jeff King
2024-04-08 16:57           ` Junio C Hamano
2024-04-08 17:09             ` Jeff King
2024-04-11 21:23 ` Josh Steadmon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88f2063e-bddb-4479-a0c1-5bad582b9fe9@web.de \
    --to=l.s.r@web.de \
    --cc=chandrapratap3519@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).