From 4ca8825e02ff8959e3790df2d7818ecfb4134963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Sun, 5 Jun 2022 13:29:38 +0200 Subject: [PATCH] Clean up Use gchar when memory is allocated through GLib. --- fiv-browser.c | 4 ++-- fiv-io.c | 34 +++++++++++++++++----------------- fiv-io.h | 10 +++++----- fiv-jpegcrop.c | 6 +++--- fiv-sidebar.c | 4 ++-- fiv-thumbnail.c | 6 +++--- fiv-view.c | 4 ++-- fiv-view.h | 2 +- fiv.c | 16 ++++++++-------- xdg.c | 10 +++++----- 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/fiv-browser.c b/fiv-browser.c index df2b63d..4c4dab6 100644 --- a/fiv-browser.c +++ b/fiv-browser.c @@ -90,7 +90,7 @@ struct _FivBrowser { static cairo_user_data_key_t fiv_browser_key_mtime_msec; struct entry { - char *uri; ///< GIO URI + gchar *uri; ///< GIO URI gint64 mtime_msec; ///< Modification time in milliseconds cairo_surface_t *thumbnail; ///< Prescaled thumbnail GIcon *icon; ///< If no thumbnail, use this icon @@ -706,7 +706,7 @@ thumbnailers_start(FivBrowser *self) typedef struct _OpenContext { GWeakRef widget; GFile *file; - char *content_type; + gchar *content_type; GAppInfo *app_info; } OpenContext; diff --git a/fiv-io.c b/fiv-io.c index ddb8526..b0766b9 100644 --- a/fiv-io.c +++ b/fiv-io.c @@ -115,7 +115,7 @@ const char *fiv_io_supported_media_types[] = { NULL }; -char ** +gchar ** fiv_io_all_supported_media_types(void) { GPtrArray *types = g_ptr_array_new(); @@ -957,7 +957,7 @@ fail: static cairo_surface_t * open_wuffs_using(wuffs_base__image_decoder *(*allocate)(), - const gchar *data, gsize len, const FivIoOpenContext *ctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ctx, GError **error) { wuffs_base__image_decoder *dec = allocate(); if (!dec) { @@ -1135,7 +1135,7 @@ fail: // --- JPEG -------------------------------------------------------------------- static GBytes * -parse_jpeg_metadata(cairo_surface_t *surface, const gchar *data, gsize len) +parse_jpeg_metadata(cairo_surface_t *surface, const char *data, gsize len) { // Because the JPEG file format is simple, just do it manually. // See: https://www.w3.org/Graphics/JPEG/itu-t81.pdf @@ -1228,7 +1228,7 @@ parse_jpeg_metadata(cairo_surface_t *surface, const gchar *data, gsize len) static void load_jpeg_finalize(cairo_surface_t *surface, bool cmyk, - FivIoProfile destination, const gchar *data, size_t len) + FivIoProfile destination, const char *data, size_t len) { GBytes *icc_profile = parse_jpeg_metadata(surface, data, len); FivIoProfile source = NULL; @@ -1250,7 +1250,7 @@ load_jpeg_finalize(cairo_surface_t *surface, bool cmyk, static cairo_surface_t * open_libjpeg_turbo( - const gchar *data, gsize len, const FivIoOpenContext *ctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ctx, GError **error) { // Note that there doesn't seem to be much of a point in using this // simplified API anymore, because JPEG-QS needs the original libjpeg API. @@ -1351,7 +1351,7 @@ libjpeg_error_exit(j_common_ptr cinfo) static cairo_surface_t * open_libjpeg_enhanced( - const gchar *data, gsize len, const FivIoOpenContext *ctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ctx, GError **error) { cairo_surface_t *volatile surface = NULL; @@ -1613,7 +1613,7 @@ fail: static cairo_surface_t * open_libwebp( - const gchar *data, gsize len, const FivIoOpenContext *ctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ctx, GError **error) { // It is wholly zero-initialized by libwebp. WebPDecoderConfig config = {}; @@ -1698,7 +1698,7 @@ fail: #ifdef HAVE_LIBRAW // --------------------------------------------------------- static cairo_surface_t * -open_libraw(const gchar *data, gsize len, GError **error) +open_libraw(const char *data, gsize len, GError **error) { // https://github.com/LibRaw/LibRaw/issues/418 libraw_data_t *iprc = libraw_init( @@ -1884,7 +1884,7 @@ load_resvg_error(int err) static cairo_surface_t * open_resvg( - const gchar *data, gsize len, const FivIoOpenContext *ctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ctx, GError **error) { GFile *file = g_file_new_for_uri(ctx->uri); GFile *base_file = g_file_get_parent(file); @@ -1974,7 +1974,7 @@ load_librsvg_render(FivIoRenderClosure *closure, double scale) static cairo_surface_t * open_librsvg( - const gchar *data, gsize len, const FivIoOpenContext *ctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ctx, GError **error) { GFile *base_file = g_file_new_for_uri(ctx->uri); GInputStream *is = g_memory_input_stream_new_from_data(data, len, NULL); @@ -2108,7 +2108,7 @@ static const XcursorFile fiv_io_xcursor_adaptor = { }; static cairo_surface_t * -open_xcursor(const gchar *data, gsize len, GError **error) +open_xcursor(const char *data, gsize len, GError **error) { if (len > G_MAXLONG) { set_error(error, "size overflow"); @@ -2318,7 +2318,7 @@ load_libheif_aux_images(const FivIoOpenContext *ioctx, static cairo_surface_t * open_libheif( - const gchar *data, gsize len, const FivIoOpenContext *ioctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ioctx, GError **error) { // libheif will throw C++ exceptions on allocation failures. // The library is generally awful through and through. @@ -2547,7 +2547,7 @@ fail: static cairo_surface_t * open_libtiff( - const gchar *data, gsize len, const FivIoOpenContext *ctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ctx, GError **error) { // Both kinds of handlers are called, redirect everything. TIFFErrorHandler eh = TIFFSetErrorHandler(NULL); @@ -2651,7 +2651,7 @@ load_gdkpixbuf_argb32_unpremultiplied(GdkPixbuf *pixbuf) static cairo_surface_t * open_gdkpixbuf( - const gchar *data, gsize len, const FivIoOpenContext *ctx, GError **error) + const char *data, gsize len, const FivIoOpenContext *ctx, GError **error) { // gdk-pixbuf controls the playback itself, there is no reliable method of // extracting individual frames (due to loops). @@ -3002,7 +3002,7 @@ static guint model_signals[LAST_SIGNAL]; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static gboolean -model_supports(FivIoModel *self, const gchar *filename) +model_supports(FivIoModel *self, const char *filename) { gchar *utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); if (!utf8) @@ -3410,7 +3410,7 @@ set_metadata(WebPMux *mux, const char *fourcc, GBytes *data) gboolean fiv_io_save(cairo_surface_t *page, cairo_surface_t *frame, FivIoProfile target, - const gchar *path, GError **error) + const char *path, GError **error) { g_return_val_if_fail(page != NULL, FALSE); g_return_val_if_fail(path != NULL, FALSE); @@ -3574,7 +3574,7 @@ fiv_io_exif_orientation(const guint8 *tiff, gsize len) } gboolean -fiv_io_save_metadata(cairo_surface_t *page, const gchar *path, GError **error) +fiv_io_save_metadata(cairo_surface_t *page, const char *path, GError **error) { g_return_val_if_fail(page != NULL, FALSE); diff --git a/fiv-io.h b/fiv-io.h index 3d5aca6..0c23799 100644 --- a/fiv-io.h +++ b/fiv-io.h @@ -39,7 +39,7 @@ void fiv_io_profile_free(FivIoProfile self); extern const char *fiv_io_supported_media_types[]; -char **fiv_io_all_supported_media_types(void); +gchar **fiv_io_all_supported_media_types(void); // Userdata are typically attached to all Cairo surfaces in an animation. @@ -127,8 +127,8 @@ gboolean fiv_io_model_open(FivIoModel *self, GFile *directory, GError **error); GFile *fiv_io_model_get_location(FivIoModel *self); typedef struct { - char *uri; ///< GIO URI - char *collate_key; ///< Collate key for the filename + gchar *uri; ///< GIO URI + gchar *collate_key; ///< Collate key for the filename gint64 mtime_msec; ///< Modification time in milliseconds } FivIoModelEntry; @@ -145,7 +145,7 @@ unsigned char *fiv_io_encode_webp( /// Saves the page as a lossless WebP still picture or animation. /// If no exact frame is specified, this potentially creates an animation. gboolean fiv_io_save(cairo_surface_t *page, cairo_surface_t *frame, - FivIoProfile target, const gchar *path, GError **error); + FivIoProfile target, const char *path, GError **error); // --- Metadata ---------------------------------------------------------------- @@ -173,4 +173,4 @@ FivIoOrientation fiv_io_exif_orientation(const guint8 *exif, gsize len); /// Save metadata attached by this module in Exiv2 format. gboolean fiv_io_save_metadata( - cairo_surface_t *page, const gchar *path, GError **error); + cairo_surface_t *page, const char *path, GError **error); diff --git a/fiv-jpegcrop.c b/fiv-jpegcrop.c index 4bbcd97..50828c7 100644 --- a/fiv-jpegcrop.c +++ b/fiv-jpegcrop.c @@ -22,10 +22,10 @@ // --- Utilities --------------------------------------------------------------- -static void exit_fatal(const gchar *format, ...) G_GNUC_PRINTF(1, 2); +static void exit_fatal(const char *format, ...) G_GNUC_PRINTF(1, 2); static void -exit_fatal(const gchar *format, ...) +exit_fatal(const char *format, ...) { va_list ap; va_start(ap, format); @@ -250,7 +250,7 @@ on_motion(G_GNUC_UNUSED GtkWidget *self, GdkEventMotion *event, } static gboolean -open_jpeg(const gchar *data, gsize len, GError **error) +open_jpeg(const char *data, gsize len, GError **error) { tjhandle h = tjInitDecompress(); if (!h) { diff --git a/fiv-sidebar.c b/fiv-sidebar.c index bc96d03..aa648a6 100644 --- a/fiv-sidebar.c +++ b/fiv-sidebar.c @@ -306,9 +306,9 @@ complete_path(GFile *location, GtkListStore *model) g_file_info_get_is_hidden(info)) continue; - char *parse_name = g_file_get_parse_name(child); + gchar *parse_name = g_file_get_parse_name(child); if (!g_str_has_suffix(parse_name, G_DIR_SEPARATOR_S)) { - char *save = parse_name; + gchar *save = parse_name; parse_name = g_strdup_printf("%s%c", parse_name, G_DIR_SEPARATOR); g_free(save); } diff --git a/fiv-thumbnail.c b/fiv-thumbnail.c index c6e1896..18be4eb 100644 --- a/fiv-thumbnail.c +++ b/fiv-thumbnail.c @@ -378,7 +378,7 @@ fiv_thumbnail_produce(GFile *target, FivThumbnailSize max_size, } static bool -check_wide_thumbnail_texts(GBytes *thum, const gchar *target, time_t mtime, +check_wide_thumbnail_texts(GBytes *thum, const char *target, time_t mtime, bool *sRGB) { gsize len = 0; @@ -409,7 +409,7 @@ check_wide_thumbnail_texts(GBytes *thum, const gchar *target, time_t mtime, static cairo_surface_t * read_wide_thumbnail( - const gchar *path, const gchar *uri, time_t mtime, GError **error) + const char *path, const char *uri, time_t mtime, GError **error) { gchar *thumbnail_uri = g_filename_to_uri(path, NULL, error); if (!thumbnail_uri) @@ -447,7 +447,7 @@ read_wide_thumbnail( static cairo_surface_t * read_png_thumbnail( - const gchar *path, const gchar *uri, time_t mtime, GError **error) + const char *path, const char *uri, time_t mtime, GError **error) { cairo_surface_t *surface = fiv_io_open_png_thumbnail(path, error); if (!surface) diff --git a/fiv-view.c b/fiv-view.c index 8378a5a..9526a6c 100644 --- a/fiv-view.c +++ b/fiv-view.c @@ -1161,7 +1161,7 @@ fiv_view_init(FivView *self) // --- Public interface -------------------------------------------------------- static cairo_surface_t * -open_without_swapping_in(FivView *self, const gchar *uri) +open_without_swapping_in(FivView *self, const char *uri) { FivIoOpenContext ctx = { .uri = uri, @@ -1190,7 +1190,7 @@ open_without_swapping_in(FivView *self, const gchar *uri) // TODO(p): Progressive picture loading, or at least async/cancellable. gboolean -fiv_view_set_uri(FivView *self, const gchar *uri) +fiv_view_set_uri(FivView *self, const char *uri) { // This is extremely expensive, and only works sometimes. g_clear_pointer(&self->enhance_swap, cairo_surface_destroy); diff --git a/fiv-view.h b/fiv-view.h index 7df00e0..c2d8b8b 100644 --- a/fiv-view.h +++ b/fiv-view.h @@ -24,7 +24,7 @@ G_DECLARE_FINAL_TYPE(FivView, fiv_view, FIV, VIEW, GtkWidget) /// Try to open the given file, synchronously, to be displayed by the widget. /// The current image is cleared on failure. -gboolean fiv_view_set_uri(FivView *self, const gchar *uri); +gboolean fiv_view_set_uri(FivView *self, const char *uri); // And this is how you avoid glib-mkenums. typedef enum _FivViewCommand { diff --git a/fiv.c b/fiv.c index acf35ea..9486f06 100644 --- a/fiv.c +++ b/fiv.c @@ -35,10 +35,10 @@ // --- Utilities --------------------------------------------------------------- -static void exit_fatal(const gchar *format, ...) G_GNUC_PRINTF(1, 2); +static void exit_fatal(const char *format, ...) G_GNUC_PRINTF(1, 2); static void -exit_fatal(const gchar *format, ...) +exit_fatal(const char *format, ...) { va_list ap; va_start(ap, format); @@ -618,7 +618,7 @@ update_files_index(void) } static void -load_directory_without_reload(const gchar *uri) +load_directory_without_reload(const char *uri) { gchar *uri_duplicated = g_strdup(uri); if (g.directory_back && !strcmp(uri, g.directory_back->data)) { @@ -657,7 +657,7 @@ load_directory_without_reload(const gchar *uri) } static void -load_directory_without_switching(const gchar *uri) +load_directory_without_switching(const char *uri) { if (uri) { load_directory_without_reload(uri); @@ -682,7 +682,7 @@ load_directory_without_switching(const gchar *uri) } static void -load_directory(const gchar *uri) +load_directory(const char *uri) { load_directory_without_switching(uri); @@ -761,7 +761,7 @@ on_notify_view_messages(FivView *view, G_GNUC_UNUSED gpointer user_data) } static void -open(const gchar *uri) +open(const char *uri) { GFile *file = g_file_new_for_uri(uri); if (fiv_view_set_uri(FIV_VIEW(g.view), uri)) @@ -1322,7 +1322,7 @@ on_button_press_browser_paned( } static GtkWidget * -make_toolbar_button(const gchar *symbolic, const gchar *tooltip) +make_toolbar_button(const char *symbolic, const char *tooltip) { GtkWidget *button = gtk_button_new(); gtk_button_set_image(GTK_BUTTON(button), @@ -1335,7 +1335,7 @@ make_toolbar_button(const gchar *symbolic, const gchar *tooltip) } static GtkWidget * -make_toolbar_toggle(const gchar *symbolic, const gchar *tooltip) +make_toolbar_toggle(const char *symbolic, const char *tooltip) { GtkWidget *button = gtk_toggle_button_new(); gtk_button_set_image(GTK_BUTTON(button), diff --git a/xdg.c b/xdg.c index 7ebd5de..503b9a1 100644 --- a/xdg.c +++ b/xdg.c @@ -21,7 +21,7 @@ /// defining is-a relations, and is traversed recursively. static void add_applying_transitive_closure( - const gchar *element, GHashTable *relation, GHashTable *output) + const char *element, GHashTable *relation, GHashTable *output) { // Stop condition. if (!g_hash_table_add(output, g_strdup(element))) @@ -61,7 +61,7 @@ get_xdg_data_dirs(void) GPtrArray *output = g_ptr_array_new_with_free_func(g_free); g_ptr_array_add(output, get_xdg_home_dir("XDG_DATA_HOME", ".local/share")); - const gchar *xdg_data_dirs; + const char *xdg_data_dirs; if (!(xdg_data_dirs = getenv("XDG_DATA_DIRS")) || !*xdg_data_dirs) xdg_data_dirs = "/usr/local/share/:/usr/share/"; @@ -82,7 +82,7 @@ get_xdg_data_dirs(void) // Derived from shared-mime-info-spec 0.21. static void -read_mime_subclasses(const gchar *path, GHashTable *subclass_sets) +read_mime_subclasses(const char *path, GHashTable *subclass_sets) { gchar *data = NULL; if (!g_file_get_contents(path, &data, NULL /* length */, NULL /* error */)) @@ -112,7 +112,7 @@ read_mime_subclasses(const gchar *path, GHashTable *subclass_sets) } static gboolean -filter_mime_globs(const gchar *path, guint is_globs2, GHashTable *supported_set, +filter_mime_globs(const char *path, guint is_globs2, GHashTable *supported_set, GHashTable *output_set) { gchar *data = NULL; @@ -120,7 +120,7 @@ filter_mime_globs(const gchar *path, guint is_globs2, GHashTable *supported_set, return FALSE; gchar *datasave = NULL; - for (const gchar *line = strtok_r(data, "\r\n", &datasave); line; + for (const char *line = strtok_r(data, "\r\n", &datasave); line; line = strtok_r(NULL, "\r\n", &datasave)) { if (*line == '#') continue;