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
--- a/gcc-debug.mk	Fri Feb 08 11:25:04 2013 +0100
+++ b/gcc-debug.mk	Fri Feb 08 17:09:12 2013 +0100
@@ -31,7 +31,7 @@
 AR = ar
 RM = rm
 
-CFLAGS  = -std=gnu99 -g -fstrict-aliasing -Wstrict-aliasing -c
+CFLAGS  = -std=gnu99 -g -fstrict-aliasing -Werror -Wall -pedantic -c
 COFLAGS = -o
 LDFLAGS = 
 LOFLAGS = -o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/osx-debug.mk	Fri Feb 08 17:09:12 2013 +0100
@@ -0,0 +1,44 @@
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2011 Olaf Wintermann. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright
+#      notice, this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+CC = gcc
+LD = gcc
+AR = ar
+RM = rm
+
+CFLAGS  = -std=gnu99 -g -c
+COFLAGS = -o
+LDFLAGS = 
+LOFLAGS = -o
+ARFLAGS = -r
+RMFLAGS = -f
+
+OBJ_EXT = o
+LIB_EXT = a
+APP_EXT =
+
--- a/test/buffer_tests.c	Fri Feb 08 11:25:04 2013 +0100
+++ b/test/buffer_tests.c	Fri Feb 08 17:09:12 2013 +0100
@@ -49,7 +49,6 @@
 
     UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
     b->size = b->capacity;
-    int r;
 
     UCX_TEST_BEGIN
 
@@ -117,7 +116,6 @@
 
     UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
     b->size = b->capacity;
-    int r;
 
     UCX_TEST_BEGIN
 
--- a/ucx/logging.c	Fri Feb 08 11:25:04 2013 +0100
+++ b/ucx/logging.c	Fri Feb 08 17:09:12 2013 +0100
@@ -4,7 +4,7 @@
 #include <stdarg.h>
 #include <time.h>
 
-UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask) {
+UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask) {
     UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger));
     if (logger != NULL) {
         logger->stream = stream;
--- a/ucx/logging.h	Fri Feb 08 11:25:04 2013 +0100
+++ b/ucx/logging.h	Fri Feb 08 17:09:12 2013 +0100
@@ -21,7 +21,7 @@
 #define UCX_LOGGER_SOURCE       0x04
 
 typedef struct {
-    FILE *stream;
+    void *stream;
     write_func writer;
     char *dateformat;
     unsigned int level;
@@ -29,21 +29,21 @@
     UcxMap* levels;
 } UcxLogger;
 
-UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask);
+UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask);
 void ucx_logger_free(UcxLogger* logger);
 
 void ucx_logger_logf(UcxLogger *logger, unsigned int level, const char* file,
         const unsigned int line, const char* format, ...);
-#define ucx_logger_log(logger, level, format...) \
-    ucx_logger_logf(logger, level, __FILE__, __LINE__, format)
-#define ucx_logger_error(logger,format...) \
-    ucx_logger_log(logger, UCX_LOGGER_ERROR, format)
-#define ucx_logger_info(logger,format...) \
-    ucx_logger_log(logger, UCX_LOGGER_INFO, format)
-#define ucx_logger_warn(logger,format...) \
-    ucx_logger_log(logger, UCX_LOGGER_WARN, format)
-#define ucx_logger_trace(logger,format...) \
-    ucx_logger_log(logger, UCX_LOGGER_TRACE, format)
+#define ucx_logger_log(logger, level, ...) \
+    ucx_logger_logf(logger, level, __FILE__, __LINE__, __VA_ARGS__)
+#define ucx_logger_error(logger, ...) \
+    ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)
+#define ucx_logger_info(logger, ...) \
+    ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)
+#define ucx_logger_warn(logger, ...) \
+    ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)
+#define ucx_logger_trace(logger, ...) \
+    ucx_logger_log(logger, UCX_LOGGER_TRACE, __VA_ARGS__)
 
 #ifdef __cplusplus
 }
--- a/ucx/test.c	Fri Feb 08 11:25:04 2013 +0100
+++ b/ucx/test.c	Fri Feb 08 17:09:12 2013 +0100
@@ -18,20 +18,45 @@
 }
 
 void ucx_test_suite_free(UcxTestSuite* suite) {
-    ucx_list_free(suite->tests);
+    UcxTestList *l = suite->tests;
+    while (l != NULL) {
+        UcxTestList *e = l;
+        l = l->next;
+        free(e);
+    }
     free(suite);
 }
 
-void ucx_test_register(UcxTestSuite* suite, UcxTest test) {
-    suite->tests = ucx_list_append(suite->tests, (void*) test);
+int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
+    if (suite->tests) {
+        UcxTestList *list = (UcxTestList*) malloc(sizeof(UcxTestList));
+        if (list) {
+            list->test = test;
+            list->next = suite->tests;
+            suite->tests = list;
+            
+            return EXIT_SUCCESS;
+        } else {
+            return EXIT_FAILURE;
+        }
+    } else {
+        suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList));
+        if (suite->tests) {
+            suite->tests->test = test;
+            suite->tests->next = NULL;
+            
+            return EXIT_SUCCESS;
+        } else {
+            return EXIT_FAILURE;
+        }
+    }
 }
 
 void ucx_test_run(UcxTestSuite* suite, FILE* output) {
     suite->success = 0;
     suite->failure = 0;
-    UCX_FOREACH (UcxList*, suite->tests, e) {
-        UcxTest test = (UcxTest) (e->data);
-        test(suite, output);
+    UCX_FOREACH (UcxTestList*, suite->tests, e) {
+        e->test(suite, output);
     }
     fwrite("\nAll test completed.\n", 1, 21, output);
     fprintf(output, "  Total:   %d\n  Success: %d\n  Failure: %d\n",
--- a/ucx/test.h	Fri Feb 08 11:25:04 2013 +0100
+++ b/ucx/test.h	Fri Feb 08 17:09:12 2013 +0100
@@ -37,7 +37,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <setjmp.h>
-#include "list.h"
 
 #ifdef	__cplusplus
 extern "C" {
@@ -47,18 +46,25 @@
 #define __FUNCTION__ __func__
 #endif
 
-typedef struct {
+typedef struct UcxTestList UcxTestList;
+typedef struct UcxTestSuite UcxTestSuite;
+typedef void(*UcxTest)(UcxTestSuite*,FILE*);
+    
+struct UcxTestList{
+    UcxTest test;
+    UcxTestList *next;
+};
+
+struct UcxTestSuite {
     unsigned int success;
     unsigned int failure;
-    UcxList *tests;
-} UcxTestSuite;
-
-typedef void(*UcxTest)(UcxTestSuite*,FILE*);
+    UcxTestList *tests;
+};
 
 UcxTestSuite* ucx_test_suite_new();
 void ucx_test_suite_free(UcxTestSuite*);
 
-void ucx_test_register(UcxTestSuite*, UcxTest);
+int ucx_test_register(UcxTestSuite*, UcxTest);
 void ucx_test_run(UcxTestSuite*, FILE*);
 
 #define UCX_TEST_DECLARE(name) void name(UcxTestSuite*,FILE *)

mercurial