[ghex] build: make mmap default; cleanup malloc headers



commit 059bb5443cea694a9753897672c4d277dd6053f9
Author: Logan Rathbone <poprocks gmail com>
Date:   Tue Dec 21 21:05:18 2021 -0500

    build: make mmap default; cleanup malloc headers

 ALPHA-INFO.txt          |  8 --------
 meson.build             | 52 +++++++++++++------------------------------------
 meson_options.txt       |  2 +-
 src/hex-buffer-malloc.h |  2 --
 src/hex-dialog.c        |  5 -----
 src/hex-document.c      | 10 ++++------
 src/hex-document.h      |  4 +---
 src/main.c              |  7 ++++---
 8 files changed, 24 insertions(+), 66 deletions(-)
---
diff --git a/ALPHA-INFO.txt b/ALPHA-INFO.txt
index 38d285e..ae49ce7 100644
--- a/ALPHA-INFO.txt
+++ b/ALPHA-INFO.txt
@@ -73,14 +73,6 @@ Other known issues to be addressed in a future version:
 
    I am told this may be a bug in GTK relating to the context menu.
 
- - Memory-mapping of files instead of reading directly into memory.
-   See:  https://gitlab.gnome.org/GNOME/ghex/-/issues/15
-   I have started work on a memory-mapping backend for the HexBuffer
-   interface. If you want to try hacking it, you can enable it at compile-time
-   with `-Dexperimental-mmap=true`.  Note that it is HIGHLY experimental and
-   unstable at this time.  Do NOT trust your data with it in any way, shape or
-   form! You have been warned.
-
  - Users have requested other features as well. Some will be implemented, some
    will not, and some will be taken under advisement.
    See https://gitlab.gnome.org/GNOME/ghex/-/issues for some discussions.
diff --git a/meson.build b/meson.build
index 0821e66..8a35c2f 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
 project(
   'ghex', 'c',
-  version: '4.alpha.1',
+  version: '4.alpha.2',
   meson_version: '>=0.53.0',
   license: 'GPL2'
 )
@@ -35,7 +35,8 @@ ghex_po_dir = join_paths(meson.source_root(), 'po')
 # warning cflags
 warning_cflags = [
   '-Wno-unused-variable',
-  '-Wno-unused-parameter'
+  '-Wno-unused-parameter',
+  '-Werror=implicit'
 ]
 c_compiler = meson.get_compiler('c')
 supported_warning_cflags = c_compiler.get_supported_arguments(warning_cflags)
@@ -47,7 +48,7 @@ i18n = import('i18n')
 cc = meson.get_compiler('c')
 
 # nb: this option will likely be removed in a future release
-experimental_mmap = get_option('experimental-mmap')
+buffer_backend = get_option('buffer-backend')
 
 # just to avoid manually punching it into the XML files as well as the source.
 shaded_box_max = 1000
@@ -67,7 +68,10 @@ config_h.set('GETTEXT_PACKAGE', 'PACKAGE_NAME')
 config_h.set('LOCALEDIR', 'PACKAGE_LOCALE_DIR')
 
 config_h.set('CONFIG_H_SHADED_BOX_MAX', shaded_box_max)
-config_h.set('EXPERIMENTAL_MMAP', experimental_mmap)
+
+if buffer_backend == 'mmap'
+  config_h.set('BACKEND_MMAP', true)
+endif
 
 config_h.set_quoted('LIBGTKHEX_RELEASE_STRING', 'gtkhex-@0@.0'.format(libghex_version_major))
 
@@ -76,43 +80,15 @@ config_h.set('DEBUG', get_option('debug'))
 # i18n:  Always enabled
 config_h.set10('ENABLE_NLS', true) 
 
-# Check for required headers and functions
-# FIXME - unistd.h & friends shouldn't be required
-check_headers = [
-  'dlfcn.h',
-  'inttypes.h',
-  'memory.h',
-  'stdint.h',
-  'stdlib.h',
-  'string.h',
-  'sys/stat.h',
-  'sys/types.h',
-  'unistd.h',
-]
-
-foreach h : check_headers
-  cc.has_header(h, required: true)
-endforeach
-
-check_functions = [
-  'pow',
-  'strstr',
-  'strtoul'
-]
-
-foreach f : check_functions
-  if cc.has_function(f) == false
-    error('Required C function not found: @0@'.format(f))
-  endif
-endforeach
-
 # mmap: Check for required headers and fcns
