Creates a more-explicitly-type-unsafe value reader for enums.
authorOmari Stephens <xsdg@xsdg.org>
Mon, 30 May 2022 08:15:58 +0000 (08:15 +0000)
committerColin Clark <colin.clark@cclark.uk>
Sun, 7 Aug 2022 08:41:53 +0000 (09:41 +0100)
This code relies on our ability to read a guint into an enum address.  C++ forbids this being done implicitly, so we do it explicitly.

src/filefilter.c
src/layout.c
src/rcfile.c
src/rcfile.h

index 1efdd49..c1430d3 100644 (file)
@@ -547,7 +547,7 @@ void filter_load_file_type(const gchar **attribute_names, const gchar **attribut
                if (READ_BOOL(fe, enabled)) continue;
                if (READ_CHAR(fe, extensions)) continue;
                if (READ_CHAR(fe, description)) continue;
-               if (READ_UINT(fe, file_class)) continue;
+               if (READ_UINT_ENUM(fe, file_class)) continue;
                if (READ_BOOL(fe, writable)) continue;
                if (READ_BOOL(fe, allow_sidecar)) continue;
 
index dc0482b..1662644 100644 (file)
@@ -2859,16 +2859,16 @@ void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names
                if (READ_INT(*layout, style)) continue;
                if (READ_CHAR(*layout, order)) continue;
 
-               if (READ_UINT(*layout, dir_view_type)) continue;
-               if (READ_UINT(*layout, file_view_type)) continue;
-               if (READ_UINT(*layout, dir_view_list_sort.method)) continue;
+               if (READ_UINT_ENUM(*layout, dir_view_type)) continue;
+               if (READ_UINT_ENUM(*layout, file_view_type)) continue;
+               if (READ_UINT_ENUM(*layout, dir_view_list_sort.method)) continue;
                if (READ_BOOL(*layout, dir_view_list_sort.ascend)) continue;
                if (READ_BOOL(*layout, show_marks)) continue;
                if (READ_BOOL(*layout, show_file_filter)) continue;
                if (READ_BOOL(*layout, show_thumbnails)) continue;
                if (READ_BOOL(*layout, show_directory_date)) continue;
                if (READ_CHAR(*layout, home_path)) continue;
-               if (READ_UINT_CLAMP(*layout, startup_path, 0, STARTUP_PATH_HOME)) continue;
+               if (READ_UINT_ENUM_CLAMP(*layout, startup_path, 0, STARTUP_PATH_HOME)) continue;
 
                /* window positions */
 
index 23e64c3..125bf1e 100644 (file)
@@ -837,7 +837,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_INT(*options, open_recent_list_maxsize)) continue;
                if (READ_INT(*options, recent_folder_image_list_maxsize)) continue;
                if (READ_INT(*options, dnd_icon_size)) continue;
-               if (READ_UINT(*options, dnd_default_action)) continue;
+               if (READ_UINT_ENUM(*options, dnd_default_action)) continue;
                if (READ_BOOL(*options, place_dialogs_under_mouse)) continue;
                if (READ_INT(*options, clipboard_selection)) continue;
 
@@ -868,8 +868,8 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_BOOL(*options, with_rename)) continue;
 
                /* Image options */
-               if (READ_UINT_CLAMP(*options, image.zoom_mode, 0, ZOOM_RESET_NONE)) continue;
-               if (READ_UINT_CLAMP(*options, image.zoom_style, 0, ZOOM_ARITHMETIC)) continue;
+               if (READ_UINT_ENUM_CLAMP(*options, image.zoom_mode, 0, ZOOM_RESET_NONE)) continue;
+               if (READ_UINT_ENUM_CLAMP(*options, image.zoom_style, 0, ZOOM_ARITHMETIC)) continue;
                if (READ_BOOL(*options, image.zoom_2pass)) continue;
                if (READ_BOOL(*options, image.zoom_to_fit_allow_expand)) continue;
                if (READ_BOOL(*options, image.fit_window_to_image)) continue;
@@ -909,7 +909,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
 //             if (READ_BOOL(*options, thumbnails.use_ft_metadata_small)) continue;
 
                /* File sorting options */
-               if (READ_UINT(*options, file_sort.method)) continue;
+               if (READ_UINT_ENUM(*options, file_sort.method)) continue;
                if (READ_BOOL(*options, file_sort.ascending)) continue;
                if (READ_BOOL(*options, file_sort.case_sensitive)) continue;
                if (READ_BOOL(*options, file_sort.natural)) continue;
index 4d873ba..7aa1bf9 100644 (file)
@@ -56,9 +56,11 @@ gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *
 #define READ_BOOL(_target_, _name_) read_bool_option(option, #_name_, value, &(_target_)._name_)
 #define READ_INT(_target_, _name_) read_int_option(option, #_name_, value, &(_target_)._name_)
 #define READ_UINT(_target_, _name_) read_uint_option(option, #_name_, value, &(_target_)._name_)
+#define READ_UINT_ENUM(_target_, _name_) read_uint_option(option, #_name_, value, (guint*)&(_target_)._name_)
 #define READ_USHORT(_target_, _name_) read_ushort_option(option, #_name_, value, &(_target_)._name_)
 #define READ_INT_CLAMP(_target_, _name_, _min_, _max_) read_int_option_clamp(option, #_name_, value, &(_target_)._name_, _min_, _max_)
 #define READ_UINT_CLAMP(_target_, _name_, _min_, _max_) read_uint_option_clamp(option, #_name_, value, &(_target_)._name_, _min_, _max_)
+#define READ_UINT_ENUM_CLAMP(_target_, _name_, _min_, _max_) read_uint_option_clamp(option, #_name_, value, (guint*)&(_target_)._name_, _min_, _max_)
 #define READ_INT_UNIT(_target_, _name_, _unit_) read_int_unit_option(option, #_name_, value, &(_target_)._name_, _unit_)
 #define READ_CHAR(_target_, _name_) read_char_option(option, #_name_, value, &(_target_)._name_)
 #define READ_COLOR(_target_, _name_) read_color_option(option, #_name_, value, &(_target_)._name_)