made the code work with g++ without errors (but warnings)

Fri, 12 Oct 2012 12:08:34 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 12 Oct 2012 12:08:34 +0200
changeset 71
303dabadff1c
parent 69
fb59270b1de3
child 72
bb3eae81aae8

made the code work with g++ without errors (but warnings)

test/buffer_tests.c file | annotate | diff | comparison | revisions
test/dlist_tests.c file | annotate | diff | comparison | revisions
test/list_tests.c file | annotate | diff | comparison | revisions
test/map_tests.c file | annotate | diff | comparison | revisions
test/string_tests.c file | annotate | diff | comparison | revisions
ucx/map.h file | annotate | diff | comparison | revisions
ucx/string.c file | annotate | diff | comparison | revisions
--- a/test/buffer_tests.c	Fri Oct 12 10:54:55 2012 +0200
+++ b/test/buffer_tests.c	Fri Oct 12 12:08:34 2012 +0200
@@ -123,7 +123,7 @@
     UCX_TEST_ASSERT(ucx_buffer_eof(b), "eof shall be set");
 
     ucx_buffer_seek(b, 8, SEEK_SET);
-    r = ucx_buffer_write("not", 1, 3, b);
+    r = ucx_buffer_write((void*)"not", 1, 3, b);
     UCX_TEST_ASSERT(r == 3, "three bytes should be replace");
     UCX_TEST_ASSERT(memcmp(buffer, "this is not too much", 16) == 0,
             "modified buffer is incorrect");
--- a/test/dlist_tests.c	Fri Oct 12 10:54:55 2012 +0200
+++ b/test/dlist_tests.c	Fri Oct 12 12:08:34 2012 +0200
@@ -5,13 +5,13 @@
 #include "dlist_tests.h"
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_append) {
-    UcxDlist *list = ucx_dlist_append(NULL, "Hello");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
     UCX_TEST_BEGIN
     
     UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
             "failed");
     
-    list = ucx_dlist_append(list, " World!");
+    list = ucx_dlist_append(list, (void*)" World!");
     
     UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
             "failed");
@@ -22,10 +22,10 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_prepend) {
-    UcxDlist *list = ucx_dlist_prepend(NULL, " World!");
+    UcxDlist *list = ucx_dlist_prepend(NULL, (void*)" World!");
     UCX_TEST_BEGIN
 
-    list = ucx_dlist_prepend(list, "Hello");
+    list = ucx_dlist_prepend(list, (void*)"Hello");
     
     UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
             "failed");
@@ -38,12 +38,12 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_equals) {
-    UcxDlist *list = ucx_dlist_append(NULL, "Hello");
-    list = ucx_dlist_append(list, " World!");
-    UcxDlist *list2 = ucx_dlist_prepend(NULL, " World!");
-    list2 = ucx_dlist_prepend(list2, "Hello");
-    UcxDlist *list3 = ucx_dlist_prepend(NULL, " Welt!");
-    list3 = ucx_dlist_prepend(list3, "Hallo");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
+    list = ucx_dlist_append(list, (void*)" World!");
+    UcxDlist *list2 = ucx_dlist_prepend(NULL, (void*)" World!");
+    list2 = ucx_dlist_prepend(list2, (void*)"Hello");
+    UcxDlist *list3 = ucx_dlist_prepend(NULL, (void*)" Welt!");
+    list3 = ucx_dlist_prepend(list3, (void*)"Hallo");
     UCX_TEST_BEGIN
     
     UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, cmp_string, NULL), "failed");
@@ -56,8 +56,8 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_concat) {
-    UcxDlist *list = ucx_dlist_append(NULL, "Hello");
-    UcxDlist *list2 = ucx_dlist_prepend(NULL, " World!");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
+    UcxDlist *list2 = ucx_dlist_prepend(NULL, (void*)" World!");
     UCX_TEST_BEGIN
     
     list = ucx_dlist_concat(list, list2);
@@ -73,12 +73,12 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_size) {
-    UcxDlist *list = ucx_dlist_append(NULL, "This ");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"This ");
     UCX_TEST_BEGIN
