git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] replace-object.c: remove the_repository from prepare_replace_object
Date: Thu, 10 May 2018 19:23:13 +0900	[thread overview]
Message-ID: <xmqqtvrfizce.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20180509234059.52156-2-sbeller@google.com> (Stefan Beller's message of "Wed, 9 May 2018 16:40:59 -0700")

Stefan Beller <sbeller@google.com> writes:

> This was missed in 5982da9d2ce (replace-object: allow
> prepare_replace_object to handle arbitrary repositories, 2018-04-11)
>
> Technically the code works correctly as the replace_map is the same
> size in different repositories, however it is hard to read. So convert
> the code to the familiar pattern of dereferencing the pointer that we
> assign in the sizeof itself.

;-)

We say

	ptr = xmalloc(sizeof(*ptr))

is better because 

	ptr = xmalloc(sizeof(typeof(*ptr)))

is easy to go stale unless we actually use typeof and instead say a
concrete type like "struct oidmap".

This one was doing

	ptr = xmalloc(sizeof(*another_ptr))

and it was OK because ptr and another_ptr happened to be of the same
type.  I wonder if we are making it safer, or making it more obscure
to seasoned C programmers, if we introduced a pair of helper macros,
perhaps like these:

	#define ALLOCATE(ptr) (ptr) = xmalloc(sizeof(*(ptr)))
	#define CALLOCATE(ptr,cnt) (ptr) = xcalloc((cnt), sizeof(*(ptr)))

The change looks obviously good.  Will queue.

Thanks.

  reply	other threads:[~2018-05-10 10:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09 23:40 [PATCH 1/2] object.c: free replace map in raw_object_store_clear Stefan Beller
2018-05-09 23:40 ` [PATCH 2/2] replace-object.c: remove the_repository from prepare_replace_object Stefan Beller
2018-05-10 10:23   ` Junio C Hamano [this message]
2018-05-10 11:56     ` Jeff King
2018-05-10 14:53       ` Derrick Stolee
2018-05-10 18:32         ` Stefan Beller
2018-05-10 10:16 ` [PATCH 1/2] object.c: free replace map in raw_object_store_clear Junio C Hamano
2018-05-10 17:23   ` Stefan Beller
  -- strict thread matches above, loose matches on Subject: below --
2018-05-17 18:20 What's cooking in git.git (May 2018, #02; Thu, 17) Stefan Beller
2018-05-17 18:29 ` [PATCH 0/2] Reroll 2 last commits of sb/object-store-replace Stefan Beller
2018-05-17 18:29   ` [PATCH 2/2] replace-object.c: remove the_repository from prepare_replace_object Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqtvrfizce.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=sbeller@google.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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).