summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fat_patree.c13
-rw-r--r--src/hash.c2
-rw-r--r--src/patree.c3
-rw-r--r--src/ring.c22
-rw-r--r--src/sorted_array.c9
-rw-r--r--src/strindex.c7
-rw-r--r--src/tree.c5
7 files changed, 34 insertions, 27 deletions
diff --git a/src/fat_patree.c b/src/fat_patree.c
index 278da2a..454cfba 100644
--- a/src/fat_patree.c
+++ b/src/fat_patree.c
@@ -17,7 +17,6 @@
#define _XOPEN_SOURCE 500
#include <assert.h>
-#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -85,15 +84,16 @@ patree_find_edge(ZixFatPatreeNode* n, uint8_t c, n_edges_t* index)
static void
patree_add_edge(ZixFatPatreeNode* n,
- char* str,
- char* first,
- char* last)
+ char* str,
+ char* first,
+ char* last)
{
assert(last >= first);
const int index = (uint8_t)first[0];
assert(!n->children[index]);
- ZixFatPatreeNode* new_node = malloc(sizeof(ZixFatPatreeNode));
+ ZixFatPatreeNode* new_node = (ZixFatPatreeNode*)malloc(
+ sizeof(ZixFatPatreeNode));
n->children[index] = new_node;
n->children[index]->label_first = first;
n->children[index]->label_last = last;
@@ -112,7 +112,8 @@ patree_split_edge(ZixFatPatreeNode* child,
char* const last = child->label_last;
assert(last >= first);
- ZixFatPatreeNode* new_node = malloc(sizeof(ZixFatPatreeNode));
+ ZixFatPatreeNode* new_node = (ZixFatPatreeNode*)malloc(
+ sizeof(ZixFatPatreeNode));
new_node->label_first = first;
new_node->label_last = last;
new_node->str = child->str;
diff --git a/src/hash.c b/src/hash.c
index c267757..f654e91 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -55,7 +55,7 @@ zix_hash_new(ZixHashFunc hash_func,
hash->key_equal_func = key_equal_func;
hash->count = 0;
hash->n_buckets = &sizes[0];
- hash->buckets = malloc(*hash->n_buckets * sizeof(Entry*));
+ hash->buckets = (Entry**)malloc(*hash->n_buckets * sizeof(Entry*));
memset(hash->buckets, 0, *hash->n_buckets * sizeof(Entry*));
return hash;
diff --git a/src/patree.c b/src/patree.c
index 0cb74d3..f3603a2 100644
--- a/src/patree.c
+++ b/src/patree.c
@@ -17,7 +17,6 @@
#define _XOPEN_SOURCE 500
#include <assert.h>
-#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -61,7 +60,7 @@ zix_patree_print_rec(ZixPatreeNode* node, FILE* fd)
{
if (node->label_first) {
size_t edge_label_len = node->label_last - node->label_first + 1;
- char* edge_label = malloc(edge_label_len + 1);
+ char* edge_label = (char*)malloc(edge_label_len + 1);
strncpy(edge_label, node->label_first, edge_label_len);
fprintf(fd, "\t\"%p\" [label=<"
"<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">"
diff --git a/src/ring.c b/src/ring.c
index fd5133a..7ebbe67 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -20,15 +20,25 @@
#ifdef HAVE_MLOCK
# include <sys/mman.h>
+# define ZIX_MLOCK(ptr, size) mlock((ptr), (size))
+#elif defined(_WIN32)
+# include <windows.h>
+# define ZIX_MLOCK(ptr, size) VirtualLock((ptr), (size))
+#else
+# pragma message("warning: No memory locking, possible RT violations")
+# define ZIX_MLOCK(ptr, size)
#endif
#if defined(__APPLE__)
# include <libkern/OSAtomic.h>
# define ZIX_FULL_BARRIER() OSMemoryBarrier()
+#elif defined(_WIN32)
+# include <windows.h>
+# define ZIX_FULL_BARRIER() MemoryBarrier()
#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
# define ZIX_FULL_BARRIER() __sync_synchronize()
#else
-# warning Memory barriers unsupported, possible bugs on SMP systems
+# pragma message("warning: No memory barriers, possible SMP bugs")
# define ZIX_FULL_BARRIER()
#endif
@@ -68,7 +78,7 @@ zix_ring_new(uint32_t size)
ring->read_head = 0;
ring->size = next_power_of_two(size);
ring->size_mask = ring->size - 1;
- ring->buf = malloc(ring->size);
+ ring->buf = (char*)malloc(ring->size);
return ring;
}
@@ -82,12 +92,8 @@ zix_ring_free(ZixRing* ring)
void
zix_ring_mlock(ZixRing* ring)
{
-#ifdef HAVE_MLOCK
- mlock(ring, sizeof(ZixRing));
- mlock(ring->buf, ring->size);
-#else
-# warning Memory locking (via mlock) unsupported
-#endif
+ ZIX_MLOCK(ring, sizeof(ZixRing));
+ ZIX_MLOCK(ring->buf, ring->size);
}
void
diff --git a/src/sorted_array.c b/src/sorted_array.c
index ae08946..f8e785d 100644
--- a/src/sorted_array.c
+++ b/src/sorted_array.c
@@ -15,7 +15,6 @@
*/
#include <assert.h>
-#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -51,10 +50,12 @@ zix_sorted_array_print(ZixSortedArray* a)
ZIX_API
ZixSortedArray*
-zix_sorted_array_new(bool allow_duplicates, ZixComparator cmp, void* cmp_data,
- size_t elem_size)
+zix_sorted_array_new(bool allow_duplicates,
+ ZixComparator cmp,
+ void* cmp_data,
+ size_t elem_size)
{
- ZixSortedArray* a = malloc(sizeof(ZixSortedArray));
+ ZixSortedArray* a = (ZixSortedArray*)malloc(sizeof(ZixSortedArray));
a->array = NULL;
a->cmp = cmp;
a->cmp_data = cmp_data;
diff --git a/src/strindex.c b/src/strindex.c
index eae98b2..886d261 100644
--- a/src/strindex.c
+++ b/src/strindex.c
@@ -109,8 +109,8 @@ strindex_add_edge(ZixStrindexNode* n,
char* last)
{
assert(last > first);
- n->children = realloc(n->children,
- (n->num_children + 1) * sizeof(ZixStrindexNode));
+ n->children = (ZixStrindexNode*)realloc(
+ n->children, (n->num_children + 1) * sizeof(ZixStrindexNode));
memset(&n->children[n->num_children], '\0', sizeof(ZixStrindexNode));
@@ -133,7 +133,8 @@ strindex_split_edge(ZixStrindexNode* child,
assert(last > first);
assert(child->first);
- child->children = malloc(sizeof(ZixStrindexNode));
+ child->children = (ZixStrindexNode*)malloc(sizeof(ZixStrindexNode));
+
child->children[0].children = children;
child->children[0].num_children = num_children;
child->children[0].first = child->first;
diff --git a/src/tree.c b/src/tree.c
index 13b7745..74f882a 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -15,7 +15,6 @@
*/
#include <assert.h>
-#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -74,7 +73,7 @@ zix_tree_new(bool allow_duplicates,
void* cmp_data,
ZixDestroyFunc destroy)
{
- ZixTree* t = malloc(sizeof(ZixTree));
+ ZixTree* t = (ZixTree*)malloc(sizeof(ZixTree));
t->root = NULL;
t->destroy = destroy;
t->cmp = cmp;
@@ -366,7 +365,7 @@ zix_tree_insert(ZixTree* t, void* e, ZixTreeIter** ti)
}
// Allocate a new node n
- if (!(n = malloc(sizeof(ZixTreeNode)))) {
+ if (!(n = (ZixTreeNode*)malloc(sizeof(ZixTreeNode)))) {
return ZIX_STATUS_NO_MEM;
}
memset(n, '\0', sizeof(ZixTreeNode));