git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 7/7] odb: use size_t for object_info.sizep and the size APIs

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 15, 2026, 09:29 UTC
Message-ID
<d82abb94-1720-ba15-15b6-e1a9ac28b0aa@gmx.de>
In-Reply-To
<aibJZ8EXoQSD2lsB@pks.im>
Hi Patrick,
On Mon, 15 Jun 2026, Patrick Steinhardt wrote:
Show 26 quoted lines
> On Thu, Jun 04, 2026 at 10:51:12AM +0000, Johannes Schindelin via GitGitGadget wrote:
> > diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> > index fa45f774d7..fa6e396ddc 100644
> > --- a/builtin/cat-file.c
> > +++ b/builtin/cat-file.c
> > @@ -120,7 +120,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
> >  	struct object_id oid;
> >  	enum object_type type;
> >  	char *buf;
> > -	unsigned long size;
> > +	size_t size;
> >  	struct object_context obj_context = {0};
> >  	struct object_info oi = OBJECT_INFO_INIT;
> >  	unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
> > @@ -166,7 +166,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
> >  		if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
> >  			size_t s = size;
> >  			buf = replace_idents_using_mailmap(buf, &s);
> > -			size = cast_size_t_to_ulong(s);
> > +			size = s;
> >  		}
> >  
> >  		printf("%"PRIuMAX"\n", (uintmax_t)size);
> 
> Can't we drop this local variable completely and instead supply `&size`
> directly?
Well spotted!
Show 29 quoted lines
> > @@ -219,7 +225,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
> >  		if (use_mailmap) {
> >  			size_t s = size;
> >  			buf = replace_idents_using_mailmap(buf, &s);
> > -			size = cast_size_t_to_ulong(s);
> > +			size = s;
> >  		}
> >  
> >  		/* otherwise just spit out the data */
> > @@ -266,7 +272,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
> >  		if (use_mailmap) {
> >  			size_t s = size;
> >  			buf = replace_idents_using_mailmap(buf, &s);
> > -			size = cast_size_t_to_ulong(s);
> > +			size = s;
> >  		}
> >  		break;
> >  	}
> > @@ -446,7 +455,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
> >  		if (use_mailmap) {
> >  			size_t s = size;
> >  			contents = replace_idents_using_mailmap(contents, &s);
> > -			size = cast_size_t_to_ulong(s);
> > +			size = s;
> >  		}
> >  
> >  		if (type != data->type)
> 
> Likewise for these three instances.
I totally agree.
Show 11 quoted lines
> > @@ -555,7 +564,7 @@ static void batch_object_write(const char *obj_name,
> >  			if (!buf)
> >  				die(_("unable to read %s"), oid_to_hex(&data->oid));
> >  			buf = replace_idents_using_mailmap(buf, &s);
> > -			data->size = cast_size_t_to_ulong(s);
> > +			data->size = s;
> >  
> >  			free(buf);
> >  		}
> 
> And I think this site here can be adapted, as well.
Indeed!
Show 34 quoted lines
> > diff --git a/diff.c b/diff.c
> > index 5a584fa1d5..816b89dc6c 100644
> > --- a/diff.c
> > +++ b/diff.c
> > @@ -4594,8 +4594,9 @@ int diff_populate_filespec(struct repository *r,
> >  		}
> >  	}
> >  	else {
> > +		size_t size_st = 0;
> >  		struct object_info info = {
> > -			.sizep = &s->size
> > +			.sizep = &size_st
> >  		};
> >  
> >  		if (!(size_only || check_binary))
> > @@ -4617,6 +4618,7 @@ int diff_populate_filespec(struct repository *r,
> >  			die("unable to read %s", oid_to_hex(&s->oid));
> >  
> >  object_read:
> > +		s->size = cast_size_t_to_ulong(size_st);
> >  		if (size_only || check_binary) {
> >  			if (size_only)
> >  				return 0;
> > @@ -4631,6 +4633,7 @@ object_read:
> >  			if (odb_read_object_info_extended(r->objects, &s->oid, &info,
> >  							  OBJECT_INFO_LOOKUP_REPLACE))
> >  				die("unable to read %s", oid_to_hex(&s->oid));
> > +			s->size = cast_size_t_to_ulong(size_st);
> >  		}
> >  		s->should_free = 1;
> >  	}
> 
> The flow in this function is quite weird if you ask me, but that's a
> preexisting issue. This does look correct to me, even if it's awkward.
Yes, on all four accounts.

Ciao, Johannes

Previous: Patrick SteinhardtNext: Johannes Schindelin via GitGitGadget
Message 17 of 29 in “More work supporting objects larger than 4GB on Windows”
  1. 0/7 More work supporting objects larger than 4GB on WindowsJohannes Schindelin via GitGitGadget, Jun 4, 2026
  2. 1/7 compat/msvc: use _chsize_s for ftruncateJohannes Schindelin via GitGitGadget, Jun 4, 2026
  3. 2/7 patch-delta: use size_t for sizesJohannes Schindelin via GitGitGadget, Jun 4, 2026
  4. Patrick SteinhardtJun 8, 2026
  5. Johannes SchindelinJun 15, 2026
  6. 3/7 pack-objects(check_pack_inflate()): use size_t instead of unsigned longJohannes Schindelin via GitGitGadget, Jun 4, 2026
  7. Patrick SteinhardtJun 8, 2026
  8. Johannes SchindelinJun 15, 2026
  9. 4/7 packfile: widen unpack_entry()'s size out-parameter to size_tJohannes Schindelin via GitGitGadget, Jun 4, 2026
  10. Patrick SteinhardtJun 8, 2026
  11. Johannes SchindelinJun 15, 2026
  12. 5/7 pack-objects: use size_t for in-core object sizesJohannes Schindelin via GitGitGadget, Jun 4, 2026
  13. 6/7 packfile,delta: drop the `cast_size_t_to_ulong()` wrappersJohannes Schindelin via GitGitGadget, Jun 4, 2026
  14. Patrick SteinhardtJun 8, 2026
  15. 7/7 odb: use size_t for object_info.sizep and the size APIsJohannes Schindelin via GitGitGadget, Jun 4, 2026
  16. Patrick SteinhardtJun 8, 2026
  17. Johannes SchindelinJun 15, 2026
  18. 0/7 More work supporting objects larger than 4GB on WindowsJohannes Schindelin via GitGitGadget, Jun 15, 2026
  19. 1/7 compat/msvc: use _chsize_s for ftruncateJohannes Schindelin via GitGitGadget, Jun 15, 2026
  20. 2/7 patch-delta: use size_t for sizesJohannes Schindelin via GitGitGadget, Jun 15, 2026
  21. Junio C HamanoJun 16, 2026
  22. 3/7 pack-objects(check_pack_inflate()): use size_t instead of unsigned longJohannes Schindelin via GitGitGadget, Jun 15, 2026
  23. 4/7 packfile: widen unpack_entry()'s size out-parameter to size_tJohannes Schindelin via GitGitGadget, Jun 15, 2026
  24. 5/7 pack-objects: use size_t for in-core object sizesJohannes Schindelin via GitGitGadget, Jun 15, 2026
  25. 6/7 packfile,delta: drop the `cast_size_t_to_ulong()` wrappersJohannes Schindelin via GitGitGadget, Jun 15, 2026
  26. 7/7 odb: use size_t for object_info.sizep and the size APIsJohannes Schindelin via GitGitGadget, Jun 15, 2026
  27. Junio C HamanoJun 15, 2026
  28. Patrick SteinhardtJun 18, 2026
  29. Junio C HamanoJun 18, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.