summaryrefslogtreecommitdiffhomepage
path: root/src/pool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pool.c')
-rw-r--r--src/pool.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/pool.c b/src/pool.c
index 3cbb2b163..daa6d0f69 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -8,6 +8,18 @@
#include <stddef.h>
#include <string.h>
+/* configuration section */
+/* allocated memory address should be multiple of POOL_ALIGNMENT */
+/* or undef it if alignment does not matter */
+#ifndef POOL_ALIGNMENT
+#define POOL_ALIGNMENT 4
+#endif
+/* page size of memory pool */
+#ifndef POOL_PAGE_SIZE
+#define POOL_PAGE_SIZE 16000
+#endif
+/* end of configuration section */
+
struct mrb_pool_page {
struct mrb_pool_page *next;
size_t offset;
@@ -23,16 +35,13 @@ struct mrb_pool {
#undef TEST_POOL
#ifdef TEST_POOL
-#include <stdio.h>
#define mrb_malloc(m,s) malloc(s)
#define mrb_free(m,p) free(p)
#endif
-#define POOL_PAGE_SIZE 16000
-
-#ifdef ALLOC_ALIGN
-# define ALIGN_PADDING(x) ((x % ALLOC_ALIGN) ? ALLOC_ALIGN - (x % ALLOC_ALIGN) : 0)
+#ifdef POOL_ALIGNMENT
+# define ALIGN_PADDING(x) ((-x) & (POOL_ALIGNMENT - 1))
#else
# define ALIGN_PADDING(x) (0)
#endif
@@ -40,7 +49,7 @@ struct mrb_pool {
mrb_pool*
mrb_pool_open(mrb_state *mrb)
{
- mrb_pool *pool = mrb_malloc(mrb, sizeof(mrb_pool));
+ mrb_pool *pool = (mrb_pool *)mrb_malloc(mrb, sizeof(mrb_pool));
if (pool) {
pool->mrb = mrb;
@@ -72,7 +81,7 @@ page_alloc(mrb_pool *pool, size_t len)
if (len < POOL_PAGE_SIZE)
len = POOL_PAGE_SIZE;
- page = mrb_malloc(pool->mrb, sizeof(struct mrb_pool_page)+len-1);
+ page = (struct mrb_pool_page *)mrb_malloc(pool->mrb, sizeof(struct mrb_pool_page)+len-1);
if (page) {
page->offset = 0;
page->len = len;