Browse Source

Use g_assert() instead of assert(3).

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 8 years ago
parent
commit
9a39e35dc3
10 changed files with 49 additions and 75 deletions
  1. 1 0
      acinclude.m4
  2. 3 1
      configure.ac
  3. 0 11
      lib/global.h
  4. 1 6
      lib/strutil.h
  5. 1 6
      lib/strutil/xstrtol.c
  6. 21 0
      m4.include/mc-assert.m4
  7. 4 11
      src/editor/editcmd.c
  8. 2 6
      src/viewer/coord_cache.c
  9. 12 28
      src/viewer/datasource.c
  10. 4 6
      src/viewer/display.c

+ 1 - 0
acinclude.m4

@@ -21,3 +21,4 @@ m4_include([m4.include/mc-vfs.m4])
 m4_include([m4.include/mc-version.m4])
 m4_include([m4.include/mc-tests.m4])
 m4_include([m4.include/mc-i18n.m4])
+m4_include([m4.include/mc-assert.m4])

+ 3 - 1
configure.ac

@@ -161,7 +161,6 @@ AC_CHECK_HEADERS([string.h memory.h limits.h malloc.h \
 	sys/select.h sys/ioctl.h stropts.h arpa/inet.h \
 	sys/socket.h])
 AC_HEADER_MAJOR
-AC_HEADER_ASSERT
 
 
 dnl ############################################################################
@@ -386,6 +385,8 @@ dnl ############################################################################
 dnl MC options
 dnl ############################################################################
 
+mc_ASSERT
+
 mc_WITH_INTERNAL_EDIT
 
 dnl Diff viewer support.
@@ -649,6 +650,7 @@ Configuration:
   Source code location:       ${srcdir}
   Compiler:                   ${CC}
   Compiler flags:             ${CFLAGS}
+  Assertions:                 ${enable_assert}
   File system:                ${vfs_type}
                               ${vfs_flags}
   Screen library:             ${screen_msg}

+ 0 - 11
lib/global.h

@@ -135,17 +135,6 @@
 /* one caused by typing 'exit' or 'logout' in the subshell */
 #define SUBSHELL_EXIT 128
 
-#if 0
-#ifdef MC_ENABLE_DEBUGGING_CODE
-#undef NDEBUG
-#else
-#define NDEBUG
-#endif
-#ifdef HAVE_ASSERT_H
-#include <assert.h>
-#endif
-#endif
-
 #define MC_ERROR g_quark_from_static_string (PACKAGE)
 
 #define DEFAULT_CHARSET "ASCII"

+ 1 - 6
lib/strutil.h

@@ -6,9 +6,6 @@
 #include <sys/types.h>
 #include <inttypes.h>
 #include <string.h>
-#ifdef HAVE_ASSERT_H
-#include <assert.h>             /* assert() */
-#endif
 
 /* Header file for strutil.c, strutilascii.c, strutil8bit.c, strutilutf8.c.
  * There are two sort of functions:
@@ -599,9 +596,7 @@ str_move (char *dest, const char *src)
 {
     size_t n;
 
-#ifdef HAVE_ASSERT_H
-    assert (dest <= src);
-#endif
+    g_assert (dest <= src);
 
     n = strlen (src) + 1;       /* + '\0' */
 

+ 1 - 6
lib/strutil/xstrtol.c

@@ -24,9 +24,6 @@
    need stderr defined if assertion checking is enabled.  */
 #include <stdio.h>
 
-#ifdef HAVE_ASSERT_H
-#include <assert.h>
-#endif
 #include <ctype.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -84,9 +81,7 @@ xstrtoumax (const char *s, char **ptr, int base, uintmax_t * val, const char *va
     uintmax_t tmp;
     strtol_error_t err = LONGINT_OK;
 
-#ifdef HAVE_ASSERT_H
-    assert (0 <= base && base <= 36);
-#endif
+    g_assert (0 <= base && base <= 36);
 
     p = (ptr != NULL ? ptr : &t_ptr);
 

+ 21 - 0
m4.include/mc-assert.m4

@@ -0,0 +1,21 @@
+dnl
+dnl Check whether to enable/disable assertions.
+dnl
+
+AC_DEFUN([mc_ASSERT],
+[
+    AC_ARG_ENABLE([assert],
+    AS_HELP_STRING([--enable-assert], [turn on assertions [yes]]),
+    [
+        if test "x$enableval" = xno; then
+            enable_assert=no
+        else
+            enable_assert=yes
+        fi
+    ],
+    [enable_assert=yes])
+
+    if test "x$enable_assert" = xno; then
+        AC_DEFINE(G_DISABLE_ASSERT, 1, [Define to disable assertions])
+    fi
+])

+ 4 - 11
src/editor/editcmd.c

@@ -35,11 +35,7 @@
 
 #include <config.h>
 
-#ifdef HAVE_ASSERT_H
-#include <assert.h>
-#endif
 #include <ctype.h>
-
 #include <stdio.h>
 #include <stdarg.h>
 #include <sys/types.h>
@@ -384,9 +380,8 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
         vfs_path_t *tmp_vpath;
         gboolean ok;
 
-#ifdef HAVE_ASSERT_H
-        assert (option_backup_ext != NULL);
-#endif
+        g_assert (option_backup_ext != NULL);
+
         /* add backup extension to the path */
         tmp_vpath = vfs_path_clone (real_filename_vpath);
         last_vpath_element = (vfs_path_element_t *) vfs_path_get_by_index (tmp_vpath, -1);
@@ -1629,10 +1624,6 @@ edit_save_mode_cmd (void)
         N_("&Do backups with following extension:")
     };
 
