modified code to compile with -pedantic

Fri, 08 Feb 2013 17:09:12 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 08 Feb 2013 17:09:12 +0100
changeset 83
3b552d7a9610
parent 82
6068d965328b
child 84
7465c18765dc

modified code to compile with -pedantic

gcc-debug.mk file | annotate | diff | comparison | revisions
osx-debug.mk file | annotate | diff | comparison | revisions
test/buffer_tests.c file | annotate | diff | comparison | revisions
ucx/logging.c file | annotate | diff | comparison | revisions
ucx/logging.h file | annotate | diff | comparison | revisions
ucx/test.c file | annotate | diff | comparison | revisions
ucx/test.h file | annotate | diff | comparison | revisions
     1.1 --- a/gcc-debug.mk	Fri Feb 08 11:25:04 2013 +0100
     1.2 +++ b/gcc-debug.mk	Fri Feb 08 17:09:12 2013 +0100
     1.3 @@ -31,7 +31,7 @@
     1.4  AR = ar
     1.5  RM = rm
     1.6  
     1.7 -CFLAGS  = -std=gnu99 -g -fstrict-aliasing -Wstrict-aliasing -c
     1.8 +CFLAGS  = -std=gnu99 -g -fstrict-aliasing -Werror -Wall -pedantic -c
     1.9  COFLAGS = -o
    1.10  LDFLAGS = 
    1.11  LOFLAGS = -o
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/osx-debug.mk	Fri Feb 08 17:09:12 2013 +0100
     2.3 @@ -0,0 +1,44 @@
     2.4 +#
     2.5 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 +#
     2.7 +# Copyright 2011 Olaf Wintermann. All rights reserved.
     2.8 +#
     2.9 +# Redistribution and use in source and binary forms, with or without
    2.10 +# modification, are permitted provided that the following conditions are met:
    2.11 +#
    2.12 +#   1. Redistributions of source code must retain the above copyright
    2.13 +#      notice, this list of conditions and the following disclaimer.
    2.14 +#
    2.15 +#   2. Redistributions in binary form must reproduce the above copyright
    2.16 +#      notice, this list of conditions and the following disclaimer in the
    2.17 +#      documentation and/or other materials provided with the distribution.
    2.18 +#
    2.19 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    2.20 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2.21 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    2.22 +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    2.23 +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    2.24 +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    2.25 +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    2.26 +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    2.27 +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    2.28 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    2.29 +# POSSIBILITY OF SUCH DAMAGE.
    2.30 +#
    2.31 +
    2.32 +CC = gcc
    2.33 +LD = gcc
    2.34 +AR = ar
    2.35 +RM = rm
    2.36 +
    2.37 +CFLAGS  = -std=gnu99 -g -c
    2.38 +COFLAGS = -o
    2.39 +LDFLAGS = 
    2.40 +LOFLAGS = -o
    2.41 +ARFLAGS = -r
    2.42 +RMFLAGS = -f
    2.43 +
    2.44 +OBJ_EXT = o
    2.45 +LIB_EXT = a
    2.46 +APP_EXT =
    2.47 +
     3.1 --- a/test/buffer_tests.c	Fri Feb 08 11:25:04 2013 +0100
     3.2 +++ b/test/buffer_tests.c	Fri Feb 08 17:09:12 2013 +0100
     3.3 @@ -49,7 +49,6 @@
     3.4  
     3.5      UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
     3.6      b->size = b->capacity;
     3.7 -    int r;
     3.8  
     3.9      UCX_TEST_BEGIN
    3.10  
    3.11 @@ -117,7 +116,6 @@
    3.12  
    3.13      UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
    3.14      b->size = b->capacity;
    3.15 -    int r;
    3.16  
    3.17      UCX_TEST_BEGIN
    3.18  
     4.1 --- a/ucx/logging.c	Fri Feb 08 11:25:04 2013 +0100
     4.2 +++ b/ucx/logging.c	Fri Feb 08 17:09:12 2013 +0100
     4.3 @@ -4,7 +4,7 @@
     4.4  #include <stdarg.h>
     4.5  #include <time.h>
     4.6  
     4.7 -UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask) {
     4.8 +UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask) {
     4.9      UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger));
    4.10      if (logger != NULL) {
    4.11          logger->stream = stream;
     5.1 --- a/ucx/logging.h	Fri Feb 08 11:25:04 2013 +0100
     5.2 +++ b/ucx/logging.h	Fri Feb 08 17:09:12 2013 +0100
     5.3 @@ -21,7 +21,7 @@
     5.4  #define UCX_LOGGER_SOURCE       0x04
     5.5  
     5.6  typedef struct {
     5.7 -    FILE *stream;
     5.8 +    void *stream;
     5.9      write_func writer;
    5.10      char *dateformat;
    5.11      unsigned int level;
    5.12 @@ -29,21 +29,21 @@
    5.13      UcxMap* levels;
    5.14  } UcxLogger;
    5.15  
    5.16 -UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask);
    5.17 +UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask);
    5.18  void ucx_logger_free(UcxLogger* logger);
    5.19  
    5.20  void ucx_logger_logf(UcxLogger *logger, unsigned int level, const char* file,
    5.21          const unsigned int line, const char* format, ...);
    5.22 -#define ucx_logger_log(logger, level, format...) \
    5.23 -    ucx_logger_logf(logger, level, __FILE__, __LINE__, format)
    5.24 -#define ucx_logger_error(logger,format...) \
    5.25 -    ucx_logger_log(logger, UCX_LOGGER_ERROR, format)
    5.26 -#define ucx_logger_info(logger,format...) \
    5.27 -    ucx_logger_log(logger, UCX_LOGGER_INFO, format)
    5.28 -#define ucx_logger_warn(logger,format...) \
    5.29 -    ucx_logger_log(logger, UCX_LOGGER_WARN, format)
    5.30 -#define ucx_logger_trace(logger,format...) \
    5.31 -    ucx_logger_log(logger, UCX_LOGGER_TRACE, format)
    5.32 +#define ucx_logger_log(logger, level, ...) \
    5.33 +    ucx_logger_logf(logger, level, __FILE__, __LINE__, __VA_ARGS__)
    5.34 +#define ucx_logger_error(logger, ...) \
    5.35 +    ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)
    5.36 +#define ucx_logger_info(logger, ...) \
    5.37 +    ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)
    5.38 +#define ucx_logger_warn(logger, ...) \
    5.39 +    ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)
    5.40 +#define ucx_logger_trace(logger, ...) \
    5.41 +    ucx_logger_log(logger, UCX_LOGGER_TRACE, __VA_ARGS__)
    5.42  
    5.43  #ifdef __cplusplus
    5.44  }
     6.1 --- a/ucx/test.c	Fri Feb 08 11:25:04 2013 +0100
     6.2 +++ b/ucx/test.c	Fri Feb 08 17:09:12 2013 +0100
     6.3 @@ -18,20 +18,45 @@
     6.4  }
     6.5  
     6.6  void ucx_test_suite_free(UcxTestSuite* suite) {
     6.7 -    ucx_list_free(suite->tests);
     6.8 +    UcxTestList *l = suite->tests;
     6.9 +    while (l != NULL) {
    6.10 +        UcxTestList *e = l;
    6.11 +        l = l->next;
    6.12 +        free(e);
    6.13 +    }
    6.14      free(suite);
    6.15  }
    6.16  
    6.17 -void ucx_test_register(UcxTestSuite* suite, UcxTest test) {
    6.18 -    suite->tests = ucx_list_append(suite->tests, (void*) test);
    6.19 +int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
    6.20 +    if (suite->tests) {
    6.21 +        UcxTestList *list = (UcxTestList*) malloc(sizeof(UcxTestList));
    6.22 +        if (list) {
    6.23 +            list->test = test;
    6.24 +            list->next = suite->tests;
    6.25 +            suite->tests = list;
    6.26 +            
    6.27 +            return EXIT_SUCCESS;
    6.28 +        } else {
    6.29 +            return EXIT_FAILURE;
    6.30 +        }
    6.31 +    } else {
    6.32 +        suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList));
    6.33 +        if (suite->tests) {
    6.34 +            suite->tests->test = test;
    6.35 +            suite->tests->next = NULL;
    6.36 +            
    6.37 +            return EXIT_SUCCESS;
    6.38 +        } else {
    6.39 +            return EXIT_FAILURE;
    6.40 +        }
    6.41 +    }
    6.42  }
    6.43  
    6.44  void ucx_test_run(UcxTestSuite* suite, FILE* output) {
    6.45      suite->success = 0;
    6.46      suite->failure = 0;
    6.47 -    UCX_FOREACH (UcxList*, suite->tests, e) {
    6.48 -        UcxTest test = (UcxTest) (e->data);
    6.49 -        test(suite, output);
    6.50 +    UCX_FOREACH (UcxTestList*, suite->tests, e) {
    6.51 +        e->test(suite, output);
    6.52      }
    6.53      fwrite("\nAll test completed.\n", 1, 21, output);
    6.54      fprintf(output, "  Total:   %d\n  Success: %d\n  Failure: %d\n",
     7.1 --- a/ucx/test.h	Fri Feb 08 11:25:04 2013 +0100
     7.2 +++ b/ucx/test.h	Fri Feb 08 17:09:12 2013 +0100
     7.3 @@ -37,7 +37,6 @@
     7.4  #include <stdio.h>
     7.5  #include <string.h>
     7.6  #include <setjmp.h>
     7.7 -#include "list.h"
     7.8  
     7.9  #ifdef	__cplusplus
    7.10  extern "C" {
    7.11 @@ -47,18 +46,25 @@
    7.12  #define __FUNCTION__ __func__
    7.13  #endif
    7.14  
    7.15 -typedef struct {
    7.16 +typedef struct UcxTestList UcxTestList;
    7.17 +typedef struct UcxTestSuite UcxTestSuite;
    7.18 +typedef void(*UcxTest)(UcxTestSuite*,FILE*);
    7.19 +    
    7.20 +struct UcxTestList{
    7.21 +    UcxTest test;
    7.22 +    UcxTestList *next;
    7.23 +};
    7.24 +
    7.25 +struct UcxTestSuite {
    7.26      unsigned int success;
    7.27      unsigned int failure;
    7.28 -    UcxList *tests;
    7.29 -} UcxTestSuite;
    7.30 -
    7.31 -typedef void(*UcxTest)(UcxTestSuite*,FILE*);
    7.32 +    UcxTestList *tests;
    7.33 +};
    7.34  
    7.35  UcxTestSuite* ucx_test_suite_new();
    7.36  void ucx_test_suite_free(UcxTestSuite*);
    7.37  
    7.38 -void ucx_test_register(UcxTestSuite*, UcxTest);
    7.39 +int ucx_test_register(UcxTestSuite*, UcxTest);
    7.40  void ucx_test_run(UcxTestSuite*, FILE*);
    7.41  
    7.42  #define UCX_TEST_DECLARE(name) void name(UcxTestSuite*,FILE *)

mercurial