-    list = ucx_dlist_append(list, "list ");
-    list = ucx_dlist_append(list, "has ");
-    list = ucx_dlist_append(list, "size ");
-    list = ucx_dlist_append(list, "5!");
+    list = ucx_dlist_append(list, (void*)"list ");
+    list = ucx_dlist_append(list, (void*)"has ");
+    list = ucx_dlist_append(list, (void*)"size ");
+    list = ucx_dlist_append(list, (void*)"5!");
     
     UCX_TEST_ASSERT(ucx_dlist_size(list) == 5, "failed");
     
@@ -87,10 +87,10 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_first) {
-    UcxDlist *list = ucx_dlist_append(NULL, "Find ");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find ");
     UCX_TEST_BEGIN
-    list = ucx_dlist_append(list, "the ");
-    list = ucx_dlist_append(list, "first!");
+    list = ucx_dlist_append(list, (void*)"the ");
+    list = ucx_dlist_append(list, (void*)"first!");
     
     const char* first = (const char*) (ucx_dlist_first(list)->data);
     
@@ -101,10 +101,10 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_last) {
-    UcxDlist *list = ucx_dlist_append(NULL, "Find ");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find ");
     UCX_TEST_BEGIN
-    list = ucx_dlist_append(list, "the ");
-    list = ucx_dlist_append(list, "last!");
+    list = ucx_dlist_append(list, (void*)"the ");
+    list = ucx_dlist_append(list, (void*)"last!");
     
     const char* last = (const char*) (ucx_dlist_last(list)->data);
     
@@ -115,10 +115,10 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_get) {
-    UcxDlist *list = ucx_dlist_append(NULL, "Find ");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find ");
     UCX_TEST_BEGIN
-    list = ucx_dlist_append(list, "the ");
-    list = ucx_dlist_append(list, "mid!");
+    list = ucx_dlist_append(list, (void*)"the ");
+    list = ucx_dlist_append(list, (void*)"mid!");
     
     const char* mid = (const char*) (ucx_dlist_get(list, 1)->data);
     
@@ -129,10 +129,10 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_remove) {
-    UcxDlist *list = ucx_dlist_append(NULL, "Hello");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
     UCX_TEST_BEGIN
-    list = ucx_dlist_append(list, " fucking");
-    list = ucx_dlist_append(list, " World!");
+    list = ucx_dlist_append(list, (void*)" fucking");
+    list = ucx_dlist_append(list, (void*)" World!");
     
     list = ucx_dlist_remove(list, ucx_dlist_get(list, 1));
     
@@ -175,21 +175,21 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_dlist_sort) {
-    UcxDlist *list = ucx_dlist_append(NULL, "this");
-    list = ucx_dlist_append(list, "is");
-    list = ucx_dlist_append(list, "a");
-    list = ucx_dlist_append(list, "test");
-    list = ucx_dlist_append(list, "for");
-    list = ucx_dlist_append(list, "partial");
-    list = ucx_dlist_append(list, "correctness");
+    UcxDlist *list = ucx_dlist_append(NULL, (void*)"this");
+    list = ucx_dlist_append(list, (void*)"is");
+    list = ucx_dlist_append(list, (void*)"a");
+    list = ucx_dlist_append(list, (void*)"test");
+    list = ucx_dlist_append(list, (void*)"for");
+    list = ucx_dlist_append(list, (void*)"partial");
+    list = ucx_dlist_append(list, (void*)"correctness");
 
-    UcxDlist *expected = ucx_dlist_append(NULL, "a");
-    expected = ucx_dlist_append(expected, "correctness");
-    expected = ucx_dlist_append(expected, "for");
-    expected = ucx_dlist_append(expected, "is");
-    expected = ucx_dlist_append(expected, "partial");
-    expected = ucx_dlist_append(expected, "test");
-    expected = ucx_dlist_append(expected, "this");
+    UcxDlist *expected = ucx_dlist_append(NULL, (void*)"a");
+    expected = ucx_dlist_append(expected, (void*)"correctness");
+    expected = ucx_dlist_append(expected, (void*)"for");
+    expected = ucx_dlist_append(expected, (void*)"is");
+    expected = ucx_dlist_append(expected, (void*)"partial");
+    expected = ucx_dlist_append(expected, (void*)"test");
+    expected = ucx_dlist_append(expected, (void*)"this");
 
     list = ucx_dlist_sort(list, cmp_string, NULL);
 
--- a/test/list_tests.c	Fri Oct 12 10:54:55 2012 +0200
+++ b/test/list_tests.c	Fri Oct 12 12:08:34 2012 +0200
@@ -5,12 +5,12 @@
 #include "list_tests.h"
 
 UCX_TEST_IMPLEMENT(test_ucx_list_append) {
-    UcxList *list = ucx_list_append(NULL, "Hello");
+    UcxList *list = ucx_list_append(NULL, (void*)"Hello");
     UCX_TEST_BEGIN
     UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
             "failed");
     
-    list = ucx_list_append(list, " World!");
+    list = ucx_list_append(list, (void*)" World!");
     
     UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
             "failed");
