[COMMIT] Use alloca_{rawbytes, ibytes} in #'copy-file, #'insert-file-contents-internal

Aidan Kehoe <[email protected]>
Newsgroups gmane.emacs.xemacs.patches
Message-ID <[email protected]>
Thank you for the input, Stephen!

APPROVE COMMIT

NOTE: This patch has been committed.

# HG changeset patch
# User Aidan Kehoe <[email protected]>
# Date 1390240387 0
# Node ID 0853e1ec8529b0b7d50abe5ffdadaaee54c3d9b4
# Parent  580ebed3500a224370cc7f4a6f7ad84f5ecf7530
Use alloca_{rawbytes,ibytes} in #'copy-file, #'insert-file-contents-internal

src/ChangeLog addition:

2014-01-20  Aidan Kehoe  <[email protected]>

	* fileio.c (Fcopy_file, Finsert_file_contents_internal):
	Use alloca_{rawbytes,ibytes} here instead of the implicit alloca
	on the stack; doesn't change where the buffers are allocated for
	these two functions, but does mean that decisions about alloca
	vs. malloc based on buffer size are made in the same place
	(ultimately, the ALLOCA() macro).

diff -r 580ebed3500a -r 0853e1ec8529 src/ChangeLog
--- a/src/ChangeLog	Sat Jan 18 17:40:41 2014 +0100
+++ b/src/ChangeLog	Mon Jan 20 17:53:07 2014 +0000
@@ -1,3 +1,12 @@
+2014-01-20  Aidan Kehoe  <[email protected]>
+
+	* fileio.c (Fcopy_file, Finsert_file_contents_internal):
+	Use alloca_{rawbytes,ibytes} here instead of the implicit alloca
+	on the stack; doesn't change where the buffers are allocated for
+	these two functions, but does mean that decisions about alloca
+	vs. malloc based on buffer size are made in the same place
+	(ultimately, the ALLOCA() macro).
+
 2014-01-16  Aidan Kehoe  <[email protected]>
 
 	* fileio.c (READ_BUF_SIZE):
diff -r 580ebed3500a -r 0853e1ec8529 src/fileio.c
--- a/src/fileio.c	Sat Jan 18 17:40:41 2014 +0100
+++ b/src/fileio.c	Mon Jan 20 17:53:07 2014 +0000
@@ -1803,7 +1803,7 @@
 {
   /* This function can call Lisp.  GC checked 2000-07-28 ben */
   int ifd, ofd, n;
-  Rawbyte buf[READ_BUF_SIZE];
+  Rawbyte *buf = alloca_rawbytes (READ_BUF_SIZE);
   struct stat st, out_st;
   Lisp_Object handler;
   int speccount = specpdl_depth ();
@@ -1909,7 +1909,7 @@
 
     record_unwind_protect (close_file_unwind, ofd_locative);
 
-    while ((n = read_allowing_quit (ifd, buf, sizeof (buf))) > 0)
+    while ((n = read_allowing_quit (ifd, buf, READ_BUF_SIZE)) > 0)
     {
       if (write_allowing_quit (ofd, buf, n) != n)
 	report_file_error ("I/O error", newname);
@@ -2899,7 +2899,7 @@
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   Lisp_Object val;
   int total;
-  Ibyte read_buf[READ_BUF_SIZE];
+  Ibyte *read_buf = alloca_ibytes (READ_BUF_SIZE);
   int mc_count;
   struct buffer *buf = current_buffer;
   Lisp_Object curbuf;
@@ -3199,8 +3199,7 @@
 	Charcount cc_inserted, this_tell = last_tell;
 
 	QUIT;
-	this_len = Lstream_read (XLSTREAM (stream), read_buf,
-				 sizeof (read_buf));
+	this_len = Lstream_read (XLSTREAM (stream), read_buf, READ_BUF_SIZE);
 
 	if (this_len <= 0)
 	  {


-- 
‘Liston operated so fast that he once accidentally amputated an assistant’s
fingers along with a patient’s leg, […] The patient and the assistant both
died of sepsis, and a spectator reportedly died of shock, resulting in the
only known procedure with a 300% mortality.’ (Atul Gawande, NEJM, 2012)

_______________________________________________
XEmacs-Patches mailing list
[email protected]
http://lists.xemacs.org/mailman/listinfo/xemacs-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.