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

Re: [PATCH v2 2/3] textconv: support for blame

From
Bbonneta <bonneta@ensimag.fr>
Date
Jun 15, 2010, 10:32 UTC
Message-ID
<192517e06785fed4fa799bee9a11ae28@ensimag.fr>
In-Reply-To
<20100615095452.GA32624@sigill.intra.peff.net>
On Tue, 15 Jun 2010 05:54:53 -0400, Jeff King <peff@peff.net> wrote:
Show 33 quoted lines
> On Tue, Jun 15, 2010 at 11:29:57AM +0200, Clément Poulain wrote:
> 
>> > The same issue exists in Clément's patch to builtin/cat-file.c.
>> 
>> We did this way because we found a similar cast in prep_temp_blob(),
>> diff.c:
>> 
>> 	if (convert_to_working_tree(path,
>> 			(const char *)blob, (size_t)size, &buf)) {
>> 
>> where size is an unsigned long.
>> Is it the same issue ? Or is it different because it's not a pointer
>> cast?
> 
> Right. The compiler will handle conversion between integer types during
> assignment itself, converting representations as necessary (in fact,
> that cast looks useless to me, as implicit conversions are allowed in
> C). The only problem is dereferencing a pointer to X as something other
> than X.
> 
>> Otherwise, we thought of reversing the conversion. That is to say,
>> instead
>> of casting "long *" in "size_t *" when calling textconv_object(), is it
>> better to cast size_t in "unsigned long" in textconv_object():
>> 
>> 	*buf_size = (unsigned long) fill_textconv(textconv, df, buf); ?
> 
> You shouldn't even have to cast there, for the same reason as above.
> That is why I wrote fill_textconv to return the size parameter, rather
> than writing to a passed-in pointer. It avoids the annoying
> size_t / unsigned long casting caused by different usage (in an ideal
> world, all of our sizes would be the same type, but the strbuf and diff
> code obviously differ).
Thanks for your answer.
We have changed the declaration of textconv_object() to:
static int textconv_object(const char *path,
                           const unsigned char *sha1,
                           char **buf,
                           unsigned long *buf_size)

And now we can do: *buf_size = fill_textconv(textconv, df, buf); without any cast.

But we have to do: textconv_object(read_from, null_sha1, &buf.buf, (unsigned long *) &buf.len)) where buf.len is size_t.

Is that ok? Our gcc doesn't report any strict-aliasing problem, so we don't know if it is better than the initial version or not...

Previous: Jeff KingNext: Matthieu Moy
Message 12 of 17 in “textconv support for blame”
  1. 0/3 textconv support for blameAxel Bonnet, Jun 7, 2010
  2. 1/3 textconv: make the API publicAxel Bonnet, Jun 7, 2010
  3. 2/3 textconv: support for blameAxel Bonnet, Jun 7, 2010
  4. 3/3 t/t8006: test textconv support for blameAxel Bonnet, Jun 7, 2010
  5. Junio C HamanoJun 11, 2010
  6. Diane GasselinJun 14, 2010
  7. Junio C HamanoJun 11, 2010
  8. Jeff KingJun 12, 2010
  9. Junio C HamanoJun 14, 2010
  10. Clément PoulainJun 15, 2010
  11. Jeff KingJun 15, 2010
  12. bonnetaJun 15, 2010
  13. Matthieu MoyJun 15, 2010
  14. Junio C HamanoJun 15, 2010
  15. 2/3 textconv: support for blameAxel Bonnet, Jun 15, 2010
  16. Jeff KingJun 15, 2010
  17. bonnetaJun 15, 2010

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.