qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs qe.h buffer.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs qe.h buffer.c
Date: Sun, 18 May 2014 11:01:55 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/05/18 11:01:55

Modified files:
        .              : qe.h buffer.c 

Log message:
        fixed bugs in memory mapped buffers
        
        * unmap file upon buffer clear
        * fix bug that caused file to be mmapped AND loaded (!)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.170&r2=1.171
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.79&r2=1.80

Patches:
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -b -r1.170 -r1.171
--- qe.h        17 May 2014 10:15:22 -0000      1.170
+++ qe.h        18 May 2014 11:01:55 -0000      1.171
@@ -813,6 +813,9 @@
                         its handle is there */
     int flags;
 
+    void *map_address;
+    int map_length;
+
     /* buffer data type (default is raw) */
     struct EditBufferDataType *data_type;
     void *data; /* associated buffer data, used if data_type != raw_data */
@@ -934,7 +937,8 @@
 void do_redo(EditState *s);
 
 int raw_buffer_load1(EditBuffer *b, FILE *f, int offset);
-int mmap_buffer(EditBuffer *b, const char *filename);
+int eb_mmap_buffer(EditBuffer *b, const char *filename);
+void eb_munmap_buffer(EditBuffer *b);
 int eb_write_buffer(EditBuffer *b, int start, int end, const char *filename);
 int eb_save_buffer(EditBuffer *b);
 

Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -b -r1.79 -r1.80
--- buffer.c    23 Mar 2014 01:11:34 -0000      1.79
+++ buffer.c    18 May 2014 11:01:55 -0000      1.80
@@ -547,6 +547,8 @@
     eb_delete(b, 0, b->total_size);
     log_reset(b);
 
+    eb_munmap_buffer(b);
+
     /* close and reset file handle */
     if (b->file_handle > 0) {
         close(b->file_handle);
@@ -1623,12 +1625,23 @@
 }
 
 #ifdef CONFIG_MMAP
-int mmap_buffer(EditBuffer *b, const char *filename)
+void eb_munmap_buffer(EditBuffer *b)
+{
+    if (b->map_address) {
+        munmap(b->map_address, b->map_length);
+        b->map_address = NULL;
+        b->map_length = 0;
+    }
+}
+
+int eb_mmap_buffer(EditBuffer *b, const char *filename)
 {
     int fd, len, file_size, n, size;
     u8 *file_ptr, *ptr;
     Page *p;
 
+    eb_munmap_buffer(b);
+
     fd = open(filename, O_RDONLY);
     if (fd < 0)
         return -1;
@@ -1639,6 +1652,9 @@
         close(fd);
         return -1;
     }
+    b->map_address = file_ptr;
+    b->map_length = file_size;
+
     n = (file_size + MAX_PAGE_SIZE - 1) / MAX_PAGE_SIZE;
     p = qe_malloc_array(Page, n);
     if (!p) {
@@ -1661,6 +1677,7 @@
         size -= len;
         p++;
     }
+    // XXX: not needed
     b->file_handle = fd;
     //put_status(NULL, "");
     return 0;
@@ -1679,7 +1696,7 @@
 
 #ifdef CONFIG_MMAP
     if (st.st_size >= qs->mmap_threshold) {
-        if (mmap_buffer(b, b->filename))
+        if (!eb_mmap_buffer(b, b->filename))
             return 0;
     }
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]