-#ifdef HAVE_ASSERT_H
-    assert (option_backup_ext != NULL);
-#endif
-
 #ifdef ENABLE_NLS
     size_t i;
 
@@ -1640,6 +1631,8 @@ edit_save_mode_cmd (void)
         str[i] = _(str[i]);
 #endif
 
+    g_assert (option_backup_ext != NULL);
+
     {
         quick_widget_t quick_widgets[] = {
             /* *INDENT-OFF* */

+ 2 - 6
src/viewer/coord_cache.c

@@ -146,9 +146,7 @@ mcview_ccache_find (WView * view, const coord_cache_entry_t * coord, cmp_func_t
     size_t base = 0;
     size_t limit = view->coord_cache->size;
 
-#ifdef HAVE_ASSERT_H
-    assert (limit != 0);
-#endif
+    g_assert (limit != 0);
 
     while (limit > 1)
     {
@@ -215,9 +213,7 @@ mcview_ccache_dump (WView * view)
     guint i;
     const coord_cache_t *cache = view->coord_cache;
 
-#ifdef HAVE_ASSERT_H
-    assert (cache != NULL);
-#endif
+    g_assert (cache != NULL);
 
     filesize = mcview_get_filesize (view);
 

+ 12 - 28
src/viewer/datasource.c

@@ -114,9 +114,7 @@ mcview_get_filesize (WView * view)
     case DS_STRING:
         return view->ds_string_len;
     default:
-#ifdef HAVE_ASSERT_H
-        assert (!"Unknown datasource type");
-#endif
+        g_assert (!"Unknown datasource type");
         return 0;
     }
 }
@@ -139,9 +137,7 @@ mcview_update_filesize (WView * view)
 char *
 mcview_get_ptr_file (WView * view, off_t byte_index)
 {
-#ifdef HAVE_ASSERT_H
-    assert (view->datasource == DS_FILE);
-#endif
+    g_assert (view->datasource == DS_FILE);
 
     mcview_file_load_data (view, byte_index);
     if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen))
@@ -225,9 +221,8 @@ mcview_get_utf (WView * view, off_t byte_index, int *ch, int *ch_len)
 char *
 mcview_get_ptr_string (WView * view, off_t byte_index)
 {
-#ifdef HAVE_ASSERT_H
-    assert (view->datasource == DS_STRING);
-#endif
+    g_assert (view->datasource == DS_STRING);
+
     if (byte_index >= 0 && byte_index < (off_t) view->ds_string_len)
         return (char *) (view->ds_string_data + byte_index);
     return NULL;
@@ -260,9 +255,7 @@ mcview_get_byte_none (WView * view, off_t byte_index, int *retval)
     (void) &view;
     (void) byte_index;
 
-#ifdef HAVE_ASSERT_H
-    assert (view->datasource == DS_NONE);
-#endif
+    g_assert (view->datasource == DS_NONE);
 
     if (retval != NULL)
         *retval = -1;
@@ -275,13 +268,10 @@ void
 mcview_set_byte (WView * view, off_t offset, byte b)
 {
     (void) &b;
-#ifndef HAVE_ASSERT_H
-    (void) offset;
-#else
-    assert (offset < mcview_get_filesize (view));
-    assert (view->datasource == DS_FILE);
 
-#endif
+    g_assert (offset < mcview_get_filesize (view));
+    g_assert (view->datasource == DS_FILE);
+
     view->ds_file_datalen = 0;  /* just force reloading */
 }
 
@@ -295,9 +285,7 @@ mcview_file_load_data (WView * view, off_t byte_index)
     ssize_t res;
     size_t bytes_read;
 
-#ifdef HAVE_ASSERT_H
-    assert (view->datasource == DS_FILE);
-#endif
+    g_assert (view->datasource == DS_FILE);
 
     if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen))
         return;
@@ -368,10 +356,7 @@ mcview_close_datasource (WView * view)
         MC_PTR_FREE (view->ds_string_data);
         break;
     default:
-#ifdef HAVE_ASSERT_H
-        assert (!"Unknown datasource type")
-#endif
-            ;
+        g_assert (!"Unknown datasource type");
     }
     view->datasource = DS_NONE;
 }
@@ -426,9 +411,8 @@ mcview_load_command_output (WView * view, const char *command)
 void
 mcview_set_datasource_vfs_pipe (WView * view, int fd)
 {
-#ifdef HAVE_ASSERT_H
-    assert (fd != -1);
-#endif
+    g_assert (fd != -1);
+
     view->datasource = DS_VFS_PIPE;
     view->ds_vfs_pipe = fd;
 

+ 4 - 6
src/viewer/display.c

@@ -326,9 +326,8 @@ mcview_update_bytes_per_line (WView * view)
         bytes = 4;
     else
         bytes = 4 * ((cols - 9) / ((cols <= 80) ? 17 : 18));
-#ifdef HAVE_ASSERT_H
-    assert (bytes != 0);
-#endif
+
+    g_assert (bytes != 0);
 
     view->bytes_per_line = bytes;
     view->dirty = mcview_max_dirt_limit + 1;    /* To force refresh */
@@ -346,9 +345,8 @@ mcview_display_toggle_ruler (WView * view)
         RULER_NONE
     };
 
-#ifdef HAVE_ASSERT_H
-    assert ((size_t) ruler < 3);
-#endif
+    g_assert ((size_t) ruler < 3);
+
     ruler = next[(size_t) ruler];
     mcview_compute_areas (view);
     view->dirty++;

Some files were not shown because too many files changed in this diff