[balsa/66-save-and-open-folder] remove unnecessary checks, exported methods



commit ddb5ee0c57d5a88e52320c2d6e493375f6a7b287
Author: Albrecht Dreß <albrecht dress netcologne de>
Date:   Sun Jan 23 16:02:48 2022 +0100

    remove unnecessary checks, exported methods
    
    See #66 and the discussion in
    https://gitlab.gnome.org/GNOME/balsa/-/commit/0e5ea496a7f0339b419b9dcca89733311881408d#note_1363373.
    
    g_object_new() will return NULL in OOM conditions only, and the object
    will be initialised properly.  Thus, we can safely omit some paranoid
    checks.  Furthermore, locally used methods shall not be exported.
    
    Details:
    - libbalsa/libbalsa-vfs.[ch]: throw paranoid assertion instead of
    returning NULL in libbalsa_vfs_new_from_uri(), remove
    libbalsa_vfs_new(), do not export libbalsa_vfs_get_text_attr()
    - libnetclient/net-client-(pop|siobuf|smtp).c: throw paranoid assertion
    instead of returning NULL in constructors
    - src/balsa-message.c, src/balsa-mime-widget-callbacks.c,
    src/sendmgs-window.c: libbalsa_vfs_new_from_uri() does never return NULL
    
    Signed-off-by: Albrecht Dreß <albrecht dress netcologne de>

 libbalsa/libbalsa-vfs.c           | 16 +++++-----------
 libbalsa/libbalsa-vfs.h           |  4 +---
 libnetclient/net-client-pop.c     | 12 ++++--------
 libnetclient/net-client-siobuf.c  | 14 +++++---------
 libnetclient/net-client-smtp.c    | 10 +++-------
 src/balsa-message.c               |  5 +----
 src/balsa-mime-widget-callbacks.c |  8 +-------
 src/sendmsg-window.c              |  8 +-------
 8 files changed, 21 insertions(+), 56 deletions(-)
