Use g_assert() instead of assert(3).

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-11-03 10:46:11 +03:00
parent f64e8b99d4
commit 9a39e35dc3
15 changed files with 66 additions and 118 deletions

View File

@ -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])

View File

@ -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}

View File

@ -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"

View File

@ -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' */

View File

@ -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
m4.include/mc-assert.m4 Normal file
View File

@ -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
])

View File

@ -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* */

View File

@ -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);

View File

@ -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;

View File

@ -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++;

View File

@ -94,9 +94,7 @@ mcview_growbuf_done (WView * view)
void
mcview_growbuf_free (WView * view)
{
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use);
#endif
g_assert (view->growbuf_in_use);
g_ptr_array_foreach (view->growbuf_blockptr, (GFunc) g_free, NULL);
@ -111,9 +109,7 @@ mcview_growbuf_free (WView * view)
off_t
mcview_growbuf_filesize (WView * view)
{
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use);
#endif
g_assert (view->growbuf_in_use);
if (view->growbuf_blockptr->len == 0)
return 0;
@ -132,9 +128,7 @@ mcview_growbuf_read_until (WView * view, off_t ofs)
{
gboolean short_read = FALSE;
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use);
#endif
g_assert (view->growbuf_in_use);
if (view->growbuf_finished)
return;
@ -226,9 +220,7 @@ mcview_growbuf_read_until (WView * view, off_t ofs)
}
else
{
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_VFS_PIPE);
#endif
g_assert (view->datasource == DS_VFS_PIPE);
do
{
nread = mc_read (view->ds_vfs_pipe, p, bytesfree);
@ -253,9 +245,7 @@ mcview_get_byte_growing_buffer (WView * view, off_t byte_index, int *retval)
{
char *p;
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use);
#endif
g_assert (view->growbuf_in_use);
if (retval != NULL)
*retval = -1;
@ -280,9 +270,7 @@ mcview_get_ptr_growing_buffer (WView * view, off_t byte_index)
{
off_t pageno, pageindex;
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use);
#endif
g_assert (view->growbuf_in_use);
if (byte_index < 0)
return NULL;

View File

@ -389,9 +389,7 @@ mcview_hexedit_save_changes (WView * view)
char *text;
struct hexedit_change_node *curr, *next;
#ifdef HAVE_ASSERT_H
assert (view->filename_vpath != NULL);
#endif
g_assert (view->filename_vpath != NULL);
fp = mc_open (view->filename_vpath, O_WRONLY);
if (fp != -1)

View File

@ -1,10 +1,6 @@
#ifndef MC__VIEWER_INLINES_H
#define MC__VIEWER_INLINES_H
#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
/*** typedefs(not structures) and defined constants **********************************************/
/*** enums ***************************************************************************************/
@ -29,9 +25,7 @@ mcview_offset_doz (off_t a, off_t b)
static inline off_t
mcview_offset_rounddown (off_t a, off_t b)
{
#ifdef HAVE_ASSERT_H
assert (b != 0);
#endif
g_assert (b != 0);
return a - a % b;
}
@ -77,9 +71,7 @@ mcview_already_loaded (off_t offset, off_t idx, size_t size)
static inline gboolean
mcview_get_byte_file (WView * view, off_t byte_index, int *retval)
{
#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))
@ -110,9 +102,7 @@ mcview_get_byte (WView * view, off_t offset, int *retval)
case DS_NONE:
return mcview_get_byte_none (view, offset, retval);
default:
#ifdef HAVE_ASSERT_H
assert (!"Unknown datasource type");
#endif
g_assert (!"Unknown datasource type");
return FALSE;
}
}

View File

@ -271,9 +271,7 @@ mcview_load (WView * view, const char *command, const char *file, int start_line
gboolean retval = FALSE;
vfs_path_t *vpath = NULL;
#ifdef HAVE_ASSERT_H
assert (view->bytes_per_line != 0);
#endif
g_assert (view->bytes_per_line != 0);
view->filename_vpath = vfs_path_from_str (file);

View File

@ -173,9 +173,9 @@ mcview_move_left (WView * view, off_t columns)
if (view->hex_mode)
{
off_t old_cursor = view->hex_cursor;
#ifdef HAVE_ASSERT_H
assert (columns == 1);
#endif
g_assert (columns == 1);
if (view->hexview_in_text || !view->hexedit_lownibble)
{
if (view->hex_cursor > 0)
@ -201,9 +201,9 @@ mcview_move_right (WView * view, off_t columns)
off_t old_cursor = view->hex_cursor;
last_byte = mcview_offset_doz (mcview_get_filesize (view), 1);
#ifdef HAVE_ASSERT_H
assert (columns == 1);
#endif
g_assert (columns == 1);
if (view->hexview_in_text || view->hexedit_lownibble)
{
if (view->hex_cursor < last_byte)