added gnu++11 support

Wed, 27 Feb 2013 13:30:21 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 27 Feb 2013 13:30:21 +0100
changeset 95
ecfdc1c4a552
parent 94
57ea041df22f
child 96
fbbff331beba

added gnu++11 support

g++-debug.mk file | annotate | diff | comparison | revisions
g++.mk file | annotate | diff | comparison | revisions
test/buffer_tests.c file | annotate | diff | comparison | revisions
test/logging_tests.c file | annotate | diff | comparison | revisions
test/map_tests.c file | annotate | diff | comparison | revisions
ucx/buffer.c file | annotate | diff | comparison | revisions
ucx/logging.c file | annotate | diff | comparison | revisions
ucx/map.c file | annotate | diff | comparison | revisions
ucx/map.h file | annotate | diff | comparison | revisions
ucx/mempool.c file | annotate | diff | comparison | revisions
ucx/string.c file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/g++-debug.mk	Wed Feb 27 13:30:21 2013 +0100
@@ -0,0 +1,43 @@
+#
+# 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 = g++
+LD = g++
+AR = ar
+RM = rm
+
+CFLAGS  = -std=gnu++11 -g -O2 -fstrict-aliasing -Werror -Wall -pedantic -c
+COFLAGS = -o
+LDFLAGS = 
+LOFLAGS = -o
+ARFLAGS = -r
+RMFLAGS = -f
+
+OBJ_EXT = o
+LIB_EXT = a
+APP_EXT =
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/g++.mk	Wed Feb 27 13:30:21 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 = g++
+LD = g++
+AR = ar
+RM = rm
+
+CFLAGS  = -std=gnu++11 -O2 -fstrict-aliasing -c
+COFLAGS = -o
+LDFLAGS = 
+LOFLAGS = -o
+ARFLAGS = -r
+RMFLAGS = -f
+
+OBJ_EXT = o
+LIB_EXT = a
+APP_EXT =
+
--- a/test/buffer_tests.c	Wed Feb 27 11:48:29 2013 +0100
+++ b/test/buffer_tests.c	Wed Feb 27 13:30:21 2013 +0100
@@ -120,7 +120,7 @@
     UCX_TEST_BEGIN
 
     char rb[16];