---
diff --git a/libbalsa/libbalsa-vfs.c b/libbalsa/libbalsa-vfs.c
index 49efc57ab..be859725b 100644
--- a/libbalsa/libbalsa-vfs.c
+++ b/libbalsa/libbalsa-vfs.c
@@ -1,7 +1,7 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
 /*
  * libbalsa vfs glue layer library
- * Copyright (C) 2008 Albrecht Dre� <albrecht dress arcor de>
+ * Copyright (C) 2008 Albrecht Dre� <albrecht dress arcor de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -65,6 +65,7 @@ struct _LibbalsaVfs {
 
 static void libbalsa_vfs_dispose(GObject *object);
 static void libbalsa_vfs_finalize(GObject *object);
+static LibBalsaTextAttribute libbalsa_vfs_get_text_attr(LibbalsaVfs * file);
 
 
 gboolean
@@ -121,13 +122,6 @@ libbalsa_vfs_finalize(GObject *object)
 }
 
 
-LibbalsaVfs *
-libbalsa_vfs_new(void)
-{
-    return LIBBALSA_VFS(g_object_new(LIBBALSA_TYPE_VFS, NULL));
-}
-
-
 LibbalsaVfs *
 libbalsa_vfs_new_from_uri(const gchar * uri)
 {
@@ -135,8 +129,8 @@ libbalsa_vfs_new_from_uri(const gchar * uri)
 
     g_return_val_if_fail(uri != NULL, NULL);
 
-    if ((retval = libbalsa_vfs_new()) == NULL)
-        return NULL;
+    retval = LIBBALSA_VFS(g_object_new(LIBBALSA_TYPE_VFS, NULL));
+    g_assert(retval != NULL);
 
     retval->text_attr = (LibBalsaTextAttribute) -1;
 
@@ -333,7 +327,7 @@ libbalsa_vfs_get_charset(LibbalsaVfs * file)
 }
 
 
-LibBalsaTextAttribute
+static LibBalsaTextAttribute
 libbalsa_vfs_get_text_attr(LibbalsaVfs * file)
 {
     g_return_val_if_fail(LIBBALSA_IS_VFS(file), 0);
diff --git a/libbalsa/libbalsa-vfs.h b/libbalsa/libbalsa-vfs.h
index e2b71cda3..99a020f19 100644
--- a/libbalsa/libbalsa-vfs.h
+++ b/libbalsa/libbalsa-vfs.h
@@ -1,7 +1,7 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
 /*
  * libbalsa vfs glue layer library
- * Copyright (C) 2008 Albrecht Dre� <albrecht dress arcor de>
+ * Copyright (C) 2008 Albrecht Dre� <albrecht dress arcor de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -43,7 +43,6 @@ G_DECLARE_FINAL_TYPE(LibbalsaVfs,
 
 
 gboolean libbalsa_vfs_local_only(void);
-LibbalsaVfs * libbalsa_vfs_new(void);
 LibbalsaVfs * libbalsa_vfs_new_from_uri(const gchar * uri);
 LibbalsaVfs * libbalsa_vfs_append(LibbalsaVfs * file,
                                   const gchar * text);
@@ -55,7 +54,6 @@ const gchar * libbalsa_vfs_get_uri_utf8(LibbalsaVfs * file);
 const gchar * libbalsa_vfs_get_basename_utf8(LibbalsaVfs * file);
 const gchar * libbalsa_vfs_get_mime_type(LibbalsaVfs * file);
 const gchar * libbalsa_vfs_get_charset(LibbalsaVfs * file);
-LibBalsaTextAttribute libbalsa_vfs_get_text_attr(LibbalsaVfs * file);
 guint64 libbalsa_vfs_get_size(LibbalsaVfs * file);
 GMimeStream * libbalsa_vfs_create_stream(LibbalsaVfs * file,
                                          mode_t mode, 
diff --git a/libnetclient/net-client-pop.c b/libnetclient/net-client-pop.c
index abf78b7cb..6141c9b2d 100644
--- a/libnetclient/net-client-pop.c
+++ b/libnetclient/net-client-pop.c
@@ -81,15 +81,11 @@ net_client_pop_new(const gchar *host, guint16 port, NetClientCryptMode crypt_mod
                NULL);
 
        client = NET_CLIENT_POP(g_object_new(NET_CLIENT_POP_TYPE, NULL));
-       if (client != NULL) {
-               if (!net_client_configure(NET_CLIENT(client), host, port, MAX_POP_LINE_LEN, NULL)) {
-                       g_object_unref(client);
-                       client = NULL;
-               } else {
-                       client->crypt_mode = crypt_mode;
-                       client->use_pipelining = use_pipelining;
-               }
+       if (!net_client_configure(NET_CLIENT(client), host, port, MAX_POP_LINE_LEN, NULL)) {
+               g_assert_not_reached();
        }
+       client->crypt_mode = crypt_mode;
+       client->use_pipelining = use_pipelining;
 
        return client;
 }
diff --git a/libnetclient/net-client-siobuf.c b/libnetclient/net-client-siobuf.c
index e60fbfdf7..66a2cb630 100644
--- a/libnetclient/net-client-siobuf.c
+++ b/libnetclient/net-client-siobuf.c
@@ -45,16 +45,12 @@ net_client_siobuf_new(const gchar *host, guint16 port)
        g_return_val_if_fail(host != NULL, NULL);
 
        client = NET_CLIENT_SIOBUF(g_object_new(NET_CLIENT_SIOBUF_TYPE, NULL));
-       if (client != NULL) {
-               if (!net_client_configure(NET_CLIENT(client), host, port, 0, NULL)) {
-                       g_object_unref(client);
-                       client = NULL;
-               } else {
-                       client->buffer = g_string_sized_new(1024U);
-                       client->read_ptr = NULL;
-                       client->writebuf = g_string_sized_new(1024U);
-               }
+       if (!net_client_configure(NET_CLIENT(client), host, port, 0, NULL)) {
+               g_assert_not_reached();
        }
+       client->buffer = g_string_sized_new(1024U);
+       client->read_ptr = NULL;
+       client->writebuf = g_string_sized_new(1024U);
 
        return client;
 }
diff --git a/libnetclient/net-client-smtp.c b/libnetclient/net-client-smtp.c
index 7171a2fb2..48b45838d 100644
--- a/libnetclient/net-client-smtp.c
+++ b/libnetclient/net-client-smtp.c
@@ -83,14 +83,10 @@ net_client_smtp_new(const gchar *host, guint16 port, NetClientCryptMode crypt_mo
                NULL);
 
        client = NET_CLIENT_SMTP(g_object_new(NET_CLIENT_SMTP_TYPE, NULL));
-       if (client != NULL) {
-               if (!net_client_configure(NET_CLIENT(client), host, port, MAX_SMTP_LINE_LEN, NULL)) {
-                       g_object_unref(client);
-                       client = NULL;
-               } else {
-                       client->crypt_mode = crypt_mode;
-               }
+       if (!net_client_configure(NET_CLIENT(client), host, port, MAX_SMTP_LINE_LEN, NULL)) {
+               g_assert_not_reached();
        }
+       client->crypt_mode = crypt_mode;
 
        return client;
 }
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 6939a3aaa..31027a9bf 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -1778,10 +1778,7 @@ part_context_dump_all_cb(GtkWidget * menu_item, GList * info_list)
         LibbalsaVfs * dir_uri;
 
         g_debug("store to URI: %s", dir_name);
-        if (!(dir_uri = libbalsa_vfs_new_from_uri(dir_name)))
-            balsa_information(LIBBALSA_INFORMATION_ERROR,
-                              _("Could not create URI for %s"),
-                              dir_name);
+        dir_uri = libbalsa_vfs_new_from_uri(dir_name);
 
        /* remember the folder */
        g_free(balsa_app.save_dir);
diff --git a/src/balsa-mime-widget-callbacks.c b/src/balsa-mime-widget-callbacks.c
index a18b35bd5..adac188ba 100644
--- a/src/balsa-mime-widget-callbacks.c
+++ b/src/balsa-mime-widget-callbacks.c
@@ -117,13 +117,7 @@ balsa_mime_widget_ctx_menu_save(GtkWidget * parent_widget,
     /* get the file name */
     file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(save_dialog));
     gtk_widget_destroy(save_dialog);
-    if (!(save_file = libbalsa_vfs_new_from_uri(file_uri))) {
-        balsa_information(LIBBALSA_INFORMATION_ERROR,
-                          _("Could not construct URI from %s"),
-                          file_uri);
-        g_free(file_uri);
-       return;
-    }
+    save_file = libbalsa_vfs_new_from_uri(file_uri);
 
     /* remember the folder uri */
     g_free(balsa_app.save_dir);
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index b60d08ce6..10711675d 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1659,13 +1659,7 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
     gchar *content_desc;
 
     g_debug("Trying to attach '%s'", filename);
-    if (!(file_uri = libbalsa_vfs_new_from_uri(filename))) {
-        balsa_information_parented(GTK_WINDOW(bsmsg->window),
-                                   LIBBALSA_INFORMATION_ERROR,
-                                   _("Cannot create file URI object for %s"),
-                                   filename);
-        return FALSE;
-    }
+    file_uri = libbalsa_vfs_new_from_uri(filename);
     if (!libbalsa_vfs_is_regular_file(file_uri, &err)) {
         balsa_information_parented(GTK_WINDOW(bsmsg->window),
                                    LIBBALSA_INFORMATION_ERROR,


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