[ghex/expand-search-options: 16/16] hexdoc: new public struct funcs for HexDocumentFindData
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex/expand-search-options: 16/16] hexdoc: new public struct funcs for HexDocumentFindData
- Date: Sat, 23 Apr 2022 04:34:45 +0000 (UTC)
commit 8ade9debde45ebf1e824c1577bb83aaafefe1e31
Author: Logan Rathbone <poprocks gmail com>
Date: Wed Apr 20 01:16:29 2022 -0400
hexdoc: new public struct funcs for HexDocumentFindData
- bump soname for ABI break in HexDocumentFindData
- bump glib2 requirement to 2.68 to utilize g_memdup2()
meson.build | 8 +++++---
src/findreplace.c | 6 +++---
src/gtkhex.c | 2 +-
src/hex-document.c | 43 +++++++++++++++++++++++++++++++++----------
src/hex-document.h | 5 +++++
src/meson.build | 1 +
6 files changed, 48 insertions(+), 17 deletions(-)
---
diff --git a/meson.build b/meson.build
index 0e9c386..213e42c 100644
--- a/meson.build
+++ b/meson.build
@@ -29,8 +29,8 @@ ghex_version_major = version_arr[0].to_int()
# libgtkhex version info
libgtkhex_api_version = 4
-libgtkhex_version_major = 0
-libgtkhex_version_minor = 1
+libgtkhex_version_major = 1
+libgtkhex_version_minor = 0
libgtkhex_version_micro = 0
libgtkhex_version = '@0@.@1@.@2@'.format(libgtkhex_api_version, libgtkhex_version_minor,
libgtkhex_version_micro)
@@ -130,8 +130,10 @@ if mmap_backend
message('...DONE')
endif
+glib_ver = '>= 2.68.0'
gmodule_dep = dependency('gmodule-2.0')
-gio_dep = dependency('gio-2.0', version: '>= 2.66.0')
+glib_dep = dependency('glib-2.0', version: glib_ver)
+gio_dep = dependency('gio-2.0', version: glib_ver)
gtk_dep = dependency('gtk4', version: '>= 4.0.0')
configure_file(
diff --git a/src/findreplace.c b/src/findreplace.c
index 20a77a6..1787e05 100644
--- a/src/findreplace.c
+++ b/src/findreplace.c
@@ -323,7 +323,7 @@ find_common (FindDialog *self, enum FindDirection direction,
/* Search for requested string */
- find_data = g_new0 (HexDocumentFindData, 1);
+ find_data = hex_document_find_data_new ();
find_data->what = str;
find_data->len = str_len;
find_data->found_msg = found_msg;
@@ -549,7 +549,7 @@ replace_one_cb (GtkButton *button, gpointer user_data)
if (find_len > payload - cursor_pos)
goto clean_up;
- find_data = g_new0 (HexDocumentFindData, 1);
+ find_data = hex_document_find_data_new ();
find_data->start = cursor_pos;
find_data->what = find_str;
find_data->len = find_len;
@@ -613,7 +613,7 @@ replace_all_cb (GtkButton *button, gpointer user_data)
goto clean_up;
- find_data = g_new0 (HexDocumentFindData, 1);
+ find_data = hex_document_find_data_new ();
find_data->start = 0;
find_data->what = find_str;
find_data->len = find_len;
diff --git a/src/gtkhex.c b/src/gtkhex.c
index 4f158aa..a284858 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -2034,7 +2034,7 @@ hex_widget_find_limited (HexWidget *self, char *find, int findlen,
{
gboolean retval = FALSE;
gint64 pos = lower;
- HexDocumentFindData *find_data = g_new0 (HexDocumentFindData, 1);
+ HexDocumentFindData *find_data = hex_document_find_data_new ();
find_data->what = find;
find_data->len = findlen;
diff --git a/src/hex-document.c b/src/hex-document.c
index 54cd2f6..bcc7acf 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -69,16 +69,39 @@ enum {
static guint hex_signals[LAST_SIGNAL];
-/* TODO - come up with _new functions for the GTypes below and actually use
- * them. */
-
/* HexDocumentFindData GType Definitions */
-/* FIXME - unused and could be unreliable. */
-static HexDocumentFindData *
+/**
+ * hex_document_find_data_new:
+ *
+ * Create a new empty [struct@Hex.DocumentFindData] structure.
+ *
+ * Returns: a new #HexDocumentFindData structure. Can be freed with
+ * `g_free ()`.
+ *
+ * Since: 4.2
+ */
+HexDocumentFindData *
+hex_document_find_data_new (void)
+{
+ return g_new0 (HexDocumentFindData, 1);
+}
+
+/**
+ * hex_document_find_data_copy:
+ *
+ * Copy a [struct@Hex.DocumentFindData] structure. This function is likely
+ * only useful for language bindings.
+ *
+ * Returns: a newly allocated #HexDocumentFindData structure. Can be freed with
+ * `g_free ()`.
+ *
+ * Since: 4.2
+ */
+HexDocumentFindData *
hex_document_find_data_copy (HexDocumentFindData *data)
{
- return data;
+ return g_memdup2 (data, sizeof *data);
}
G_DEFINE_BOXED_TYPE (HexDocumentFindData, hex_document_find_data,
@@ -1222,7 +1245,7 @@ hex_document_compare_data (HexDocument *doc,
const char *what, gint64 pos, size_t len)
{
int retval;
- HexDocumentFindData *find_data = g_new0 (HexDocumentFindData, 1);
+ HexDocumentFindData *find_data = hex_document_find_data_new ();
find_data->what = what;
find_data->len = len;
@@ -1299,7 +1322,7 @@ hex_document_find_forward (HexDocument *doc, gint64 start, const char *what,
size_t len, gint64 *offset)
{
gboolean retval;
- HexDocumentFindData *find_data = g_new0 (HexDocumentFindData, 1);
+ HexDocumentFindData *find_data = hex_document_find_data_new ();
find_data->start = start;
find_data->what = what;
@@ -1433,7 +1456,7 @@ FUNC_NAME (HexDocument *doc, \
gpointer user_data) \
{ \
GTask *task; \
- HexDocumentFindData *find_data = g_new0 (HexDocumentFindData, 1); \
+ HexDocumentFindData *find_data = hex_document_find_data_new (); \
\
find_data->start = start; \
find_data->what = what; \
@@ -1512,7 +1535,7 @@ hex_document_find_backward (HexDocument *doc, gint64 start, const char *what,
size_t len, gint64 *offset)
{
gboolean retval;
- HexDocumentFindData *find_data = g_new0 (HexDocumentFindData, 1);
+ HexDocumentFindData *find_data = hex_document_find_data_new ();
find_data->start = start;
find_data->what = what;
diff --git a/src/hex-document.h b/src/hex-document.h
index be627ea..73b364e 100644
--- a/src/hex-document.h
+++ b/src/hex-document.h
@@ -221,6 +221,11 @@ gboolean hex_document_set_file (HexDocument *doc, GFile *file);
HexChangeData * hex_document_get_undo_data (HexDocument *doc);
HexBuffer * hex_document_get_buffer (HexDocument *doc);
+/* HexDocumentFindData functions */
+
+HexDocumentFindData *hex_document_find_data_new (void);
+HexDocumentFindData *hex_document_find_data_copy (HexDocumentFindData *data);
+
G_END_DECLS
#endif /* HEX_DOCUMENT_H */
diff --git a/src/meson.build b/src/meson.build
index 60c32d9..c5f57e8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -16,6 +16,7 @@ libgtkhex_headers = [
libgtkhex_deps = [
gmodule_dep,
+ glib_dep,
gio_dep,
gtk_dep,
]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]