From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: view/edit large files Date: Tue, 17 Feb 2009 14:23:32 -0500 Message-ID: References: <86fxiuw6u7.fsf@lifelogs.com> <86zlgzqudo.fsf_-_@lifelogs.com> <86k583p96e.fsf@lifelogs.com> <874oz7grs0.fsf@catnip.gol.com> <864oz3nyj8.fsf@lifelogs.com> <864oz2l47t.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1234898635 31099 80.91.229.12 (17 Feb 2009 19:23:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 Feb 2009 19:23:55 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ted Zlatanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 17 20:25:11 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LZVZ5-00024l-HI for ged-emacs-devel@m.gmane.org; Tue, 17 Feb 2009 20:25:08 +0100 Original-Received: from localhost ([127.0.0.1]:48610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LZVXl-0008UL-A1 for ged-emacs-devel@m.gmane.org; Tue, 17 Feb 2009 14:23:45 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LZVXe-0008Sj-Os for emacs-devel@gnu.org; Tue, 17 Feb 2009 14:23:38 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LZVXd-0008Rf-4t for emacs-devel@gnu.org; Tue, 17 Feb 2009 14:23:38 -0500 Original-Received: from [199.232.76.173] (port=55911 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LZVXd-0008RY-29 for emacs-devel@gnu.org; Tue, 17 Feb 2009 14:23:37 -0500 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:35789) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LZVXc-0005YQ-Q1 for emacs-devel@gnu.org; Tue, 17 Feb 2009 14:23:36 -0500 Original-Received: from alfajor.home (vpn-132-204-232-203.acd.umontreal.ca [132.204.232.203]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id n1HJOEvr016235; Tue, 17 Feb 2009 14:24:14 -0500 Original-Received: by alfajor.home (Postfix, from userid 20848) id 720E4A225A; Tue, 17 Feb 2009 14:23:32 -0500 (EST) In-Reply-To: <864oz2l47t.fsf@lifelogs.com> (Ted Zlatanov's message of "Tue, 10 Feb 2009 09:08:22 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.90 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3213=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:109140 Archived-At: > While time values and file offsets can certainly be represented as > floats under some constraints, I think it's an inelegant solution. > This is the chance to have a clean design for support of large integers, > since I or someone else will be modifying insert-file-contents anyhow. Using floats has the major advantage that it only requires changes in insert-file-contents (e.g. try the patch below). Large integers can be added as well, but it's a mostly orthogonal issue. Stefan === modified file 'src/fileio.c' --- src/fileio.c 2009-02-11 20:00:50 +0000 +++ src/fileio.c 2009-02-17 19:21:59 +0000 @@ -3161,6 +3161,7 @@ Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark; int we_locked_file = 0; int deferred_remove_unwind_protect = 0; + off_t beg_offset, end_offset; if (current_buffer->base_buffer && ! NILP (visit)) error ("Cannot do file visiting in an indirect buffer"); @@ -3268,12 +3269,12 @@ } if (!NILP (beg)) - CHECK_NUMBER (beg); + CHECK_NUMBER_OR_FLOAT (beg); else XSETFASTINT (beg, 0); if (!NILP (end)) - CHECK_NUMBER (end); + CHECK_NUMBER_OR_FLOAT (end); else { if (! not_regular) @@ -3408,6 +3409,8 @@ set_coding_system = 1; } + beg_offset = FLOATP (beg) ? (off_t) XFLOAT_DATA (beg) : XINT (beg); + end_offset = FLOATP (end) ? (off_t) XFLOAT_DATA (end) : XINT (end); /* If requested, replace the accessible part of the buffer with the file contents. Avoid replacing text at the beginning or end of the buffer that matches the file contents; @@ -3438,9 +3441,9 @@ give up on handling REPLACE in the optimized way. */ int giveup_match_end = 0; - if (XINT (beg) != 0) + if (beg_offset != 0) { - if (lseek (fd, XINT (beg), 0) < 0) + if (lseek (fd, beg_offset, 0) < 0) report_file_error ("Setting file position", Fcons (orig_filename, Qnil)); } @@ -3487,7 +3490,7 @@ immediate_quit = 0; /* If the file matches the buffer completely, there's no need to replace anything. */ - if (same_at_start - BEGV_BYTE == XINT (end)) + if (same_at_start - BEGV_BYTE == end_offset - beg_offset) { emacs_close (fd); specpdl_ptr--; @@ -3505,7 +3508,7 @@ EMACS_INT total_read, nread, bufpos, curpos, trial; /* At what file position are we now scanning? */ - curpos = XINT (end) - (ZV_BYTE - same_at_end); + curpos = end_offset - (ZV_BYTE - same_at_end); /* If the entire file matches the buffer tail, stop the scan. */ if (curpos == 0) break; @@ -3583,8 +3586,8 @@ same_at_end += overlap; /* Arrange to read only the nonmatching middle part of the file. */ - XSETFASTINT (beg, XINT (beg) + (same_at_start - BEGV_BYTE)); - XSETFASTINT (end, XINT (end) - (ZV_BYTE - same_at_end)); + beg_offset += same_at_start - BEGV_BYTE; + end_offset -= ZV_BYTE - same_at_end; del_range_byte (same_at_start, same_at_end, 0); /* Insert from the file at the proper position. */ @@ -3628,7 +3631,7 @@ /* First read the whole file, performing code conversion into CONVERSION_BUFFER. */ - if (lseek (fd, XINT (beg), 0) < 0) + if (lseek (fd, beg_offset, 0) < 0) report_file_error ("Setting file position", Fcons (orig_filename, Qnil)); @@ -3803,7 +3806,7 @@ { register Lisp_Object temp; - total = XINT (end) - XINT (beg); + total = end_offset - beg_offset; /* Make sure point-max won't overflow after this insertion. */ XSETINT (temp, total); @@ -3830,9 +3833,9 @@ if (GAP_SIZE < total) make_gap (total - GAP_SIZE); - if (XINT (beg) != 0 || !NILP (replace)) + if (beg_offset != 0 || !NILP (replace)) { - if (lseek (fd, XINT (beg), 0) < 0) + if (lseek (fd, beg_offset, 0) < 0) report_file_error ("Setting file position", Fcons (orig_filename, Qnil)); }