some fixes

Wed, 06 Feb 2013 12:55:56 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 06 Feb 2013 12:55:56 +0100
changeset 78
af355652f271
parent 77
51311a5685d3
child 79
cf3757c60c8f

some fixes

ucx/buffer.c file | annotate | diff | comparison | revisions
ucx/map.h file | annotate | diff | comparison | revisions
--- a/ucx/buffer.c	Thu Jan 17 23:56:48 2013 +0100
+++ b/ucx/buffer.c	Wed Feb 06 12:55:56 2013 +0100
@@ -8,7 +8,7 @@
     if (buffer) {
         buffer->flags = flags;
         if (!space) {
-            buffer->space = malloc(size);
+            buffer->space = (char*)malloc(size);
             if (!buffer->space) {
                 free(buffer);
                 return NULL;
@@ -16,7 +16,7 @@
             memset(buffer->space, 0, size);
             buffer->flags |= UCX_BUFFER_AUTOFREE;
         } else {
-            buffer->space = space;
+            buffer->space = (char*)space;
         }
         buffer->capacity = size;
         buffer->size = 0;
@@ -48,7 +48,7 @@
 
     UcxBuffer *dst = (UcxBuffer*) malloc(sizeof(UcxBuffer));
     if (dst) {
-        dst->space = malloc(length);
+        dst->space = (char*)malloc(length);
         if (!dst->space) {
             free(dst);
             return NULL;
@@ -95,7 +95,7 @@
     size_t newcap = buffer->capacity;
     while (buffer->pos + len > newcap) newcap <<= 1;
     
-    char *newspace = realloc(buffer->space, newcap);
+    char *newspace = (char*)realloc(buffer->space, newcap);
     if (newspace) {
         memset(newspace+buffer->size, 0, newcap-buffer->size);
         buffer->space = newspace;
@@ -185,7 +185,7 @@
 size_t ucx_buffer_generic_copy(void *s1, void *s2,
         read_func readfnc, write_func writefnc, size_t bufsize) {
     size_t ncp = 0;
-    char *buf = malloc(bufsize);
+    char *buf = (char*)malloc(bufsize);
     if(buf == NULL) {
         return 0;
     }
--- a/ucx/map.h	Thu Jan 17 23:56:48 2013 +0100
+++ b/ucx/map.h	Wed Feb 06 12:55:56 2013 +0100
@@ -68,17 +68,25 @@
 void* ucx_map_remove(UcxMap *map, UcxKey key);
 
 #define ucx_map_sstr_put(m, s, d) \
-    ucx_map_put(m, ucx_key((void*)s.ptr, s.length), 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((void*)s, 1+strlen(s)), d)
+    ucx_map_put(m, ucx_key((void*)s, strlen(s)), d)
+#define ucx_map_int_put(m, i, d) \
+    ucx_map_put(m, ucx_key((void*)&i, sizeof(d)), d)
+
 #define ucx_map_sstr_get(m, s) \
-    ucx_map_get(m, ucx_key((void*)s.ptr, s.length))
+    ucx_map_get(m, ucx_key(s.ptr, s.length))
 #define ucx_map_cstr_get(m, s) \
-    ucx_map_get(m, ucx_key((void*)s, 1+strlen(s)))
+    ucx_map_get(m, ucx_key((void*)s, strlen(s)))
+#define ucx_map_int_get(m, i) \
+    ucx_map_get(m, ucx_key((void*)&i, sizeof(int)))
+
 #define ucx_map_sstr_remove(m, s) \
-    ucx_map_remove(m, ucx_key((void*)s.ptr, s.length))
+    ucx_map_remove(m, ucx_key(s.ptr, s.length))
 #define ucx_map_cstr_remove(m, s) \
-    ucx_map_remove(m, ucx_key((void*)s, 1+strlen(s)))
+    ucx_map_remove(m, ucx_key((void*)s, strlen(s)))
+#define ucx_map_int_remove(m, i) \
+    ucx_map_remove(m, ucx_key((void*)&i, sizeof(int)))
 
 UcxKey ucx_key(void *data, size_t len);
 

mercurial