@@ -21,9 +21,9 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_list_prepend) {
-    UcxList *list = ucx_list_prepend(NULL, " World!");
+    UcxList *list = ucx_list_prepend(NULL, (void*)" World!");
     UCX_TEST_BEGIN
-    list = ucx_list_prepend(list, "Hello");
+    list = ucx_list_prepend(list, (void*)"Hello");
     
     UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
             "failed");
@@ -36,12 +36,12 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_list_equals) {
-    UcxList *list = ucx_list_append(NULL, "Hello");
-    list = ucx_list_append(list, " World!");
-    UcxList *list2 = ucx_list_prepend(NULL, " World!");
-    list2 = ucx_list_prepend(list2, "Hello");
-    UcxList *list3 = ucx_list_prepend(NULL, " Welt!");
-    list3 = ucx_list_prepend(list3, "Hallo");
+    UcxList *list = ucx_list_append(NULL, (void*)"Hello");
+    list = ucx_list_append(list, (void*)" World!");
+    UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!");
+    list2 = ucx_list_prepend(list2, (void*)"Hello");
+    UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!");
+    list3 = ucx_list_prepend(list3, (void*)"Hallo");
     
     UCX_TEST_BEGIN
     UCX_TEST_ASSERT(ucx_list_equals(list, list2, cmp_string, NULL), "failed");
@@ -54,8 +54,8 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_list_concat) {
-    UcxList *list = ucx_list_append(NULL, "Hello");
-    UcxList *list2 = ucx_list_prepend(NULL, " World!");
+    UcxList *list = ucx_list_append(NULL, (void*)"Hello");
+    UcxList *list2 = ucx_list_prepend(NULL, (void*)" World!");
     
     list = ucx_list_concat(list, list2);
     UCX_TEST_BEGIN
@@ -74,12 +74,12 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_list_size) {
-    UcxList *list = ucx_list_append(NULL, "This ");
+    UcxList *list = ucx_list_append(NULL, (void*)"This ");
     UCX_TEST_BEGIN
-    list = ucx_list_append(list, "list ");
-    list = ucx_list_append(list, "has ");
-    list = ucx_list_append(list, "size ");
-    list = ucx_list_append(list, "5!");
+    list = ucx_list_append(list, (void*)"list ");
+    list = ucx_list_append(list, (void*)"has ");
+    list = ucx_list_append(list, (void*)"size ");
+    list = ucx_list_append(list, (void*)"5!");
     
     UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed");
     
@@ -88,10 +88,10 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_list_last) {
-    UcxList *list = ucx_list_append(NULL, "Find ");
+    UcxList *list = ucx_list_append(NULL, (void*)"Find ");
     UCX_TEST_BEGIN
-    list = ucx_list_append(list, "the ");
-    list = ucx_list_append(list, "last!");
+    list = ucx_list_append(list, (void*)"the ");
+    list = ucx_list_append(list, (void*)"last!");
     
     const char* last = (const char*) (ucx_list_last(list)->data);
     
@@ -103,10 +103,10 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_list_get) {
-    UcxList *list = ucx_list_append(NULL, "Find ");
+    UcxList *list = ucx_list_append(NULL, (void*)"Find ");
     UCX_TEST_BEGIN
-    list = ucx_list_append(list, "the ");
-    list = ucx_list_append(list, "mid!");
+    list = ucx_list_append(list, (void*)"the ");
+    list = ucx_list_append(list, (void*)"mid!");
     
     const char* mid = (const char*) (ucx_list_get(list, 1)->data);
     
@@ -117,10 +117,10 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_list_remove) {
-    UcxList *list = ucx_list_append(NULL, "Hello");
+    UcxList *list = ucx_list_append(NULL, (void*)"Hello");
     UCX_TEST_BEGIN
-    list = ucx_list_append(list, " fucking");
-    list = ucx_list_append(list, " World!");
+    list = ucx_list_append(list, (void*)" fucking");
+    list = ucx_list_append(list, (void*)" World!");
     
     list = ucx_list_remove(list, ucx_list_get(list, 1));
     
@@ -163,21 +163,21 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_list_sort) {
-    UcxList *list = ucx_list_append(NULL, "this");
-    list = ucx_list_append(list, "is");
-    list = ucx_list_append(list, "a");
-    list = ucx_list_append(list, "test");
-    list = ucx_list_append(list, "for");
-    list = ucx_list_append(list, "partial");
-    list = ucx_list_append(list, "correctness");
+    UcxList *list = ucx_list_append(NULL, (void*)"this");
+    list = ucx_list_append(list, (void*)"is");
+    list = ucx_list_append(list, (void*)"a");
+    list = ucx_list_append(list, (void*)"test");
+    list = ucx_list_append(list, (void*)"for");
+    list = ucx_list_append(list, (void*)"partial");
+    list = ucx_list_append(list, (void*)"correctness");
 
-    UcxList *expected = ucx_list_append(NULL, "a");
-    expected = ucx_list_append(expected, "correctness");
-    expected = ucx_list_append(expected, "for");
-    expected = ucx_list_append(expected, "is");
-    expected = ucx_list_append(expected, "partial");
-    expected = ucx_list_append(expected, "test");
-    expected = ucx_list_append(expected, "this");
+    UcxList *expected = ucx_list_append(NULL, (void*)"a");
+    expected = ucx_list_append(expected, (void*)"correctness");
+    expected = ucx_list_append(expected, (void*)"for");
+    expected = ucx_list_append(expected, (void*)"is");
+    expected = ucx_list_append(expected, (void*)"partial");
+    expected = ucx_list_append(expected, (void*)"test");
+    expected = ucx_list_append(expected, (void*)"this");
 
     list = ucx_list_sort(list, cmp_string, NULL);
 
--- a/test/map_tests.c	Fri Oct 12 10:54:55 2012 +0200
+++ b/test/map_tests.c	Fri Oct 12 12:08:34 2012 +0200
@@ -15,7 +15,7 @@
 }
 
 UCX_TEST_IMPLEMENT(test_ucx_key) {
-    UcxKey key = ucx_key("This is a text.", 15);
+    UcxKey key = ucx_key((void*)"This is a text.", 15);
     UCX_TEST_BEGIN
     UCX_TEST_ASSERT(strncmp((const char*)key.data, "This is a text.", 15) == 0,
             "failed");
@@ -194,12 +194,12 @@
 UCX_TEST_IMPLEMENT(test_ucx_map_store_load) {
     UcxMap *map = ucx_map_new(4);
 
-    ucx_map_cstr_put(map, "test", "test");
-    ucx_map_cstr_put(map, "key", "value");
-    ucx_map_cstr_put(map, "other.very.long.key", "value");
-    ucx_map_cstr_put(map, "testkey", "testvalue");
-    ucx_map_cstr_put(map, "simple", "not a key but an extremely long value "
-            "to test if the buffer extension works as designed");
+    ucx_map_cstr_put(map, "test", (void*)"test");
+    ucx_map_cstr_put(map, "key", (void*)"value");
+    ucx_map_cstr_put(map, "other.very.long.key", (void*)"value");
+    ucx_map_cstr_put(map, "testkey", (void*)"testvalue");
+    ucx_map_cstr_put(map, "simple", (void*)"not a key but an extremely long "
+            "value to test if the buffer extension works as designed");
 
     UCX_TEST_BEGIN
     FILE *f = tmpfile();
@@ -259,10 +259,10 @@
 UCX_TEST_IMPLEMENT(test_ucx_map_store_load_with_mempool) {
     UcxMap *map = ucx_map_new(4);
 
-    ucx_map_cstr_put(map, "test", "test");
-    ucx_map_cstr_put(map, "key", "value");
-    ucx_map_cstr_put(map, "testkey", "testvalue");
-    ucx_map_cstr_put(map, "simple", "a simple value");
+    ucx_map_cstr_put(map, "test", (void*)"test");
+    ucx_map_cstr_put(map, "key", (void*)"value");
+    ucx_map_cstr_put(map, "testkey", (void*)"testvalue");
+    ucx_map_cstr_put(map, "simple", (void*)"a simple value");
 
     UCX_TEST_BEGIN
     FILE *f = tmpfile();
@@ -297,9 +297,9 @@
 UCX_TEST_IMPLEMENT(test_ucx_map_clone) {
     UcxMap *map = ucx_map_new(4);
     
-    ucx_map_cstr_put(map, "key1", "value1");
-    ucx_map_cstr_put(map, "key2", "value2");
-    ucx_map_cstr_put(map, "key3", "value3");
+    ucx_map_cstr_put(map, "key1", (void*)"value1");
+    ucx_map_cstr_put(map, "key2", (void*)"value2");
+    ucx_map_cstr_put(map, "key3", (void*)"value3");
     
     UcxMap *clone = ucx_map_clone(map, NULL, NULL);
     
--- a/test/string_tests.c	Fri Oct 12 10:54:55 2012 +0200
+++ b/test/string_tests.c	Fri Oct 12 12:08:34 2012 +0200
@@ -158,10 +158,8 @@
     /* exact match (exm) */
     n = 0;
     list = sstrsplit(test, ST("this,is,a,csv,string"), &n);
-    UCX_TEST_ASSERT(n == 1, "exm, list length must be 1");
-    UCX_TEST_ASSERT(list[0].length == 0, "exm, single item must be empty");
-    UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
-            "exm, original has been modified");
+    UCX_TEST_ASSERT(n == 0, "exm, list length must be 0");
+    UCX_TEST_ASSERT(list == NULL, "exm, list must be NULL");
     free(list);
 
     /* substring (subs) */
--- a/ucx/map.h	Fri Oct 12 10:54:55 2012 +0200
+++ b/ucx/map.h	Fri Oct 12 12:08:34 2012 +0200
@@ -67,12 +67,18 @@
 void* ucx_map_get(UcxMap *map, UcxKey key);
 void* ucx_map_remove(UcxMap *map, UcxKey key);
 
-#define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d)
-#define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d)
-#define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length))
-#define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s)))
-#define ucx_map_sstr_remove(m, s) ucx_map_remove(m, ucx_key(s.ptr, s.length))
-#define ucx_map_cstr_remove(m, s) ucx_map_remove(m, ucx_key(s, 1+strlen(s)))
+#define ucx_map_sstr_put(m, s, d) \
+    ucx_map_put(m, ucx_key((void*)s.ptr, s.length), d)
+#define ucx_map_cstr_put(m, s, d) \
+    ucx_map_put(m, ucx_key((void*)s, 1+strlen(s)), d)
+#define ucx_map_sstr_get(m, s) \
+    ucx_map_get(m, ucx_key((void*)s.ptr, s.length))
+#define ucx_map_cstr_get(m, s) \
+    ucx_map_get(m, ucx_key((void*)s, 1+strlen(s)))
+#define ucx_map_sstr_remove(m, s) \
+    ucx_map_remove(m, ucx_key((void*)s.ptr, s.length))
+#define ucx_map_cstr_remove(m, s) \
+    ucx_map_remove(m, ucx_key((void*)s, 1+strlen(s)))
 
 UcxKey ucx_key(void *data, size_t len);
 
--- a/ucx/string.c	Fri Oct 12 10:54:55 2012 +0200
+++ b/ucx/string.c	Fri Oct 12 12:08:34 2012 +0200
@@ -110,9 +110,8 @@
 
     /* special case: exact match - no processing needed */
     if (s.length == d.length && strncmp(s.ptr, d.ptr, s.length) == 0) {
-        result = (sstr_t*) malloc(sizeof(sstr_t));
-        result[0] = sstrn("", 0);
-        return result;
+        *n = 0;
+        return NULL;
     }
     sstr_t sv = sstrdup(s);
 

mercurial