fixed ultra fail + renamed files from mpool to mempool

Sat, 31 Dec 2011 22:46:27 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 31 Dec 2011 22:46:27 +0100
changeset 16
b4769e4eb4d1
parent 15
2dc4c688c262
child 17
2e7050c3a18e

fixed ultra fail + renamed files from mpool to mempool

.hgignore file | annotate | diff | comparison | revisions
ucx/Makefile file | annotate | diff | comparison | revisions
ucx/mempool.c file | annotate | diff | comparison | revisions
ucx/mempool.h file | annotate | diff | comparison | revisions
ucx/mpool.c file | annotate | diff | comparison | revisions
ucx/mpool.h file | annotate | diff | comparison | revisions
--- a/.hgignore	Sat Dec 31 22:41:16 2011 +0100
+++ b/.hgignore	Sat Dec 31 22:46:27 2011 +0100
@@ -1,3 +1,4 @@
 syntax:regexp
 ^nbproject/.*$
 ^build/.*$
+^core$
--- a/ucx/Makefile	Sat Dec 31 22:41:16 2011 +0100
+++ b/ucx/Makefile	Sat Dec 31 22:46:27 2011 +0100
@@ -29,7 +29,7 @@
 include ../$(CONF).mk
 
 # list of source files
-SRC = list.c dlist.c map.c mpool.c
+SRC = list.c dlist.c map.c mempool.c
 
 OBJ = $(SRC:%.c=../build/%.$(OBJ_EXT))
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ucx/mempool.c	Sat Dec 31 22:46:27 2011 +0100
@@ -0,0 +1,119 @@
+/*
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include "mpool.h"
+
+typedef struct {
+    ucx_destructor destructor;
+    char c;
+} ucx_memchunk;
+
+typedef struct {
+    ucx_destructor destructor;
+    void           *ptr;
+} ucx_regdestr;
+
+void ucx_mempool_shared_destr(void* ptr) {
+    ucx_regdestr *rd = (ucx_regdestr*)ptr;
+    rd->destructor(rd->ptr);
+}
+
+UcxMempool *ucx_mempool_new(size_t n) {
+    UcxMempool *pool = (UcxMempool*)malloc(sizeof(UcxMempool));
+    if (pool == NULL) return NULL;
+    
+    pool->data = malloc(n * sizeof(void*));
+    if (pool->data == NULL) {
+        free(pool);
+        return NULL;
+    }
+    
+    pool->ndata = 0;
+    pool->size = n;
+    return pool;
+}
+
+int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) {
+    void **data = realloc(pool->data, newcap*sizeof(void*));
+    if (data == NULL) {
+        return ENOMEM;
+    } else {
+        pool->data = data; 
+        pool->size = newcap;
+        return EXIT_SUCCESS;
+    }
+}
+
+void *ucx_mempool_malloc(UcxMempool *pool, size_t n) {
+    ucx_memchunk *mem = (ucx_memchunk*)malloc(sizeof(ucx_destructor) + n);
+    if (mem == NULL) return NULL;
+
+    if (pool->ndata >= pool->size) {
+        ucx_mempool_chcap(pool, pool->size + 16);
+     }
+
+    mem->destructor = NULL;
+    pool->data[pool->ndata] = mem;
+    pool->ndata++;
+
+    return &mem->c;
+}
+
+void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize) {
+    void *ptr = ucx_mempool_malloc(pool, nelem*elsize);
+    if(ptr == NULL) {
+        return NULL;
+    }
+    memset(ptr, 0, nelem * elsize);
+    return ptr;
+}
+
+void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n) {
+    void *mem = ((char*)ptr) - sizeof(ucx_destructor);
+    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++) {
+            if(pool->data[i] == mem) {
+                pool->data[i] = newm;
+                return ((char*) newm) + sizeof(ucx_destructor);
+            }
+        }
+        fprintf(stderr, "FATAL: %8x not in mpool %8x\n", mem, pool);
+        exit(1);
+    } else {
+        return ((char*) newm) + sizeof(ucx_destructor);
+    }
+}
+
+void ucx_mempool_free(UcxMempool *pool) {
+    ucx_memchunk *chunk;
+    for(int i=0;i<pool->ndata;i++) {
+        chunk = (ucx_memchunk*) pool->data[i];
+        if(chunk->destructor != NULL) {
+            chunk->destructor(&chunk->c);
+        }
+        free(chunk);
+    }
+    free(pool->data);
+    free(pool);
+}
+
+void ucx_mempool_set_destr(void *ptr, ucx_destructor func) {
+    *(ucx_destructor*)((char*)ptr-sizeof(ucx_destructor)) = func;
+}
+
+void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr) {
+    ucx_regdestr *rd = (ucx_regdestr*)ucx_mempool_malloc(
+            pool,
+            sizeof(ucx_regdestr));
+    rd->destructor = destr;
+    rd->ptr = ptr;
+    ucx_mempool_set_destr(rd, ucx_mempool_shared_destr);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ucx/mempool.h	Sat Dec 31 22:46:27 2011 +0100
@@ -0,0 +1,39 @@
+/* 
+ *
+ */
+
+#ifndef MPOOL_H
+#define	MPOOL_H
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+typedef void(*ucx_destructor)(void*);
+
+typedef struct {
+    void   **data;
+    size_t ndata;
+    size_t size;
+} UcxMempool;
+
+#define ucx_mempool_new_default() ucx_mempool_new(16)
+UcxMempool *ucx_mempool_new(size_t n);
+int ucx_mempool_chcap(UcxMempool *pool, size_t newcap);
+
+void *ucx_mempool_malloc(UcxMempool *pool, size_t n);
+void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize);
+void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
+
+void ucx_mempool_free(UcxMempool *pool);
+
+void ucx_mempool_set_destr(void *ptr, ucx_destructor func);
+void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* MPOOL_H */
+
--- a/ucx/mpool.c	Sat Dec 31 22:41:16 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,118 +0,0 @@
-/*
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include "mpool.h"
-
-typedef struct {
-    ucx_destructor destructor;
-    char c;
-} ucx_memchunk;
-
-typedef struct {
-    ucx_destructor destructor;
-    void           *ptr;
-} ucx_regdestr;
-
-void ucx_mempool_shared_destr(void* ptr) {
-    ucx_regdestr *rd = (ucx_regdestr*)ptr;
-    rd->destructor(rd->ptr);
-}
-
-UcxMempool *ucx_mempool_new(size_t n) {
-    UcxMempool *pool = (UcxMempool*)malloc(sizeof(UcxMempool));
-    if (pool == NULL) return NULL;
-    
-    pool->data = malloc(n * sizeof(void*));
-    if (pool->data == NULL) {
-        free(pool);
-        return NULL;
-    }
-    
-    pool->ndata = 0;
-    pool->size = n;
-    return pool;
-}
-
-int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) {
-    void **data = realloc(pool->data, newcap*sizeof(void*));
-    if (data == NULL) {
-        return ENOMEM;
-    } else {
-        pool->data = data; 
-        pool->size = newcap;
-        return EXIT_SUCCESS;
-    }
-}
-
-void *ucx_mempool_malloc(UcxMempool *pool, size_t n) {
-    ucx_memchunk *mem = (ucx_memchunk*)malloc(sizeof(ucx_destructor) + n);
-    if (mem == NULL) return NULL;
-
-    if (pool->ndata >= pool->size) {
-        ucx_mempool_chcap(pool, pool->size + 16);
-     }
-
-    mem->destructor = NULL;
-    pool->data[pool->ndata] = mem;
-    pool->ndata++;
-
-    return &mem->c;
-}
-
-void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize) {
-    void *ptr = ucx_mempool_malloc(pool, nelem*elsize);
-    if(ptr == NULL) {
-        return NULL;
-    }
-    memset(ptr, 0, nelem * elsize);
-    return ptr;
-}
-
-void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n) {
-    void *mem = ((char*)ptr) - sizeof(ucx_destructor);
-    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++) {
-            if(pool->data[i] == mem) {
-                pool->data[i] = newm;
-                break;
-            }
-        }
-        fprintf(stderr, "FATAL: %8x not in mpool %8x\n", mem, pool);
-        exit(1);
-    }
-    return ((char*) newm) + sizeof(ucx_destructor);
-}
-
-void ucx_mempool_free(UcxMempool *pool) {
-    ucx_memchunk *chunk;
-    for(int i=0;i<pool->ndata;i++) {
-        chunk = (ucx_memchunk*) pool->data[i];
-        if(chunk->destructor != NULL) {
-            chunk->destructor(&chunk->c);
-        }
-        free(chunk);
-    }
-    free(pool->data);
-    free(pool);
-}
-
-void ucx_mempool_set_destr(void *ptr, ucx_destructor func) {
-    *(ucx_destructor*)((char*)ptr-sizeof(ucx_destructor)) = func;
-}
-
-void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr) {
-    ucx_regdestr *rd = (ucx_regdestr*)ucx_mempool_malloc(
-            pool,
-            sizeof(ucx_regdestr));
-    rd->destructor = destr;
-    rd->ptr = ptr;
-    ucx_mempool_set_destr(rd, ucx_mempool_shared_destr);
-}
--- a/ucx/mpool.h	Sat Dec 31 22:41:16 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/* 
- *
- */
-
-#ifndef MPOOL_H
-#define	MPOOL_H
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-typedef void(*ucx_destructor)(void*);
-
-typedef struct {
-    void   **data;
-    size_t ndata;
-    size_t size;
-} UcxMempool;
-
-#define ucx_mempool_new_default() ucx_mempool_new(16)
-UcxMempool *ucx_mempool_new(size_t n);
-int ucx_mempool_chcap(UcxMempool *pool, size_t newcap);
-
-void *ucx_mempool_malloc(UcxMempool *pool, size_t n);
-void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize);
-void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
-
-void ucx_mempool_free(UcxMempool *pool);
-
-void ucx_mempool_set_destr(void *ptr, ucx_destructor func);
-void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr);
-
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif	/* MPOOL_H */
-

mercurial