-    for (int i = 0 ; i < 16 ; i++) {
+    for (size_t i = 0 ; i < 16 ; i++) {
         UCX_TEST_ASSERT(b->pos == i, "pos wrong during read loop");
         UCX_TEST_ASSERT(!ucx_buffer_eof(b),
                 "EOF shall not be set during read loop");
--- a/test/logging_tests.c	Wed Feb 27 11:48:29 2013 +0100
+++ b/test/logging_tests.c	Wed Feb 27 13:30:21 2013 +0100
@@ -16,7 +16,7 @@
     ucx_logger_trace(logger, "dont log this!");
     ucx_logger_error(logger, "error %d!", 42);
     fseek(stream, 0, SEEK_SET);
-    int r = fread(buffer, 1, 100, stream);
+    size_t r = fread(buffer, 1, 100, stream);
     
     size_t expected_length = 76;
     UCX_TEST_ASSERT(r == expected_length && strncmp(buffer,
--- a/test/map_tests.c	Wed Feb 27 11:48:29 2013 +0100
+++ b/test/map_tests.c	Wed Feb 27 13:30:21 2013 +0100
@@ -184,7 +184,7 @@
     const char *string = (const char*) value;
     size_t n = strlen(string);
     char *encoded = (char*) malloc(n+1);
-    for (int i = 0 ; i < n ; i++) {
+    for (size_t i = 0 ; i < n ; i++) {
         encoded[i] = string[n-1-i];
     }
     encoded[n] = 0;
--- a/ucx/buffer.c	Wed Feb 27 11:48:29 2013 +0100
+++ b/ucx/buffer.c	Wed Feb 27 13:30:21 2013 +0100
@@ -63,7 +63,7 @@
 }
 
 int ucx_buffer_seek(UcxBuffer *buffer, off_t offset, int whence) {
-    off_t npos = 0;
+    size_t npos = 0;
     switch (whence) {
     case SEEK_SET:
         npos = 0;
@@ -78,7 +78,7 @@
 
     npos += offset;
     
-    if (npos < 0 || npos > buffer->size) {
+    if (npos > buffer->size) {
         return -1;
     } else {
         buffer->pos = npos;
--- a/ucx/logging.c	Wed Feb 27 11:48:29 2013 +0100
+++ b/ucx/logging.c	Wed Feb 27 13:30:21 2013 +0100
@@ -9,20 +9,20 @@
     if (logger != NULL) {
         logger->stream = stream;
         logger->writer = (write_func)fwrite;
-        logger->dateformat = "%F %T %z ";
+        logger->dateformat = (char*) "%F %T %z ";
         logger->level = level;
         logger->mask = mask;
         logger->levels = ucx_map_new(8);
         
         unsigned int l;
         l = UCX_LOGGER_ERROR;
-        ucx_map_int_put(logger->levels, l, "[ERROR]");
+        ucx_map_int_put(logger->levels, l, (void*) "[ERROR]");
         l = UCX_LOGGER_WARN;
-        ucx_map_int_put(logger->levels, l, "[WARNING]");
+        ucx_map_int_put(logger->levels, l, (void*) "[WARNING]");
         l = UCX_LOGGER_INFO;
-        ucx_map_int_put(logger->levels, l, "[INFO]");
+        ucx_map_int_put(logger->levels, l, (void*) "[INFO]");
         l = UCX_LOGGER_TRACE;
-        ucx_map_int_put(logger->levels, l, "[TRACE]");
+        ucx_map_int_put(logger->levels, l, (void*) "[TRACE]");
     }
 
     return logger;
@@ -70,6 +70,5 @@
         msg[k++] = '\n';
         
         logger->writer(msg, 1, k, logger->stream);
-        fflush(logger->stream);
     }
 }
--- a/ucx/map.c	Wed Feb 27 11:48:29 2013 +0100
+++ b/ucx/map.c	Wed Feb 27 13:30:21 2013 +0100
@@ -360,7 +360,7 @@
     UcxMapIterator iter = ucx_map_iterator(map);
     char *k, *v;
     sstr_t key, value;
-    int written;
+    size_t written;
 
     UCX_MAP_FOREACH(v, iter) {
         k = (char*) iter.cur->key.data;
--- a/ucx/map.h	Wed Feb 27 11:48:29 2013 +0100
+++ b/ucx/map.h	Wed Feb 27 13:30:21 2013 +0100
@@ -51,7 +51,7 @@
 struct UcxMapIterator {
     UcxMap        *map;
     UcxMapElement *cur;
-    int           index;
+    size_t        index;
 };
 
 
--- a/ucx/mempool.c	Wed Feb 27 11:48:29 2013 +0100
+++ b/ucx/mempool.c	Wed Feb 27 13:30:21 2013 +0100
@@ -5,6 +5,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#ifdef __cplusplus
+#define __STDC_FORMAT_MACROS
+#endif
 #include <inttypes.h>
 
 #include "mempool.h"
@@ -79,13 +82,13 @@
     char *newm = (char*) realloc(mem, n + sizeof(ucx_destructor));
     if (newm == NULL) return NULL;
     if (mem != newm) {
-        for(int i=0;i<pool->ndata;i++) {
+        for(size_t i=0 ; i < pool->ndata ; i++) {
             if(pool->data[i] == mem) {
                 pool->data[i] = newm;
                 return newm + sizeof(ucx_destructor);
             }
         }
-        fprintf(stderr, "FATAL: 0x%08"PRIxPTR" not in mpool 0x%08"PRIxPTR"\n",
+        fprintf(stderr, "FATAL: 0x%08" PRIxPTR" not in mpool 0x%08" PRIxPTR"\n",
           (intptr_t)ptr, (intptr_t)pool);
         exit(1);
     } else {
@@ -95,7 +98,7 @@
 
 void ucx_mempool_free(UcxMempool *pool) {
     ucx_memchunk *chunk;
-    for(int i=0;i<pool->ndata;i++) {
+    for(size_t i=0 ; i<pool->ndata ; i++) {
         chunk = (ucx_memchunk*) pool->data[i];
         if(chunk->destructor != NULL) {
             chunk->destructor(&chunk->c);
--- a/ucx/string.c	Wed Feb 27 11:48:29 2013 +0100
+++ b/ucx/string.c	Wed Feb 27 13:30:21 2013 +0100
@@ -30,7 +30,7 @@
     size_t size = s.length;
     va_start(ap, s);
 
-    for (int i=0;i<n-1;i++) {
+    for (size_t i = 0 ; i < n-1 ; i++) {
         sstr_t str = va_arg(ap, sstr_t);
         size += str.length;
     }
@@ -66,7 +66,7 @@
     memcpy(ptr, c1.ptr, cplen);
     len -= cplen;
     ptr += cplen;
-    for (int i=0;i<n-1;i++) {
+    for (size_t i = 0 ; i < n-1 ; i++) {
         sstr_t str = va_arg (ap, sstr_t);
         cplen = str.length > len ? len : str.length;
         if(cplen <= 0) {
@@ -115,10 +115,10 @@
     }
     sstr_t sv = sstrdup(s);
 
-    for (int i = 0 ; i < s.length ; i++) {
+    for (size_t i = 0 ; i < s.length ; i++) {
         if (sv.ptr[i] == d.ptr[0]) {
             _Bool match = 1;
-            for (int j = 1 ; j < d.length ; j++) {
+            for (size_t j = 1 ; j < d.length ; j++) {
                 if (j+i < s.length) {
                     match &= (sv.ptr[i+j] == d.ptr[j]);
                 } else {
@@ -128,7 +128,7 @@
             }
             if (match) {
                 (*n)++;
-                for (int j = 0 ; j < d.length ; j++) {
+                for (size_t j = 0 ; j < d.length ; j++) {
                     sv.ptr[i+j] = 0;
                 }
                 i += d.length;
@@ -139,7 +139,7 @@
     result = (sstr_t*) malloc(sizeof(sstr_t) * (*n));
 
     char *pptr = sv.ptr;
-    for (int i = 0 ; i < *n ; i++) {
+    for (size_t i = 0 ; i < *n ; i++) {
         size_t l = strlen(pptr);
         char* ptr = (char*) malloc(l + 1);
         memcpy(ptr, pptr, l);

mercurial