aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPip Cet2021-03-02 20:38:23 +0000
committerMattias EngdegÄrd2021-06-16 09:44:32 +0200
commitd9698faa345a99b4a55bb02ecb324b0d8dcd2997 (patch)
treefb510877d78b84795d7270a891e3a98e304c4eaa
parentdb106ea88b41e7b293f18a587cbe43685cb769a6 (diff)
downloademacs-d9698faa345a99b4a55bb02ecb324b0d8dcd2997.tar.gz
emacs-d9698faa345a99b4a55bb02ecb324b0d8dcd2997.zip
Prepare pdumper dump file in memory, write it in one go (Bug#46881)
* src/pdumper.c (struct dump_context): Add buf, buf_size, max_offset fields. (dump_grow_buffer): New function. (dump_write): Use memcpy, not an actual emacs_write. (dump_seek): Keep track of maximum seen offset. Don't actually seek. (Fdump_emacs_portable): Write out the file contents when done.
-rw-r--r--src/pdumper.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/pdumper.c b/src/pdumper.c
index dfc7388b634..7730ea3d061 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -489,6 +489,10 @@ struct dump_context
489{ 489{
490 /* Header we'll write to the dump file when done. */ 490 /* Header we'll write to the dump file when done. */
491 struct dump_header header; 491 struct dump_header header;
492 /* Data that will be written to the dump file. */
493 void *buf;
494 dump_off buf_size;
495 dump_off max_offset;
492 496
493 Lisp_Object old_purify_flag; 497 Lisp_Object old_purify_flag;
494 Lisp_Object old_post_gc_hook; 498 Lisp_Object old_post_gc_hook;
@@ -597,6 +601,13 @@ static struct link_weight const
597 601
598/* Dump file creation */ 602/* Dump file creation */
599 603
604static void dump_grow_buffer (struct dump_context *ctx)
605{
606 ctx->buf = xrealloc (ctx->buf, ctx->buf_size = (ctx->buf_size ?
607 (ctx->buf_size * 2)
608 : 8 * 1024 * 1024));
609}
610
600static dump_off dump_object (struct dump_context *ctx, Lisp_Object object); 611static dump_off dump_object (struct dump_context *ctx, Lisp_Object object);
601static dump_off dump_object_for_offset (struct dump_context *ctx, 612static dump_off dump_object_for_offset (struct dump_context *ctx,
602 Lisp_Object object); 613 Lisp_Object object);
@@ -763,8 +774,9 @@ dump_write (struct dump_context *ctx, const void *buf, dump_off nbyte)
763 eassert (nbyte == 0 || buf != NULL); 774 eassert (nbyte == 0 || buf != NULL);
764 eassert (ctx->obj_offset == 0); 775 eassert (ctx->obj_offset == 0);
765 eassert (ctx->flags.dump_object_contents); 776 eassert (ctx->flags.dump_object_contents);
766 if (emacs_write (ctx->fd, buf, nbyte) < nbyte) 777 while (ctx->offset + nbyte > ctx->buf_size)
767 report_file_error ("Could not write to dump file", ctx->dump_filename); 778 dump_grow_buffer (ctx);
779 memcpy ((char *)ctx->buf + ctx->offset, buf, nbyte);
768 ctx->offset += nbyte; 780 ctx->offset += nbyte;
769} 781}
770 782
@@ -844,10 +856,9 @@ dump_tailq_pop (struct dump_tailq *tailq)
844static void 856static void
845dump_seek (struct dump_context *ctx, dump_off offset) 857dump_seek (struct dump_context *ctx, dump_off offset)
846{ 858{
859 if (ctx->max_offset < ctx->offset)
860 ctx->max_offset = ctx->offset;
847 eassert (ctx->obj_offset == 0); 861 eassert (ctx->obj_offset == 0);
848 if (lseek (ctx->fd, offset, SEEK_SET) < 0)
849 report_file_error ("Setting file position",
850 ctx->dump_filename);
851 ctx->offset = offset; 862 ctx->offset = offset;
852} 863}
853 864
@@ -4270,6 +4281,12 @@ types. */)
4270 ctx->header.magic[0] = dump_magic[0]; 4281 ctx->header.magic[0] = dump_magic[0];
4271 dump_seek (ctx, 0); 4282 dump_seek (ctx, 0);
4272 dump_write (ctx, &ctx->header, sizeof (ctx->header)); 4283 dump_write (ctx, &ctx->header, sizeof (ctx->header));
4284 if (emacs_write (ctx->fd, ctx->buf, ctx->max_offset) < ctx->max_offset)
4285 report_file_error ("Could not write to dump file", ctx->dump_filename);
4286 xfree (ctx->buf);
4287 ctx->buf = NULL;
4288 ctx->buf_size = 0;
4289 ctx->max_offset = 0;
4273 4290
4274 dump_off 4291 dump_off
4275 header_bytes = header_end - header_start, 4292 header_bytes = header_end - header_start,