-if experimental_mmap
-  message('Checking dependencies for experimental mmap backend...')
+if buffer_backend == 'mmap'
+  message('Checking dependencies for `mmap` buffer backend...')
 
   check_headers_mmap = [
+    'unistd.h',
+    'fcntl.h',
+    'sys/stat.h',
     'sys/mman.h',
-    'errno.h',
     ]
   foreach h : check_headers_mmap
     cc.has_header(h, required: true)
@@ -160,5 +136,5 @@ summary({'prefix': ghex_prefix,
         }, section: 'Directories')
 
 summary({'Development build': get_option('development'),
-         'Experimental mmap backend': experimental_mmap,
+         'Buffer backend': buffer_backend,
         }, section: 'Configuration')
diff --git a/meson_options.txt b/meson_options.txt
index d89e20f..8bddea0 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,2 +1,2 @@
 option('development', type: 'boolean', value: false, description: 'If this is a development build')
-option('experimental-mmap', type: 'boolean', value: false, description: 'Enable EXPERIMENTAL `mmap` 
buffering backend')
+option('buffer-backend', type : 'combo', choices : ['mmap', 'malloc'], value : 'mmap')
diff --git a/src/hex-buffer-malloc.h b/src/hex-buffer-malloc.h
index 7f504c9..8814c26 100644
--- a/src/hex-buffer-malloc.h
+++ b/src/hex-buffer-malloc.h
@@ -33,8 +33,6 @@
 
 #include <stdio.h>
 #include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
 
 G_BEGIN_DECLS
 
diff --git a/src/hex-dialog.c b/src/hex-dialog.c
index 099d694..9378f62 100644
--- a/src/hex-dialog.c
+++ b/src/hex-dialog.c
@@ -29,16 +29,11 @@
  */
 
 #include "hex-dialog.h"
-#include "gtkhex.h"
 
-#include <glib-object.h>
 #include <glib/gi18n.h>
 
 #include <stdio.h>
-#include <unistd.h>
-#include <sys/stat.h>
 #include <string.h>
-#include <math.h>
 
 #include <config.h>
 
diff --git a/src/hex-document.c b/src/hex-document.c
index 1b8e42a..1669801 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -33,18 +33,16 @@
 #include "hex-document.h"
 
 #include <stdio.h>
-#include <unistd.h>
-#include <sys/stat.h>
 #include <string.h>
 
 #include <glib/gi18n.h>
 
 #include <config.h>
 
-/* FIXME / TODO - Allow for swappability. Hardcoding for now for testing
- * purposes. Keep this include below config.h, as it is (un)def'd there.
+/* TODO - Allow for swappability. Compile-time only for now.
+ * Keep this include below config.h, as it is (un)def'd there.
  */
-#ifdef EXPERIMENTAL_MMAP
+#ifdef BACKEND_MMAP
 #  include "hex-buffer-mmap.h"
 #else
 #  include "hex-buffer-malloc.h"
@@ -297,7 +295,7 @@ hex_document_class_init (HexDocumentClass *klass)
 static void
 hex_document_init (HexDocument *doc)
 {
-#ifdef EXPERIMENTAL_MMAP
+#ifdef BACKEND_MMAP
        doc->buffer = HEX_BUFFER(hex_buffer_mmap_new (NULL));
 #else
        doc->buffer = HEX_BUFFER(hex_buffer_malloc_new (NULL));
diff --git a/src/hex-document.h b/src/hex-document.h
index b8587e7..4aa003f 100644
--- a/src/hex-document.h
+++ b/src/hex-document.h
@@ -33,12 +33,10 @@
 #ifndef HEX_DOCUMENT_H
 #define HEX_DOCUMENT_H
 
+#include <hex-buffer-iface.h>
 #include <stdio.h>
-
 #include <glib-object.h>
 
-#include <hex-buffer-iface.h>
-
 G_BEGIN_DECLS
 
 #define HEX_TYPE_DOCUMENT hex_document_get_type ()
diff --git a/src/main.c b/src/main.c
index 2f8772f..1b12c47 100644
--- a/src/main.c
+++ b/src/main.c
@@ -120,9 +120,10 @@ activate (GtkApplication *app,
        gtk_window_set_application (window, app);
        gtk_window_present (window);
 
-#ifdef EXPERIMENTAL_MMAP
-       g_warning ("Your build has the HIGHLY EXPERIMENTAL `mmap` backend enabled. "
-                       "Use with care! Do NOT trust this with any important data!");
+#ifdef BACKEND_MMAP
+       g_debug ("Backend: `mmap`");
+#else
+       g_debug ("Backend: `malloc`");
 #endif
 }
 


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