git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC] strbuf's in builtin-apply
@ 2007-09-15 14:12 Pierre Habouzit
  2007-09-15 13:56 ` [PATCH] New strbuf APIs: splice and embed Pierre Habouzit
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Pierre Habouzit @ 2007-09-15 14:12 UTC (permalink / raw)
  To: git, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 1907 bytes --]

  I promised it, here it comes. It comes though with some possible
problems, so I'd like to see them discussed first.

  builtin-apply.c was messing with its custom buffers a lot,
reallocating the buffers and so on, hence I had to create strbuf_embed
to have a strbuf-safe API doing exactly the same. Though, because of the
"I want an extra NUL in the end"-invariant, this can come with a quite
high price. in the second patch, there is a hunk:


-		nsize = got;
-		nbuf = convert_to_git(path, buf, &nsize);
-		if (nbuf) {
-			free(buf);
-			*buf_p = nbuf;
-			*alloc_p = nsize;
-			*size_p = nsize;
-		}
-		return got != size;
+
+		nsize = buf->len;
+		nbuf = convert_to_git(path, buf->buf, &nsize);
+		if (nbuf)
+			strbuf_embed(buf, nbuf, nsize, nsize);
+		return 0;

  Here, I've not been able to check if convert_to_git was in fact always
dealing with a NUL-terminated buffer (That would be in fact nsize+1) or
not, hence here this strbuf_embed will likely perform a realloc. I don't
know git enough to know if this can become an horrible burden though.

  Another suspicious hunk is:

-	data = (void*) fragment->patch;
[...]
 	case BINARY_LITERAL_DEFLATED:
-		free(desc->buffer);
-		desc->buffer = data;
-		dst_size = fragment->size;
-		break;
+		strbuf_embed(buf, fragment->patch, fragment->size, fragment->size);
+		return 0;

  TTBOMK the ->patch pointer is a pointer inside a buffer, not a buffer
that has been malloc'ed (and there are code paths before my patch that
would still realloc the buffer so I don't think I introduce an issue).
It passes the test-suite without crashing, but well, maybe this should
be a copy instead.

  The rest is pretty straightforward.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2007-09-17  5:43 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-15 14:12 [RFC] strbuf's in builtin-apply Pierre Habouzit
2007-09-15 13:56 ` [PATCH] New strbuf APIs: splice and embed Pierre Habouzit
2007-09-16  0:57   ` Junio C Hamano
2007-09-16  8:10     ` Pierre Habouzit
2007-09-15 14:04 ` [PATCH] builtin-apply: use strbuf's instead of buffer_desc's Pierre Habouzit
2007-09-16  0:56   ` Junio C Hamano
2007-09-16  8:15     ` Pierre Habouzit
2007-09-15 17:07 ` [RFC] strbuf's in builtin-apply Pierre Habouzit
2007-09-16 17:21 ` Pierre Habouzit
2007-09-15 13:56   ` [PATCH] Now that cache.h needs strbuf.h, remove useless includes Pierre Habouzit
2007-09-15 13:56   ` [PATCH] New strbuf APIs: splice and attach Pierre Habouzit
2007-09-16 20:20     ` Florian Weimer
2007-09-16 20:51       ` Pierre Habouzit
2007-09-17  5:43         ` Florian Weimer
2007-09-15 21:50   ` [PATCH] Refactor replace_encoding_header Pierre Habouzit
2007-09-16  8:19   ` [PATCH] Remove preemptive allocations Pierre Habouzit
2007-09-16 13:51   ` [PATCH] Rewrite convert_to_{git,working_tree} to use strbuf's Pierre Habouzit
2007-09-16 18:27     ` Linus Torvalds
2007-09-16 16:54   ` [PATCH] builtin-apply: use strbuf's instead of buffer_desc's Pierre Habouzit
2007-09-16 17:28   ` [RFC] strbuf's in builtin-apply Pierre Habouzit
2007-09-16 22:54     ` Junio C Hamano

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