[ghex] buf/doc/appwin: Load default backend plugins without using ifdefs
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex] buf/doc/appwin: Load default backend plugins without using ifdefs
- Date: Sun, 12 Jun 2022 18:52:31 +0000 (UTC)
commit aeb3881154b74781ae91590b89979dd3fd5f2241
Author: Logan Rathbone <poprocks gmail com>
Date: Wed Jun 8 00:10:02 2022 -0400
buf/doc/appwin: Load default backend plugins without using ifdefs
appwin: Tweak nag screen accordingly. Change messaging a bit.
doc: change hierarchical selection of buffer backend.
buf: document slight change in hex_buffer_util_new behaviour when a
non-existent plugin is requested (return NULL instead of falling back to
malloc).
meson.build | 7 -------
src/ghex-application-window.c | 37 ++++++++++++++++---------------------
src/ghex-application-window.h | 1 +
src/hex-buffer-iface.c | 31 +++++++++++++++++++++----------
src/hex-document.c | 18 +++++++++++-------
5 files changed, 49 insertions(+), 45 deletions(-)
---
diff --git a/meson.build b/meson.build
index 8fc22ea..63d6c15 100644
--- a/meson.build
+++ b/meson.build
@@ -90,13 +90,6 @@ config_h.set('LOCALEDIR', 'PACKAGE_LOCALE_DIR')
config_h.set('CONFIG_H_SHADED_BOX_MAX', shaded_box_max)
-# nb: this config.h flag will likely be removed in a future release
-#if mmap_backend
-# config_h.set('BACKEND_MMAP', true)
-if direct_backend
- config_h.set('BACKEND_DIRECT', true)
-endif
-
config_h.set_quoted('LIBGTKHEX_RELEASE_STRING', 'gtkhex-@0@.0'.format(libgtkhex_api_version))
config_h.set('STATIC_HTML_HELP', get_option('static-html-help'))
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index b53d2de..afc18de 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -37,9 +37,7 @@
#define ACTIVE_GH \
(ghex_application_window_get_hex (self))
-#ifndef BACKEND_MMAP
static GFile *tmp_global_gfile_for_nag_screen;
-#endif
/* This is dumb, but right now I can't think of a simpler solution. */
static gpointer extra_user_data;
@@ -2040,7 +2038,6 @@ ghex_application_window_add_hex (GHexApplicationWindow *self,
show_hex_notebook (self);
}
-#ifndef BACKEND_MMAP
/* Helper */
static void
nag_screen_response_cb (GtkDialog *nag_screen,
@@ -2069,11 +2066,12 @@ do_nag_screen (GHexApplicationWindow *self)
GtkWidget *nag_screen;
char *msg = _("You are attempting to open a file 1GB or larger.\n\n"
"This can make GHex and your machine unstable as the file "
- "will be loaded into memory.\n\n"
+ "will be loaded into memory, using the active backend.\n\n"
"Are you sure you want to proceed?\n\n"
"This message will not be shown again for the remainder of "
"this GHex session.\n\n"
- "This limitation will be removed in a future version of GHex.");
+ "To avoid this message from appearing, try using a different "
+ "buffer backend.");
g_printerr ("%s", msg);
g_printerr ("\n");
@@ -2088,7 +2086,6 @@ do_nag_screen (GHexApplicationWindow *self)
G_CALLBACK(nag_screen_response_cb), self);
gtk_widget_show (nag_screen);
}
-#endif
/* also takes extra_user_data ! Hooray for cheap shortcuts! */
static void
@@ -2136,25 +2133,10 @@ ghex_application_window_open_file (GHexApplicationWindow *self, GFile *file)
{
HexDocument *doc;
HexWidget *gh = NULL;
-#ifndef BACKEND_MMAP
static gboolean nag_screen_shown = FALSE;
-#endif
g_return_if_fail (GHEX_IS_APPLICATION_WINDOW(self));
-#ifndef BACKEND_MMAP
- if (! nag_screen_shown)
- /* FIXME: Temporary nag-screen until we get the underlying issues
- * sorted. */
- if (hex_buffer_util_get_file_size (file) >= 1073741824)
- {
- nag_screen_shown = TRUE;
- tmp_global_gfile_for_nag_screen = file;
- do_nag_screen (self);
- return;
- }
-#endif
-
/* If we get it from the GApp :open signal, it's tfr:none - once
* HexDocument gets hold of it, though, it _refs it itself so we don't need
* to hold onto it.
@@ -2163,6 +2145,19 @@ ghex_application_window_open_file (GHexApplicationWindow *self, GFile *file)
doc = hex_document_new_from_file (file);
g_object_unref (file);
+ if (HEX_IS_BUFFER_MALLOC (hex_document_get_buffer (doc)) &&
+ ! nag_screen_shown)
+ {
+ if (hex_buffer_util_get_file_size (file) >= 1073741824)
+ {
+ nag_screen_shown = TRUE;
+ tmp_global_gfile_for_nag_screen = file;
+ do_nag_screen (self);
+ g_object_unref (doc);
+ return;
+ }
+ }
+
if (doc)
gh = HEX_WIDGET(hex_widget_new (doc));
diff --git a/src/ghex-application-window.h b/src/ghex-application-window.h
index 199a16a..ff27ee2 100644
--- a/src/ghex-application-window.h
+++ b/src/ghex-application-window.h
@@ -38,6 +38,7 @@
#include "converter.h"
#include "preferences.h"
#include "common-ui.h"
+#include "hex-buffer-malloc.h"
G_BEGIN_DECLS
diff --git a/src/hex-buffer-iface.c b/src/hex-buffer-iface.c
index 9093f7b..6133765 100644
--- a/src/hex-buffer-iface.c
+++ b/src/hex-buffer-iface.c
@@ -351,10 +351,13 @@ hex_buffer_get_payload_size (HexBuffer *self)
*
* Returns: (transfer full): a pointer to a valid implementation of a
* [iface@Hex.Buffer] interface, pre-cast as type #HexBuffer, or %NULL if
- * the operation failed.
+ * the operation failed. Starting with 4.2, if a specific backend is requested,
+ * and the system supports plugins as a whole but cannot load that specified
+ * plugin, %NULL will be returned as though the operation failed, so as to
+ * customize the fallback scheme programmatically.
*/
-
-HexBuffer * hex_buffer_util_new (const char *plugin, GFile *file)
+HexBuffer *
+hex_buffer_util_new (const char *plugin, GFile *file)
{
GModule *module;
HexBufferNewFunc func = NULL;
@@ -366,9 +369,15 @@ HexBuffer * hex_buffer_util_new (const char *plugin, GFile *file)
* if NULL is passed, fall right back to `malloc` since it's the only one
* baked in.
*/
- if (!g_module_supported () || !plugin)
+ if (! plugin)
+ {
+ g_debug ("No plugin specified; falling back to the `malloc` backend.");
+ return hex_buffer_malloc_new (file);
+ }
+ if (! g_module_supported () || !plugin)
{
- g_debug ("Modules not supported or NULL passed - falling back to `malloc` backend.");
+ g_message ("Modules not supported on this system; "
+ "falling back to `malloc` backend.");
return hex_buffer_malloc_new (file);
}
@@ -379,14 +388,13 @@ HexBuffer * hex_buffer_util_new (const char *plugin, GFile *file)
if (! module)
{
- g_warning ("Unable to load plugin at %s - falling back to `malloc` backend",
- plugin_path);
- func = hex_buffer_malloc_new;
+ g_debug ("Unable to locate/load plugin at %s", plugin_path);
+ func = NULL;
}
else if (! g_module_symbol (module, symbol_name, (gpointer *)&func) ||
func == NULL)
{
- g_warning ("Plugin found at %s - but unable to locate symbol: %s - "
+ g_message ("Plugin found at %s - but unable to locate symbol: %s - "
"falling back to `malloc` backend.",
plugin_path, symbol_name);
func = hex_buffer_malloc_new;
@@ -402,7 +410,10 @@ HexBuffer * hex_buffer_util_new (const char *plugin, GFile *file)
g_free (plugin_path);
g_free (symbol_name);
- return func (file);
+ if (func)
+ return func (file);
+ else
+ return NULL;
}
/**
diff --git a/src/hex-document.c b/src/hex-document.c
index 2d3afa1..7376a6c 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -356,13 +356,17 @@ hex_document_class_init (HexDocumentClass *klass)
static void
hex_document_init (HexDocument *doc)
{
-#ifdef BACKEND_MMAP
- doc->buffer = hex_buffer_util_new ("mmap", NULL);
-#elif defined BACKEND_DIRECT
- doc->buffer = hex_buffer_util_new ("direct", NULL);
-#else
- doc->buffer = hex_buffer_util_new (NULL, NULL);
-#endif
+ HexBuffer *try_buf = NULL;
+
+ /* FIXME - make this a setting; preferred default backend, or
+ * what-have-you.
+ */
+ try_buf = hex_buffer_util_new ("mmap", NULL);
+ if (! try_buf)
+ try_buf = hex_buffer_util_new (NULL, NULL);
+
+ g_assert (try_buf != NULL);
+ doc->buffer = try_buf;
doc->undo_max = DEFAULT_UNDO_DEPTH;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]