diff --git a/libkc3/alloc.c b/libkc3/alloc.c
index 3fec482..7c06291 100644
--- a/libkc3/alloc.c
+++ b/libkc3/alloc.c
@@ -10,23 +10,124 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/mman.h>
#include "alloc.h"
#include "assert.h"
-#include <stdlib.h>
+#include "skiplist__alloc.h"
+#include "skiplist_node__alloc.h"
+
+static sw g_alloc_init = 0;
+static s_skiplist__alloc g_alloc_skiplist_mapped_size = {0};
+static s_skiplist__alloc g_alloc_skiplist_size_mapped = {0};
void * alloc (uw size)
{
- void *a;
+ s_alloc *a;
if (! size) {
err_puts("alloc: zero size");
assert(! "alloc: zero size");
return NULL;
}
- a = calloc(1, size);
+ a = alloc_map(sizeof(s_alloc));
if (! a) {
- err_puts("alloc: failed to allocate memory");
- assert(! "alloc: failed to allocate memory");
+ err_puts("alloc: alloc_map(s_alloc)");
+ assert(! "alloc: alloc_map(s_alloc)");
+ return NULL;
+ }
+ a->size = size;
+ a->mapped = alloc_map(size);
+ if (! a->mapped) {
+ err_puts("alloc: alloc_map(size)");
+ assert(! "alloc: alloc_map(size)");
+ return NULL;
+ }
+ skiplist_insert__alloc(&g_alloc_skiplist_mapped_size, a);
+ skiplist_insert__alloc(&g_alloc_skiplist_size_mapped, a);
+ return a->mapped;
+}
+
+void alloc_clean (void)
+{
+ g_alloc_init--;
+ if (! g_alloc_init) {
+ skiplist_clean__alloc(&g_alloc_skiplist_mapped_size);
+ skiplist_clean__alloc(&g_alloc_skiplist_size_mapped);
+ }
+}
+
+s8 alloc_init (void)
+{
+ if (g_alloc_init) {
+ g_alloc_init++;
+ return 0;
+ }
+ if (! skiplist_init__alloc(&g_alloc_skiplist_mapped_size, 32, 2.5)) {
+ err_puts("alloc_init: skiplist_init__alloc 1");
+ assert(! "alloc_init: skiplist_init__alloc 1");
+ return 1;
+ }
+ if (! skiplist_init__alloc(&g_alloc_skiplist_size_mapped, 32, 2.5)) {
+ err_puts("alloc_init: skiplist_init__alloc 2");
+ assert(! "alloc_init: skiplist_init__alloc 2");
+ return 1;
+ }
+ g_alloc_init = 1;
+ return 0;
+}
+
+void free (void *allocated)
+{
+ s_alloc *al;
+ s_skiplist_node__alloc *node;
+ s_skiplist_node__alloc *pred;
+ s_alloc pred_alloc = {0};
+ pred_alloc.mapped = allocated;
+ if (! (pred = skiplist_pred__alloc(&g_alloc_skiplist_mapped_size,
+ &pred_alloc)))
+ goto ko;
+ if (! (node = SKIPLIST_NODE_NEXT__alloc(pred, 0)))
+ goto ko;
+ al = node->alloc;
+ if (al->mapped != allocated)
+ goto ko;
+ alloc_unmap(allocated, al->size);
+ skiplist_remove__alloc(&g_alloc_skiplist_mapped_size, al);
+ skiplist_remove__alloc(&g_alloc_skiplist_size_mapped, al);
+ alloc_unmap(al, sizeof(s_alloc));
+ ko:
+ err_puts("free: invalid argument");
+ assert(! "free: invalid argument");
+}
+
+void * alloc_map (uw size)
+{
+ sw e;
+ void *mapped = NULL;
+ if ((mapped = mmap(NULL, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON, -1, 0)) == MAP_FAILED) {
+ e = errno;
+ err_write_1("alloc_map: mmap: ");
+ err_write_1(strerror(e));
+ err_write_1("\n");
+ assert(! "alloc_map: mmap");
return NULL;
}
- return a;
+ bzero(mapped, size);
+ return mapped;
+}
+
+void alloc_unmap (void *mapped, uw size)
+{
+ sw e;
+ if (munmap(mapped, size) < 0) {
+ e = errno;
+ err_write_1("alloc_unmap: munmap: ");
+ err_write_1(strerror(e));
+ err_write_1("\n");
+ assert(! "alloc_unmap: munmap");
+ }
}
diff --git a/libkc3/alloc.h b/libkc3/alloc.h
index 9c294b5..5a1f61f 100644
--- a/libkc3/alloc.h
+++ b/libkc3/alloc.h
@@ -15,7 +15,16 @@
#include "types.h"
+/* Library initialization. Use alloc_clean after use. */
+void alloc_clean (void);
+s8 alloc_init (void);
+
+/* Heap-allocation functions. Use alloc_free after use. */
void * alloc (uw size);
-void free (void *ptr);
+void alloc_free (void *allocated);
+
+/* Memory mapping. Use alloc_unmap after use. */
+void * alloc_map (uw size);
+void alloc_unmap (void *mapped, uw size);
#endif /* LIBKC3_ALLOC_H */
diff --git a/libkc3/arg.c b/libkc3/arg.c
deleted file mode 100644
index 1f52e1c..0000000
--- a/libkc3/arg.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/* kc3
- * Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software granted the above
- * copyright notice and this permission paragraph are included in all
- * copies and substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include "alloc.h"
-#include "assert.h"
-#include "arg.h"
-
-s_arg * arg_delete (s_arg *arg)
-{
- s_arg *next = NULL;
- if (arg) {
- next = arg->next;
- free(arg);
- }
- return next;
-}
-
-void arg_delete_all (s_arg *arg)
-{
- while (arg)
- arg = arg_delete(arg);
-}
-
-s_arg * arg_init (s_arg *arg)
-{
- assert(arg);
- *arg = (s_arg) {0};
- return arg;
-}
-
-uw arg_length (s_arg *arg)
-{
- uw length = 0;
- while (arg) {
- length++;
- arg = arg->next;
- }
- return length;
-}
-
-s_arg * arg_new (void)
-{
- s_arg *arg;
- arg = alloc(sizeof(s_arg));
- if (! arg)
- return NULL;
- if (! arg_init(arg)) {
- free(arg);
- return NULL;
- }
- return arg;
-}
diff --git a/libkc3/arg.h b/libkc3/arg.h
deleted file mode 100644
index 21794c5..0000000
--- a/libkc3/arg.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* kc3
- * Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software granted the above
- * copyright notice and this permission paragraph are included in all
- * copies and substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#ifndef LIBC3_ARG_H
-#define LIBC3_ARG_H
-
-#include "types.h"
-
-/* stack-allocation compatible functions */
-s_arg * arg_init (s_arg *arg);
-
-/* constructors */
-s_arg * arg_new (void);
-
-/* destructors */
-s_arg * arg_delete (s_arg *arg);
-void arg_delete_all (s_arg *arg);
-
-/* observers */
-uw arg_length (s_arg *args);
-
-#endif /* LIBC3_ARG_H */
diff --git a/libkc3/binding.c b/libkc3/binding.c
index d69e763..64e9abf 100644
--- a/libkc3/binding.c
+++ b/libkc3/binding.c
@@ -23,7 +23,7 @@ s_binding * binding_delete (s_binding *binding)
assert(binding);
tag_clean(&binding->value);
next = binding->next;
- free(binding);
+ alloc_unmap(binding, sizeof(s_binding));
return next;
}
@@ -86,11 +86,11 @@ s_binding * binding_init (s_binding *binding, const s_sym *name,
s_binding * binding_new (const s_sym *name, s_binding *next)
{
s_binding *binding;
- binding = alloc(sizeof(s_binding));
+ binding = alloc_map(sizeof(s_binding));
if (! binding)
return NULL;
if (! binding_init(binding, name, next)) {
- free(binding);
+ alloc_unmap(binding, sizeof(s_binding));
return NULL;
}
return binding;
diff --git a/libkc3/buf.c b/libkc3/buf.c
index ca040d8..b3e69ca 100644
--- a/libkc3/buf.c
+++ b/libkc3/buf.c
@@ -185,14 +185,14 @@ void buf_clean (s_buf *buf)
rwlock_clean(&buf->rwlock);
#endif
if (buf->free)
- free(buf->ptr.p);
+ alloc_unmap(buf->ptr.p, buf->size + 1);
}
void buf_delete (s_buf *buf)
{
assert(buf);
buf_clean(buf);
- free(buf);
+ alloc_unmap(buf, sizeof(s_buf));
}
void buf_empty (s_buf *buf)
@@ -469,7 +469,7 @@ s_buf * buf_init_alloc (s_buf *buf, uw size)
assert(buf);
if (! size)
return buf_init(buf, false, 0, "");
- p = alloc(size + 1);
+ p = alloc_map(size + 1);
if (! p)
return NULL;
return buf_init(buf, true, size, p);
@@ -512,7 +512,7 @@ s_buf * buf_init_str_copy (s_buf *buf, const s_str *str)
s_buf * buf_new (bool p_free, uw size, char *p)
{
s_buf *buf;
- buf = alloc(sizeof(s_buf));
+ buf = alloc_map(sizeof(s_buf));
if (! buf)
return NULL;
buf_init(buf, p_free, size, p);
@@ -522,11 +522,11 @@ s_buf * buf_new (bool p_free, uw size, char *p)
s_buf * buf_new_alloc (uw size)
{
s_buf *buf;
- buf = alloc(sizeof(s_buf));
+ buf = alloc_map(sizeof(s_buf));
if (! buf)
return NULL;
if (! buf_init_alloc(buf, size)) {
- free(buf);
+ alloc_unmap(buf, sizeof(s_buf));
return NULL;
}
return buf;
@@ -791,7 +791,7 @@ s_str * buf_read (s_buf *buf, uw size, s_str *dest)
assert(! "buffer overflow");
goto clean;
}
- p = alloc(size);
+ p = alloc_map(size + 1);
if (! p)
goto clean;
str_init(&tmp, p, size, p);
diff --git a/libkc3/buf_inspect_u.c.in b/libkc3/buf_inspect_u.c.in
index 18bd5c1..41a1f94 100644
--- a/libkc3/buf_inspect_u.c.in
+++ b/libkc3/buf_inspect_u.c.in
@@ -45,6 +45,7 @@ sw buf_inspect_u_bits$_base (s_buf *buf,
const u_bits$ *u)
{
character *c;
+ uw c_size;
u8 digit;
sw i;
sw r;
@@ -61,7 +62,8 @@ sw buf_inspect_u_bits$_base (s_buf *buf,
return buf_write_character_utf8(buf, zero);
}
size = buf_inspect_u_bits$_base_digits(base, u);
- c = alloc(size * sizeof(character));
+ c_size = size * sizeof(character);
+ c = alloc_map(c_size);
buf_save_init(buf, &save);
radix = base->size;
i = 0;
@@ -84,7 +86,7 @@ sw buf_inspect_u_bits$_base (s_buf *buf,
restore:
buf_save_restore_wpos(buf, &save);
clean:
- free(c);
+ alloc_unmap(c, c_size);
buf_save_clean(buf, &save);
return r;
}
diff --git a/libkc3/buf_inspect_u16.c b/libkc3/buf_inspect_u16.c
index ae4b4d0..dc0cb4a 100644
--- a/libkc3/buf_inspect_u16.c
+++ b/libkc3/buf_inspect_u16.c
@@ -45,6 +45,7 @@ sw buf_inspect_u16_base (s_buf *buf,
const u16 *u)
{
character *c;
+ uw c_size;
u8 digit;
sw i;
sw r;
@@ -61,7 +62,8 @@ sw buf_inspect_u16_base (s_buf *buf,
return buf_write_character_utf8(buf, zero);
}
size = buf_inspect_u16_base_digits(base, u);
- c = alloc(size * sizeof(character));
+ c_size = size * sizeof(character);
+ c = alloc_map(c_size);
buf_save_init(buf, &save);
radix = base->size;
i = 0;
@@ -84,7 +86,7 @@ sw buf_inspect_u16_base (s_buf *buf,
restore:
buf_save_restore_wpos(buf, &save);
clean:
- free(c);
+ alloc_unmap(c, c_size);
buf_save_clean(buf, &save);
return r;
}
diff --git a/libkc3/buf_inspect_u32.c b/libkc3/buf_inspect_u32.c
index 048d4a2..9604e6e 100644
--- a/libkc3/buf_inspect_u32.c
+++ b/libkc3/buf_inspect_u32.c
@@ -45,6 +45,7 @@ sw buf_inspect_u32_base (s_buf *buf,
const u32 *u)
{
character *c;
+ uw c_size;
u8 digit;
sw i;
sw r;
@@ -61,7 +62,8 @@ sw buf_inspect_u32_base (s_buf *buf,
return buf_write_character_utf8(buf, zero);
}
size = buf_inspect_u32_base_digits(base, u);
- c = alloc(size * sizeof(character));
+ c_size = size * sizeof(character);
+ c = alloc_map(c_size);
buf_save_init(buf, &save);
radix = base->size;
i = 0;
@@ -84,7 +86,7 @@ sw buf_inspect_u32_base (s_buf *buf,
restore:
buf_save_restore_wpos(buf, &save);
clean:
- free(c);
+ alloc_unmap(c, c_size);
buf_save_clean(buf, &save);
return r;
}
diff --git a/libkc3/buf_inspect_u64.c b/libkc3/buf_inspect_u64.c
index b4f1c41..92d3d15 100644
--- a/libkc3/buf_inspect_u64.c
+++ b/libkc3/buf_inspect_u64.c
@@ -45,6 +45,7 @@ sw buf_inspect_u64_base (s_buf *buf,
const u64 *u)
{
character *c;
+ uw c_size;
u8 digit;
sw i;
sw r;
@@ -61,7 +62,8 @@ sw buf_inspect_u64_base (s_buf *buf,
return buf_write_character_utf8(buf, zero);
}
size = buf_inspect_u64_base_digits(base, u);
- c = alloc(size * sizeof(character));
+ c_size = size * sizeof(character);
+ c = alloc_map(c_size);
buf_save_init(buf, &save);
radix = base->size;
i = 0;
@@ -84,7 +86,7 @@ sw buf_inspect_u64_base (s_buf *buf,
restore:
buf_save_restore_wpos(buf, &save);
clean:
- free(c);
+ alloc_unmap(c, c_size);
buf_save_clean(buf, &save);
return r;
}
diff --git a/libkc3/buf_inspect_u8.c b/libkc3/buf_inspect_u8.c
index 3ff52fd..8906b08 100644
--- a/libkc3/buf_inspect_u8.c
+++ b/libkc3/buf_inspect_u8.c
@@ -45,6 +45,7 @@ sw buf_inspect_u8_base (s_buf *buf,
const u8 *u)
{
character *c;
+ uw c_size;
u8 digit;
sw i;
sw r;
@@ -61,7 +62,8 @@ sw buf_inspect_u8_base (s_buf *buf,
return buf_write_character_utf8(buf, zero);
}
size = buf_inspect_u8_base_digits(base, u);
- c = alloc(size * sizeof(character));
+ c_size = size * sizeof(character);
+ c = alloc_map(c_size);
buf_save_init(buf, &save);
radix = base->size;
i = 0;
@@ -84,7 +86,7 @@ sw buf_inspect_u8_base (s_buf *buf,
restore:
buf_save_restore_wpos(buf, &save);
clean:
- free(c);
+ alloc_unmap(c, c_size);
buf_save_clean(buf, &save);
return r;
}
diff --git a/libkc3/buf_inspect_uw.c b/libkc3/buf_inspect_uw.c
index 7515f2b..5b137b4 100644
--- a/libkc3/buf_inspect_uw.c
+++ b/libkc3/buf_inspect_uw.c
@@ -45,6 +45,7 @@ sw buf_inspect_uw_base (s_buf *buf,
const uw *u)
{
character *c;
+ uw c_size;
u8 digit;
sw i;
sw r;
@@ -61,7 +62,8 @@ sw buf_inspect_uw_base (s_buf *buf,
return buf_write_character_utf8(buf, zero);
}
size = buf_inspect_uw_base_digits(base, u);
- c = alloc(size * sizeof(character));
+ c_size = size * sizeof(character);
+ c = alloc_map(c_size);
buf_save_init(buf, &save);
radix = base->size;
i = 0;
@@ -84,7 +86,7 @@ sw buf_inspect_uw_base (s_buf *buf,
restore:
buf_save_restore_wpos(buf, &save);
clean:
- free(c);
+ alloc_unmap(c, c_size);
buf_save_clean(buf, &save);
return r;
}
diff --git a/libkc3/callable.c b/libkc3/callable.c
index 888c40f..50ebb1f 100644
--- a/libkc3/callable.c
+++ b/libkc3/callable.c
@@ -38,7 +38,7 @@ void callable_delete (s_callable *callable)
mutex_unlock(&callable->mutex);
mutex_clean(&callable->mutex);
#endif
- free(callable);
+ alloc_unmap(callable, sizeof(s_callable));
return;
clean:
#if HAVE_PTHREAD
@@ -50,7 +50,7 @@ void callable_delete (s_callable *callable)
s_callable * callable_new (void)
{
s_callable *callable;
- if (! (callable = alloc(sizeof(s_callable))))
+ if (! (callable = alloc_map(sizeof(s_callable))))
return NULL;
#if HAVE_PTHREAD
mutex_init(&callable->mutex);
@@ -79,7 +79,7 @@ s_callable * callable_new_copy (s_callable *src)
tmp->reference_count = 1;
return tmp;
ko:
- free(tmp);
+ alloc_unmap(tmp, sizeof(s_callable));
return NULL;
}
diff --git a/libkc3/cfn.c b/libkc3/cfn.c
index b404473..35eef0e 100644
--- a/libkc3/cfn.c
+++ b/libkc3/cfn.c
@@ -10,10 +10,10 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include "alloc.h"
-#include "assert.h"
#include <dlfcn.h>
#include <string.h>
+#include "alloc.h"
+#include "assert.h"
#include "cfn.h"
#include "list.h"
#include "mutex.h"
@@ -30,6 +30,7 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
s_list *a;
void **arg_pointer_result = NULL;
void **arg_pointers = NULL;
+ uw arg_size = 0;
void **arg_values = NULL;
void **result_pointer = NULL;
u8 arity;
@@ -76,12 +77,13 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
}
}
if (cfn->arity) {
- arg_pointers = alloc((cfn->arity + 1) * sizeof(void *));
+ arg_size = (cfn->arity + 1) * sizeof(void *);
+ arg_pointers = alloc_map(arg_size);
if (! arg_pointers)
return NULL;
- arg_values = alloc((cfn->arity + 1) * sizeof(void *));
+ arg_values = alloc_map(arg_size);
if (! arg_values) {
- free(arg_pointers);
+ alloc_unmap(arg_pointers, arg_size);
return NULL;
}
cfn_arg_types = cfn->arg_types;
@@ -161,12 +163,16 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
assert(! "cfn_apply: NULL function pointer");
tag_init_void(dest);
}
- free(arg_pointers);
- free(arg_values);
+ if (arg_size) {
+ alloc_unmap(arg_pointers, arg_size);
+ alloc_unmap(arg_values, arg_size);
+ }
return dest;
ko:
- free(arg_pointers);
- free(arg_values);
+ if (arg_size) {
+ alloc_unmap(arg_pointers, arg_size);
+ alloc_unmap(arg_values, arg_size);
+ }
return NULL;
}
@@ -187,7 +193,8 @@ void cfn_clean (s_cfn *cfn)
assert(cfn);
list_delete_all(cfn->arg_types);
if (cfn->cif.nargs)
- free(cfn->cif.arg_types);
+ alloc_unmap(cfn->cif.arg_types,
+ (cfn->arity + 1) * sizeof(ffi_type *));
#if HAVE_PTHREAD
mutex_clean(&cfn->mutex);
#endif
@@ -197,7 +204,7 @@ void cfn_delete (s_cfn *cfn)
{
assert(cfn);
cfn_clean(cfn);
- free(cfn);
+ alloc_unmap(cfn, sizeof(s_cfn));
}
bool cfn_eval (s_cfn *cfn)
@@ -285,7 +292,7 @@ s_cfn * cfn_init_copy (s_cfn *cfn, const s_cfn *src)
tmp.arity = src->arity;
tmp.cif = src->cif;
if (src->arity && src->cif.arg_types) {
- tmp.cif.arg_types = alloc((src->cif.nargs + 1) * sizeof(ffi_type *));
+ tmp.cif.arg_types = alloc_map((src->cif.nargs + 1) * sizeof(ffi_type *));
if (! tmp.cif.arg_types) {
list_delete_all(tmp.arg_types);
return NULL;
@@ -324,7 +331,7 @@ s_cfn * cfn_link (s_cfn *cfn)
s_cfn * cfn_new_copy (const s_cfn *src)
{
s_cfn *cfn;
- cfn = alloc(sizeof(s_cfn));
+ cfn = alloc_map(sizeof(s_cfn));
if (! cfn)
return NULL;
cfn_init_copy(cfn, src);
@@ -335,6 +342,7 @@ s_cfn * cfn_prep_cif (s_cfn *cfn)
{
s_list *a;
ffi_type **arg_ffi_type = NULL;
+ uw arg_size = 0;
u8 i = 0;
s_cfn *result = NULL;
ffi_type *result_ffi_type;
@@ -347,7 +355,8 @@ s_cfn * cfn_prep_cif (s_cfn *cfn)
if (! sym_to_ffi_type(cfn->result_type, NULL, &result_ffi_type))
goto clean;
if (cfn->arity) {
- arg_ffi_type = alloc((cfn->arity + 1) * sizeof(ffi_type *));
+ arg_size = (cfn->arity + 1) * sizeof(ffi_type *);
+ arg_ffi_type = alloc_map(arg_size);
if (! arg_ffi_type)
goto clean;
a = cfn->arg_types;
@@ -357,12 +366,12 @@ s_cfn * cfn_prep_cif (s_cfn *cfn)
err_write_1("cfn_prep_cif: invalid type: ");
err_puts(tag_type_to_string(a->tag.type));
assert(! "cfn_prep_cif: invalid type");
- free(arg_ffi_type);
+ alloc_unmap(arg_ffi_type, arg_size);
goto clean;
}
if (! sym_to_ffi_type(a->tag.data.sym, result_ffi_type,
arg_ffi_type + i)) {
- free(arg_ffi_type);
+ alloc_unmap(arg_ffi_type, arg_size);
goto clean;
}
if (a->tag.data.sym == &g_sym_Result) {
diff --git a/libkc3/compare.c b/libkc3/compare.c
index 29291bb..c8381b6 100644
--- a/libkc3/compare.c
+++ b/libkc3/compare.c
@@ -32,6 +32,53 @@
return 0; \
} \
+s8 compare_alloc (const s_alloc *a, const s_alloc *b)
+{
+ if (a == b)
+ return 0;
+ if (a < b)
+ return -1;
+ return 1;
+}
+
+s8 compare_alloc_mapped_size (const s_alloc *a, const s_alloc *b)
+{
+ if (a == b)
+ return 0;
+ if (! a)
+ return -1;
+ if (! b)
+ return 1;
+ if (a->mapped < b->mapped)
+ return -1;
+ if (a->mapped > b->mapped)
+ return 1;
+ if (a->size < b->size)
+ return -1;
+ if (a->size > b->size)
+ return 1;
+ return 0;
+}
+
+s8 compare_alloc_size_mapped (const s_alloc *a, const s_alloc *b)
+{
+ if (a == b)
+ return 0;
+ if (! a)
+ return -1;
+ if (! b)
+ return 1;
+ if (a->size < b->size)
+ return -1;
+ if (a->size > b->size)
+ return 1;
+ if (a->mapped < b->mapped)
+ return -1;
+ if (a->mapped > b->mapped)
+ return 1;
+ return 0;
+}
+
s8 compare_array (const s_array *a, const s_array *b)
{
uw i = 0;
diff --git a/libkc3/compare.h b/libkc3/compare.h
index 6a70b35..900844c 100644
--- a/libkc3/compare.h
+++ b/libkc3/compare.h
@@ -23,6 +23,7 @@
#define COMPARE_PROTOTYPE(type) \
s8 compare_##type (type a, type b)
+s8 compare_alloc (const s_alloc *a, const s_alloc *b);
s8 compare_array (const s_array *a, const s_array *b);
s8 compare_block (const s_block *a, const s_block *b);
s8 compare_bool (bool a, bool b);
diff --git a/libkc3/complex.c b/libkc3/complex.c
index 1ecd554..0dbd7b2 100644
--- a/libkc3/complex.c
+++ b/libkc3/complex.c
@@ -66,7 +66,7 @@ void complex_delete (s_complex *c)
{
assert(c);
complex_clean(c);
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
}
s_complex * complex_div (s_complex *a, s_complex *b,
@@ -220,11 +220,11 @@ s_complex * complex_mul (s_complex *a, s_complex *b,
s_complex * complex_new (void)
{
s_complex *c;
- c = alloc(sizeof(s_complex));
+ c = alloc_map(sizeof(s_complex));
if (! c)
return NULL;
if (! complex_init(c)) {
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
return c;
@@ -233,11 +233,11 @@ s_complex * complex_new (void)
s_complex * complex_new_add (s_complex *a, s_complex *b)
{
s_complex *c;
- c = alloc(sizeof(s_complex));
+ c = alloc_map(sizeof(s_complex));
if (! c)
return NULL;
if (! complex_add(a, b, c)) {
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
return c;
@@ -248,11 +248,11 @@ s_complex * complex_new_cast (const s_sym * const *type,
{
s_complex *c;
assert(src);
- c = alloc(sizeof(s_complex));
+ c = alloc_map(sizeof(s_complex));
if (! c)
return NULL;
if (! complex_init_cast(c, type, src)) {
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
return c;
@@ -261,11 +261,11 @@ s_complex * complex_new_cast (const s_sym * const *type,
s_complex * complex_new_div (s_complex *a, s_complex *b)
{
s_complex *c;
- c = alloc(sizeof(s_complex));
+ c = alloc_map(sizeof(s_complex));
if (! c)
return NULL;
if (! complex_div(a, b, c)) {
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
return c;
@@ -274,11 +274,11 @@ s_complex * complex_new_div (s_complex *a, s_complex *b)
s_complex * complex_new_mul (s_complex *a, s_complex *b)
{
s_complex *c;
- c = alloc(sizeof(s_complex));
+ c = alloc_map(sizeof(s_complex));
if (! c)
return NULL;
if (! complex_mul(a, b, c)) {
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
return c;
@@ -287,11 +287,11 @@ s_complex * complex_new_mul (s_complex *a, s_complex *b)
s_complex * complex_new_sub (s_complex *a, s_complex *b)
{
s_complex *c;
- c = alloc(sizeof(s_complex));
+ c = alloc_map(sizeof(s_complex));
if (! c)
return NULL;
if (! complex_sub(a, b, c)) {
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
return c;
@@ -301,11 +301,11 @@ s_complex * complex_new_copy (s_complex *src)
{
s_complex *c;
assert(src);
- c = alloc(sizeof(s_complex));
+ c = alloc_map(sizeof(s_complex));
if (! c)
return NULL;
if (! complex_init_copy(c, src)) {
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
return c;
diff --git a/libkc3/env.c b/libkc3/env.c
index 20844bb..ea7124c 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -253,6 +253,7 @@ void env_clean (s_env *env)
str_delete(env->module_path);
list_delete_all(env->path);
list_delete_all(env->search_modules_default);
+ alloc_clean();
}
void env_clean_globals (s_env *env)
@@ -2670,6 +2671,8 @@ s_ident * env_ident_resolve_module (s_env *env,
s_env * env_init (s_env *env, int *argc, char ***argv)
{
s_str path;
+ sym_init_g_sym();
+ alloc_init();
if (! env)
env = g_kc3_env;
if (! env)
@@ -2679,7 +2682,6 @@ s_env * env_init (s_env *env, int *argc, char ***argv)
env->trace = false;
if (! env_init_args(env, argc, argv))
return NULL;
- sym_init_g_sym();
env->error_handler = NULL;
if (! env_init_toplevel(env))
return NULL;
@@ -2730,8 +2732,8 @@ s_env * env_init_args (s_env *env, int *argc, char ***argv)
s_str argv0;
assert(env);
if (argc && argv && *argc && *argv) {
- (*argc)--;
- (*argv)++;
+ env->argc = (*argc)--;
+ env->argv = (*argv)++;
str_init_1(&argv0, NULL, env->argv[0]);
if (! (env->argv0_dir = alloc(sizeof(s_str))))
return NULL;
@@ -2744,8 +2746,6 @@ s_env * env_init_args (s_env *env, int *argc, char ***argv)
(*argv)++;
}
}
- env->argc = *argc;
- env->argv = *argv;
return env;
}
env->argc = 0;
diff --git a/libkc3/env_fork.c b/libkc3/env_fork.c
index ba4e8dd..f3c81e0 100644
--- a/libkc3/env_fork.c
+++ b/libkc3/env_fork.c
@@ -31,7 +31,7 @@ void env_fork_delete (s_env *env)
{
assert(env);
env_fork_clean(env);
- free(env);
+ alloc_unmap(env, sizeof(s_env));
}
s_env * env_fork_init (s_env *env, s_env *src)
@@ -68,10 +68,10 @@ s_env * env_fork_init (s_env *env, s_env *src)
s_env * env_fork_new (s_env *src)
{
s_env *env;
- if (! (env = alloc(sizeof(s_env))))
+ if (! (env = alloc_map(sizeof(s_env))))
return NULL;
if (! env_fork_init(env, src)) {
- free(env);
+ alloc_unmap(env, sizeof(s_env));
return NULL;
}
return env;
diff --git a/libkc3/error_handler.c b/libkc3/error_handler.c
index e1fe103..bee411f 100644
--- a/libkc3/error_handler.c
+++ b/libkc3/error_handler.c
@@ -26,7 +26,7 @@ s_error_handler * error_handler_delete (s_error_handler *error_handler)
assert(error_handler);
next = error_handler->next;
error_handler_clean(error_handler);
- free(error_handler);
+ alloc_unmap(error_handler, sizeof(s_error_handler));
return next;
}
@@ -48,7 +48,7 @@ error_handler_init (s_error_handler *error_handler,
s_error_handler * error_handler_new (s_error_handler *next)
{
s_error_handler *error_handler;
- error_handler = alloc(sizeof(s_error_handler));
+ error_handler = alloc_map(sizeof(s_error_handler));
if (! error_handler)
return NULL;
return error_handler_init(error_handler, next);
diff --git a/libkc3/fact_list.c b/libkc3/fact_list.c
index 58a45a2..c076ad3 100644
--- a/libkc3/fact_list.c
+++ b/libkc3/fact_list.c
@@ -19,7 +19,7 @@ s_fact_list * fact_list_delete (s_fact_list *fl)
s_fact_list *next;
assert(fl);
next = fl->next;
- free(fl);
+ alloc_unmap(fl, sizeof(s_fact_list));
return next;
}
@@ -44,11 +44,11 @@ s_fact_list * fact_list_init (s_fact_list *fl, s_fact *fact,
s_fact_list * fact_list_new (s_fact *fact, s_fact_list *next)
{
s_fact_list *fl;
- fl = alloc(sizeof(s_fact_list));
+ fl = alloc_map(sizeof(s_fact_list));
if (! fl)
return NULL;
if (! fact_list_init(fl, fact, next)) {
- free(fl);
+ alloc_unmap(fl, sizeof(s_fact_list));
return NULL;
}
return fl;
diff --git a/libkc3/file.c b/libkc3/file.c
index 860e4a5..e5db2ea 100644
--- a/libkc3/file.c
+++ b/libkc3/file.c
@@ -314,7 +314,7 @@ s_str * file_pwd (s_str *dest)
if (! getcwd(buf, sizeof(buf)))
return NULL;
size = strlen(buf);
- pchar = calloc(1, size + 1);
+ pchar = alloc_map(size + 1);
memcpy(pchar, buf, size);
str_init(dest, pchar, size, pchar);
return dest;
diff --git a/libkc3/fn.c b/libkc3/fn.c
index 06128b9..75f1d6d 100644
--- a/libkc3/fn.c
+++ b/libkc3/fn.c
@@ -13,7 +13,6 @@
#include <string.h>
#include "alloc.h"
#include "assert.h"
-#include "arg.h"
#include "binding.h"
#include "buf.h"
#include "buf_parse.h"
diff --git a/libkc3/fn_clause.c b/libkc3/fn_clause.c
index b210a5a..5824652 100644
--- a/libkc3/fn_clause.c
+++ b/libkc3/fn_clause.c
@@ -12,7 +12,6 @@
*/
#include "alloc.h"
#include "assert.h"
-#include "arg.h"
#include "binding.h"
#include "block.h"
#include "fn_clause.h"
@@ -31,7 +30,7 @@ s_fn_clause * fn_clause_delete (s_fn_clause *fn_clause)
assert(fn_clause);
next_clause = fn_clause->next_clause;
fn_clause_clean(fn_clause);
- free(fn_clause);
+ alloc_unmap(fn_clause, sizeof(s_fn_clause));
return next_clause;
}
@@ -53,7 +52,7 @@ s_fn_clause * fn_clause_init (s_fn_clause *fn_clause, s_fn_clause *next_clause)
s_fn_clause * fn_clause_new (s_fn_clause *next_clause)
{
s_fn_clause *fn_clause;
- fn_clause = alloc(sizeof(s_fn_clause));
+ fn_clause = alloc_map(sizeof(s_fn_clause));
if (! fn_clause)
return NULL;
return fn_clause_init(fn_clause, next_clause);
diff --git a/libkc3/frame.c b/libkc3/frame.c
index c046d88..bc8e318 100644
--- a/libkc3/frame.c
+++ b/libkc3/frame.c
@@ -124,7 +124,7 @@ s_frame * frame_delete (s_frame *frame)
s_frame *next = NULL;
if (frame) {
next = frame_clean(frame);
- free(frame);
+ alloc_unmap(frame, sizeof(s_frame));
}
return next;
}
@@ -199,11 +199,11 @@ s_frame * frame_init (s_frame *frame, s_frame *next,
s_frame * frame_new (s_frame *next, const s_frame *fn_frame)
{
s_frame *frame;
- frame = alloc(sizeof(s_frame));
+ frame = alloc_map(sizeof(s_frame));
if (! frame)
return NULL;
if (! frame_init(frame, next, fn_frame)) {
- free(frame);
+ alloc_unmap(frame, sizeof(s_frame));
return NULL;
}
return frame;
diff --git a/libkc3/kc3.h b/libkc3/kc3.h
index d53c154..bd9a8e9 100644
--- a/libkc3/kc3.h
+++ b/libkc3/kc3.h
@@ -15,7 +15,6 @@
#include "alist.h"
#include "alloc.h"
-#include "arg.h"
#include "array.h"
#include "assert.h"
#include "block.h"
diff --git a/libkc3/list.c b/libkc3/list.c
index 4f7fb0b..55ccc43 100644
--- a/libkc3/list.c
+++ b/libkc3/list.c
@@ -85,7 +85,7 @@ s_list * list_delete (s_list *list)
if (list) {
next = list_next(list);
list_clean(list);
- free(list);
+ alloc_unmap(list, sizeof(s_list));
}
return next;
}
@@ -363,7 +363,7 @@ s_list * list_next (const s_list *list)
s_list * list_new (s_list *next)
{
s_list *dest;
- dest = alloc(sizeof(s_list));
+ dest = alloc_map(sizeof(s_list));
if (! dest)
return NULL;
return list_init(dest, next);
@@ -415,11 +415,11 @@ s_list * list_new_copy (s_list *src)
s_list * list_new_list (s_list *x, s_list *next)
{
s_list *dest;
- if ((dest = list_new(next))) {
- if (! tag_init_list(&dest->tag, x)) {
- free(dest);
- return NULL;
- }
+ if (! (dest = list_new(next)))
+ return NULL;
+ if (! tag_init_list(&dest->tag, x)) {
+ list_delete(dest);
+ return NULL;
}
return dest;
}
@@ -431,7 +431,7 @@ s_list * list_new_tag_copy (s_tag *x, s_list *next)
if (! dest)
return NULL;
if (! tag_init_copy(&dest->tag, x)) {
- free(dest);
+ list_delete(dest);
return NULL;
}
return dest;
diff --git a/libkc3/mutex.c b/libkc3/mutex.c
index 6b933cc..fc6cc06 100644
--- a/libkc3/mutex.c
+++ b/libkc3/mutex.c
@@ -28,7 +28,7 @@ void mutex_delete (s_mutex *mutex)
{
assert(mutex);
mutex_clean(mutex);
- free(mutex);
+ alloc_unmap(mutex, sizeof(s_mutex));
}
s_mutex * mutex_init (s_mutex *mutex)
@@ -57,10 +57,10 @@ void mutex_lock (s_mutex *mutex)
s_mutex * mutex_new (void)
{
s_mutex *mutex;
- if (! (mutex = alloc(sizeof(s_mutex))))
+ if (! (mutex = alloc_map(sizeof(s_mutex))))
return NULL;
if (! mutex_init(mutex)) {
- free(mutex);
+ alloc_unmap(mutex, sizeof(s_mutex));
return NULL;
}
return mutex;
diff --git a/libkc3/ptr.c b/libkc3/ptr.c
index 91353b4..fc23630 100644
--- a/libkc3/ptr.c
+++ b/libkc3/ptr.c
@@ -20,7 +20,7 @@
void ptr_delete (u_ptr_w *ptr)
{
assert(ptr);
- free(ptr);
+ alloc_unmap(ptr, sizeof(u_ptr_w));
}
u_ptr_w * ptr_init (u_ptr_w *ptr, void *p)
@@ -84,11 +84,11 @@ u_ptr_w * ptr_init_copy (u_ptr_w *ptr, const u_ptr_w *src)
u_ptr_w * ptr_new (void *p)
{
u_ptr_w *ptr;
- ptr = alloc(sizeof(u_ptr_w));
+ ptr = alloc_map(sizeof(u_ptr_w));
if (! ptr)
return NULL;
if (! ptr_init(ptr, p)) {
- free(ptr);
+ alloc_unmap(ptr, sizeof(u_ptr_w));
return NULL;
}
return ptr;
@@ -98,11 +98,11 @@ u_ptr_w * ptr_new_copy (const u_ptr_w *src)
{
u_ptr_w *ptr;
assert(src);
- ptr = alloc(sizeof(u_ptr_w));
+ ptr = alloc_map(sizeof(u_ptr_w));
if (! ptr)
return NULL;
if (! ptr_init_copy(ptr, src)) {
- free(ptr);
+ alloc_unmap(ptr, sizeof(u_ptr_w));
return NULL;
}
return ptr;
diff --git a/libkc3/ptr_free.c b/libkc3/ptr_free.c
index 3c89aec..f04e442 100644
--- a/libkc3/ptr_free.c
+++ b/libkc3/ptr_free.c
@@ -20,14 +20,14 @@
void ptr_free_clean (u_ptr_w *ptr_free)
{
assert(ptr_free);
- free(ptr_free->p);
+ alloc_free(ptr_free->p);
}
void ptr_free_delete (u_ptr_w *ptr_free)
{
assert(ptr_free);
ptr_free_clean(ptr_free);
- free(ptr_free);
+ alloc_unmap(ptr_free, sizeof(u_ptr_w));
}
u_ptr_w * ptr_free_init (u_ptr_w *ptr_free, void *p)
@@ -91,11 +91,11 @@ u_ptr_w * ptr_free_init_copy (u_ptr_w *ptr_free, const u_ptr_w *src)
u_ptr_w * ptr_free_new (void *p)
{
u_ptr_w *ptr_free;
- ptr_free = alloc(sizeof(u_ptr_w));
+ ptr_free = alloc_map(sizeof(u_ptr_w));
if (! ptr_free)
return NULL;
if (! ptr_free_init(ptr_free, p)) {
- free(ptr_free);
+ alloc_unmap(ptr_free, sizeof(u_ptr_w));
return NULL;
}
return ptr_free;
@@ -105,11 +105,11 @@ u_ptr_w * ptr_free_new_copy (const u_ptr_w *src)
{
u_ptr_w *ptr_free;
assert(src);
- ptr_free = alloc(sizeof(u_ptr_w));
+ ptr_free = alloc_map(sizeof(u_ptr_w));
if (! ptr_free)
return NULL;
if (! ptr_free_init_copy(ptr_free, src)) {
- free(ptr_free);
+ alloc_unmap(ptr_free, sizeof(u_ptr_w));
return NULL;
}
return ptr_free;
diff --git a/libkc3/set.c.in b/libkc3/set.c.in
index 9ffb5ac..1d9baf5 100644
--- a/libkc3/set.c.in
+++ b/libkc3/set.c.in
@@ -73,7 +73,7 @@ set_clean___NAME$ (s_set___NAME$ *set)
for (i = 0; i < set->max; i++) {
set_item_delete_all___NAME$(set->items[i]);
}
- free(set->items);
+ alloc_unmap(set->items, set->max * sizeof(s_set_item___NAME$ *));
}
s_set_item___NAME$ *
@@ -133,7 +133,7 @@ set_init___NAME$ (s_set___NAME$ *set, uw max)
assert(set);
assert(max > 0);
tmp.max = max;
- tmp.items = alloc(max * sizeof(s_set_item___NAME$ *));
+ tmp.items = alloc_map(max * sizeof(s_set_item___NAME$ *));
if (! tmp.items)
return NULL;
tmp.count = 0;
diff --git a/libkc3/set__fact.c b/libkc3/set__fact.c
index b8de22b..b169786 100644
--- a/libkc3/set__fact.c
+++ b/libkc3/set__fact.c
@@ -73,7 +73,7 @@ set_clean__fact (s_set__fact *set)
for (i = 0; i < set->max; i++) {
set_item_delete_all__fact(set->items[i]);
}
- free(set->items);
+ alloc_unmap(set->items, set->max * sizeof(s_set_item__fact *));
}
s_set_item__fact *
@@ -133,7 +133,7 @@ set_init__fact (s_set__fact *set, uw max)
assert(set);
assert(max > 0);
tmp.max = max;
- tmp.items = alloc(max * sizeof(s_set_item__fact *));
+ tmp.items = alloc_map(max * sizeof(s_set_item__fact *));
if (! tmp.items)
return NULL;
tmp.count = 0;
diff --git a/libkc3/set__tag.c b/libkc3/set__tag.c
index 7f515ab..ac452e3 100644
--- a/libkc3/set__tag.c
+++ b/libkc3/set__tag.c
@@ -73,7 +73,7 @@ set_clean__tag (s_set__tag *set)
for (i = 0; i < set->max; i++) {
set_item_delete_all__tag(set->items[i]);
}
- free(set->items);
+ alloc_unmap(set->items, set->max * sizeof(s_set_item__tag *));
}
s_set_item__tag *
@@ -133,7 +133,7 @@ set_init__tag (s_set__tag *set, uw max)
assert(set);
assert(max > 0);
tmp.max = max;
- tmp.items = alloc(max * sizeof(s_set_item__tag *));
+ tmp.items = alloc_map(max * sizeof(s_set_item__tag *));
if (! tmp.items)
return NULL;
tmp.count = 0;
diff --git a/libkc3/set_item.c.in b/libkc3/set_item.c.in
index 643b786..aca0782 100644
--- a/libkc3/set_item.c.in
+++ b/libkc3/set_item.c.in
@@ -20,11 +20,11 @@ s_set_item___NAME$ *
set_item_new___NAME$ (_TYPE$ *data, uw hash, s_set_item___NAME$ *next)
{
s_set_item___NAME$ *item;
- item = alloc(sizeof(s_set_item___NAME$));
+ item = alloc_map(sizeof(s_set_item___NAME$));
if (! item)
return NULL;
if (! _NAME$_init_copy(&item->data, data)) {
- free(item);
+ alloc_unmap(item, sizeof(s_set_item___NAME$));
return NULL;
}
item->hash = hash;
@@ -37,7 +37,7 @@ void set_item_delete___NAME$ (s_set_item___NAME$ *x)
{
assert(x);
_NAME$_clean(&x->data);
- free(x);
+ alloc_unmap(x, sizeof(s_set_item___NAME$));
}
void set_item_delete_all___NAME$ (s_set_item___NAME$ *x)
diff --git a/libkc3/set_item__fact.c b/libkc3/set_item__fact.c
index 11246f7..f158b7c 100644
--- a/libkc3/set_item__fact.c
+++ b/libkc3/set_item__fact.c
@@ -20,11 +20,11 @@ s_set_item__fact *
set_item_new__fact (s_fact *data, uw hash, s_set_item__fact *next)
{
s_set_item__fact *item;
- item = alloc(sizeof(s_set_item__fact));
+ item = alloc_map(sizeof(s_set_item__fact));
if (! item)
return NULL;
if (! fact_init_copy(&item->data, data)) {
- free(item);
+ alloc_unmap(item, sizeof(s_set_item__fact));
return NULL;
}
item->hash = hash;
@@ -37,7 +37,7 @@ void set_item_delete__fact (s_set_item__fact *x)
{
assert(x);
fact_clean(&x->data);
- free(x);
+ alloc_unmap(x, sizeof(s_set_item__fact));
}
void set_item_delete_all__fact (s_set_item__fact *x)
diff --git a/libkc3/set_item__tag.c b/libkc3/set_item__tag.c
index 3da0cdc..4361fd0 100644
--- a/libkc3/set_item__tag.c
+++ b/libkc3/set_item__tag.c
@@ -20,11 +20,11 @@ s_set_item__tag *
set_item_new__tag (s_tag *data, uw hash, s_set_item__tag *next)
{
s_set_item__tag *item;
- item = alloc(sizeof(s_set_item__tag));
+ item = alloc_map(sizeof(s_set_item__tag));
if (! item)
return NULL;
if (! tag_init_copy(&item->data, data)) {
- free(item);
+ alloc_unmap(item, sizeof(s_set_item__tag));
return NULL;
}
item->hash = hash;
@@ -37,7 +37,7 @@ void set_item_delete__tag (s_set_item__tag *x)
{
assert(x);
tag_clean(&x->data);
- free(x);
+ alloc_unmap(x, sizeof(s_set_item__tag));
}
void set_item_delete_all__tag (s_set_item__tag *x)
diff --git a/libkc3/skiplist.c.in b/libkc3/skiplist.c.in
index 28488af..d808a5d 100644
--- a/libkc3/skiplist.c.in
+++ b/libkc3/skiplist.c.in
@@ -73,9 +73,11 @@ skiplist_clean___NAME$ (s_skiplist___NAME$ *skiplist)
void
skiplist_delete___NAME$ (s_skiplist___NAME$ *skiplist)
{
+ uw size;
assert(skiplist);
+ size = SKIPLIST_SIZE___NAME$(skiplist->max_height);
skiplist_clean___NAME$(skiplist);
- free(skiplist);
+ alloc_unmap(skiplist, size);
}
s_skiplist_node___NAME$ *
@@ -150,11 +152,13 @@ s_skiplist___NAME$ *
skiplist_new___NAME$ (u8 max_height, f64 spacing)
{
s_skiplist___NAME$ *skiplist;
- skiplist = alloc(SKIPLIST_SIZE___NAME$(max_height));
+ uw size;
+ size = SKIPLIST_SIZE___NAME$(max_height);
+ skiplist = alloc_map(size);
if (! skiplist)
return NULL;
if (! skiplist_init___NAME$(skiplist, max_height, spacing)) {
- free(skiplist);
+ alloc_unmap(skiplist, size);
return NULL;
}
return skiplist;
diff --git a/libkc3/skiplist__alloc.c b/libkc3/skiplist__alloc.c
index 74f1b95..431ff96 100644
--- a/libkc3/skiplist__alloc.c
+++ b/libkc3/skiplist__alloc.c
@@ -73,9 +73,11 @@ skiplist_clean__alloc (s_skiplist__alloc *skiplist)
void
skiplist_delete__alloc (s_skiplist__alloc *skiplist)
{
+ uw size;
assert(skiplist);
+ size = SKIPLIST_SIZE__alloc(skiplist->max_height);
skiplist_clean__alloc(skiplist);
- free(skiplist);
+ alloc_unmap(skiplist, size);
}
s_skiplist_node__alloc *
@@ -150,11 +152,13 @@ s_skiplist__alloc *
skiplist_new__alloc (u8 max_height, f64 spacing)
{
s_skiplist__alloc *skiplist;
- skiplist = alloc(SKIPLIST_SIZE__alloc(max_height));
+ uw size;
+ size = SKIPLIST_SIZE__alloc(max_height);
+ skiplist = alloc_map(size);
if (! skiplist)
return NULL;
if (! skiplist_init__alloc(skiplist, max_height, spacing)) {
- free(skiplist);
+ alloc_unmap(skiplist, size);
return NULL;
}
return skiplist;
diff --git a/libkc3/skiplist__fact.c b/libkc3/skiplist__fact.c
index 4f0272c..5ec7a5f 100644
--- a/libkc3/skiplist__fact.c
+++ b/libkc3/skiplist__fact.c
@@ -73,9 +73,11 @@ skiplist_clean__fact (s_skiplist__fact *skiplist)
void
skiplist_delete__fact (s_skiplist__fact *skiplist)
{
+ uw size;
assert(skiplist);
+ size = SKIPLIST_SIZE__fact(skiplist->max_height);
skiplist_clean__fact(skiplist);
- free(skiplist);
+ alloc_unmap(skiplist, size);
}
s_skiplist_node__fact *
@@ -150,11 +152,13 @@ s_skiplist__fact *
skiplist_new__fact (u8 max_height, f64 spacing)
{
s_skiplist__fact *skiplist;
- skiplist = alloc(SKIPLIST_SIZE__fact(max_height));
+ uw size;
+ size = SKIPLIST_SIZE__fact(max_height);
+ skiplist = alloc_map(size);
if (! skiplist)
return NULL;
if (! skiplist_init__fact(skiplist, max_height, spacing)) {
- free(skiplist);
+ alloc_unmap(skiplist, size);
return NULL;
}
return skiplist;
diff --git a/libkc3/skiplist_node.c.in b/libkc3/skiplist_node.c.in
index 5091497..de5ef93 100644
--- a/libkc3/skiplist_node.c.in
+++ b/libkc3/skiplist_node.c.in
@@ -13,10 +13,11 @@
/* Gen from skiplist_node.c.in NAME=_NAME$ TYPE=_TYPE$ */
#include <string.h>
#include "alloc.h"
+#include "assert.h"
#include "skiplist_node___NAME$.h"
s_skiplist_node___NAME$ *
-skiplist_node_init (s_skiplist_node___NAME$ *node, _TYPE$ _NAME$, u8 height)
+skiplist_node_init___NAME$ (s_skiplist_node___NAME$ *node, _TYPE$ _NAME$, u8 height)
{
node->_NAME$ = _NAME$;
node->height = height;
@@ -29,17 +30,18 @@ s_skiplist_node___NAME$ *
skiplist_node_new___NAME$ (_TYPE$ _NAME$, u8 height)
{
s_skiplist_node___NAME$ *node;
- node = alloc(SKIPLIST_NODE_SIZE___NAME$(height));
+ node = alloc_map(SKIPLIST_NODE_SIZE___NAME$(height));
if (! node)
return NULL;
- skiplist_node_init(node, _NAME$, height);
+ skiplist_node_init___NAME$(node, _NAME$, height);
return node;
}
void
skiplist_node_delete___NAME$ (s_skiplist_node___NAME$ *node)
{
- free(node);
+ assert(node);
+ alloc_unmap(node, SKIPLIST_NODE_SIZE___NAME$(node->height));
}
void
diff --git a/libkc3/skiplist_node.h.in b/libkc3/skiplist_node.h.in
index 554e149..dc7ebcb 100644
--- a/libkc3/skiplist_node.h.in
+++ b/libkc3/skiplist_node.h.in
@@ -32,7 +32,7 @@
(sizeof(s_skiplist_node___NAME$) + (height) * sizeof(_TYPE$))
s_skiplist_node___NAME$ *
-skiplist_node_init (s_skiplist_node___NAME$ *node, _TYPE$ value, u8 height);
+skiplist_node_init___NAME$ (s_skiplist_node___NAME$ *node, _TYPE$ value, u8 height);
s_skiplist_node___NAME$ *
skiplist_node_new___NAME$ (_TYPE$ value, u8 height);
diff --git a/libkc3/skiplist_node__alloc.c b/libkc3/skiplist_node__alloc.c
index 65f2489..8b77f56 100644
--- a/libkc3/skiplist_node__alloc.c
+++ b/libkc3/skiplist_node__alloc.c
@@ -13,10 +13,11 @@
/* Gen from skiplist_node.c.in NAME=alloc TYPE=s_alloc * */
#include <string.h>
#include "alloc.h"
+#include "assert.h"
#include "skiplist_node__alloc.h"
s_skiplist_node__alloc *
-skiplist_node_init (s_skiplist_node__alloc *node, s_alloc * alloc, u8 height)
+skiplist_node_init__alloc (s_skiplist_node__alloc *node, s_alloc * alloc, u8 height)
{
node->alloc = alloc;
node->height = height;
@@ -29,17 +30,18 @@ s_skiplist_node__alloc *
skiplist_node_new__alloc (s_alloc * alloc, u8 height)
{
s_skiplist_node__alloc *node;
- node = alloc(SKIPLIST_NODE_SIZE__alloc(height));
+ node = alloc_map(SKIPLIST_NODE_SIZE__alloc(height));
if (! node)
return NULL;
- skiplist_node_init(node, alloc, height);
+ skiplist_node_init__alloc(node, alloc, height);
return node;
}
void
skiplist_node_delete__alloc (s_skiplist_node__alloc *node)
{
- free(node);
+ assert(node);
+ alloc_unmap(node, SKIPLIST_NODE_SIZE__alloc(node->height));
}
void
diff --git a/libkc3/skiplist_node__alloc.h b/libkc3/skiplist_node__alloc.h
index 4cdff88..c472af3 100644
--- a/libkc3/skiplist_node__alloc.h
+++ b/libkc3/skiplist_node__alloc.h
@@ -32,7 +32,7 @@
(sizeof(s_skiplist_node__alloc) + (height) * sizeof(s_alloc *))
s_skiplist_node__alloc *
-skiplist_node_init (s_skiplist_node__alloc *node, s_alloc * value, u8 height);
+skiplist_node_init__alloc (s_skiplist_node__alloc *node, s_alloc * value, u8 height);
s_skiplist_node__alloc *
skiplist_node_new__alloc (s_alloc * value, u8 height);
diff --git a/libkc3/skiplist_node__fact.c b/libkc3/skiplist_node__fact.c
index 363f3d8..5667257 100644
--- a/libkc3/skiplist_node__fact.c
+++ b/libkc3/skiplist_node__fact.c
@@ -13,10 +13,11 @@
/* Gen from skiplist_node.c.in NAME=fact TYPE=s_fact * */
#include <string.h>
#include "alloc.h"
+#include "assert.h"
#include "skiplist_node__fact.h"
s_skiplist_node__fact *
-skiplist_node_init (s_skiplist_node__fact *node, s_fact * fact, u8 height)
+skiplist_node_init__fact (s_skiplist_node__fact *node, s_fact * fact, u8 height)
{
node->fact = fact;
node->height = height;
@@ -29,17 +30,18 @@ s_skiplist_node__fact *
skiplist_node_new__fact (s_fact * fact, u8 height)
{
s_skiplist_node__fact *node;
- node = alloc(SKIPLIST_NODE_SIZE__fact(height));
+ node = alloc_map(SKIPLIST_NODE_SIZE__fact(height));
if (! node)
return NULL;
- skiplist_node_init(node, fact, height);
+ skiplist_node_init__fact(node, fact, height);
return node;
}
void
skiplist_node_delete__fact (s_skiplist_node__fact *node)
{
- free(node);
+ assert(node);
+ alloc_unmap(node, SKIPLIST_NODE_SIZE__fact(node->height));
}
void
diff --git a/libkc3/skiplist_node__fact.h b/libkc3/skiplist_node__fact.h
index 4436fd7..ceda4cc 100644
--- a/libkc3/skiplist_node__fact.h
+++ b/libkc3/skiplist_node__fact.h
@@ -32,7 +32,7 @@
(sizeof(s_skiplist_node__fact) + (height) * sizeof(s_fact *))
s_skiplist_node__fact *
-skiplist_node_init (s_skiplist_node__fact *node, s_fact * value, u8 height);
+skiplist_node_init__fact (s_skiplist_node__fact *node, s_fact * value, u8 height);
s_skiplist_node__fact *
skiplist_node_new__fact (s_fact * value, u8 height);
diff --git a/libkc3/sources.mk b/libkc3/sources.mk
index 33a97fe..5d4d750 100644
--- a/libkc3/sources.mk
+++ b/libkc3/sources.mk
@@ -3,7 +3,6 @@ HEADERS = \
"abs.h" \
"alist.h" \
"alloc.h" \
- "arg.h" \
"array.h" \
"assert.h" \
"binding.h" \
@@ -186,7 +185,6 @@ SOURCES = \
"abs.c" \
"alist.c" \
"alloc.c" \
- "arg.c" \
"array.c" \
"binding.c" \
"block.c" \
@@ -477,7 +475,6 @@ LO_SOURCES = \
"abs.c" \
"alist.c" \
"alloc.c" \
- "arg.c" \
"array.c" \
"binding.c" \
"block.c" \
diff --git a/libkc3/sources.sh b/libkc3/sources.sh
index 3e3fe1b..412ad92 100644
--- a/libkc3/sources.sh
+++ b/libkc3/sources.sh
@@ -1,4 +1,4 @@
# sources.sh generated by update_sources
-HEADERS='abs.h alist.h alloc.h arg.h array.h assert.h binding.h block.h bool.h buf.h buf_fd.h buf_file.h buf_getc.h buf_getchar.h buf_inspect.h buf_inspect_s16.h buf_inspect_s16_binary.h buf_inspect_s16_decimal.h buf_inspect_s16_hexadecimal.h buf_inspect_s16_octal.h buf_inspect_s32.h buf_inspect_s32_binary.h buf_inspect_s32_decimal.h buf_inspect_s32_hexadecimal.h buf_inspect_s32_octal.h buf_inspect_s64.h buf_inspect_s64_binary.h buf_inspect_s64_decimal.h buf_inspect_s64_hexadecimal.h buf_inspect_s64_octal.h buf_inspect_s8.h buf_inspect_s8_binary.h buf_inspect_s8_decimal.h buf_inspect_s8_hexadecimal.h buf_inspect_s8_octal.h buf_inspect_sw.h buf_inspect_sw_binary.h buf_inspect_sw_decimal.h buf_inspect_sw_hexadecimal.h buf_inspect_sw_octal.h buf_inspect_u16.h buf_inspect_u16_binary.h buf_inspect_u16_decimal.h buf_inspect_u16_hexadecimal.h buf_inspect_u16_octal.h buf_inspect_u32.h buf_inspect_u32_binary.h buf_inspect_u32_decimal.h buf_inspect_u32_hexadecimal.h buf_inspect_u32_octal.h buf_inspect_u64.h buf_inspect_u64_binary.h buf_inspect_u64_decimal.h buf_inspect_u64_hexadecimal.h buf_inspect_u64_octal.h buf_inspect_u8.h buf_inspect_u8_binary.h buf_inspect_u8_decimal.h buf_inspect_u8_hexadecimal.h buf_inspect_u8_octal.h buf_inspect_uw.h buf_inspect_uw_binary.h buf_inspect_uw_decimal.h buf_inspect_uw_hexadecimal.h buf_inspect_uw_octal.h buf_parse.h buf_parse_s16.h buf_parse_s32.h buf_parse_s64.h buf_parse_s8.h buf_parse_sw.h buf_parse_u16.h buf_parse_u32.h buf_parse_u64.h buf_parse_u8.h buf_parse_uw.h buf_rw.h buf_save.h call.h callable.h cast.h ceiling.h cfn.h character.h compare.h complex.h cow.h crypt.h data.h deserialize.h env.h env_fork.h error.h error_handler.h eval.h explicit_bzero.h f128.h f32.h f64.h fact.h fact_action.h fact_list.h facts.h facts_cursor.h facts_spec.h facts_spec_cursor.h facts_transaction.h facts_with.h facts_with_cursor.h fd.h file.h float.h fn.h fn_clause.h frame.h hash.h ident.h inspect.h integer.h io.h kc3.h kc3_main.h list.h list_init.h log.h map.h module.h mutex.h operator.h pcomplex.h pcow.h pretty.h ptag.h ptr.h ptr_free.h queue.h quote.h ratio.h rwlock.h s16.h s32.h s64.h s8.h sequence.h serialize.h set__fact.h set__tag.h set_cursor__fact.h set_cursor__tag.h set_item__fact.h set_item__tag.h sh.h sha1.h sign.h skiplist__alloc.h skiplist__fact.h skiplist_node__alloc.h skiplist_node__fact.h special_operator.h str.h struct.h struct_type.h sw.h sym.h tag.h tag_init.h tag_type.h time.h to_lisp.h tuple.h types.h u16.h u32.h u64.h u8.h ucd.h unquote.h uw.h var.h void.h wait.h '
-SOURCES='abs.c alist.c alloc.c arg.c array.c binding.c block.c bool.c buf.c buf_fd.c buf_file.c buf_getc.c buf_getchar.c buf_inspect.c buf_inspect_s16.c buf_inspect_s16_binary.c buf_inspect_s16_decimal.c buf_inspect_s16_hexadecimal.c buf_inspect_s16_octal.c buf_inspect_s32.c buf_inspect_s32_binary.c buf_inspect_s32_decimal.c buf_inspect_s32_hexadecimal.c buf_inspect_s32_octal.c buf_inspect_s64.c buf_inspect_s64_binary.c buf_inspect_s64_decimal.c buf_inspect_s64_hexadecimal.c buf_inspect_s64_octal.c buf_inspect_s8.c buf_inspect_s8_binary.c buf_inspect_s8_decimal.c buf_inspect_s8_hexadecimal.c buf_inspect_s8_octal.c buf_inspect_sw.c buf_inspect_sw_binary.c buf_inspect_sw_decimal.c buf_inspect_sw_hexadecimal.c buf_inspect_sw_octal.c buf_inspect_u16.c buf_inspect_u16_binary.c buf_inspect_u16_decimal.c buf_inspect_u16_hexadecimal.c buf_inspect_u16_octal.c buf_inspect_u32.c buf_inspect_u32_binary.c buf_inspect_u32_decimal.c buf_inspect_u32_hexadecimal.c buf_inspect_u32_octal.c buf_inspect_u64.c buf_inspect_u64_binary.c buf_inspect_u64_decimal.c buf_inspect_u64_hexadecimal.c buf_inspect_u64_octal.c buf_inspect_u8.c buf_inspect_u8_binary.c buf_inspect_u8_decimal.c buf_inspect_u8_hexadecimal.c buf_inspect_u8_octal.c buf_inspect_uw.c buf_inspect_uw_binary.c buf_inspect_uw_decimal.c buf_inspect_uw_hexadecimal.c buf_inspect_uw_octal.c buf_parse.c buf_parse_s16.c buf_parse_s32.c buf_parse_s64.c buf_parse_s8.c buf_parse_sw.c buf_parse_u16.c buf_parse_u32.c buf_parse_u64.c buf_parse_u8.c buf_parse_uw.c buf_rw.c buf_save.c call.c callable.c cast.c ceiling.c cfn.c character.c compare.c complex.c cow.c crypt.c crypt_sha512.c data.c deserialize.c env.c env_fork.c error.c error_handler.c eval.c f128.c f32.c f64.c fact.c fact_action.c fact_list.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_transaction.c facts_with.c facts_with_cursor.c fd.c file.c fn.c fn_clause.c frame.c hash.c ident.c inspect.c integer.c io.c kc3.c license.c list.c list_init.c log.c map.c module.c mutex.c operator.c pcomplex.c pcow.c pretty.c ptag.c ptr.c ptr_free.c queue.c quote.c ratio.c rwlock.c s16.c s32.c s64.c s8.c sequence.c serialize.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c sh.c sha1.c sign.c skiplist__alloc.c skiplist__fact.c skiplist_node__alloc.c skiplist_node__fact.c special_operator.c str.c struct.c struct_type.c sw.c sym.c tag.c tag_add.c tag_addi.c tag_band.c tag_bnot.c tag_bor.c tag_bxor.c tag_div.c tag_init.c tag_mod.c tag_mul.c tag_neg.c tag_shift_left.c tag_shift_right.c tag_sqrt.c tag_sub.c tag_type.c time.c to_lisp.c tuple.c u16.c u32.c u64.c u8.c ucd.c unquote.c uw.c var.c void.c wait.c '
-LO_SOURCES=' ../libtommath/bn_cutoffs.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_double.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_rand_platform.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c abs.c alist.c alloc.c arg.c array.c binding.c block.c bool.c buf.c buf_fd.c buf_file.c buf_getc.c buf_getchar.c buf_inspect.c buf_inspect_s16.c buf_inspect_s16_binary.c buf_inspect_s16_decimal.c buf_inspect_s16_hexadecimal.c buf_inspect_s16_octal.c buf_inspect_s32.c buf_inspect_s32_binary.c buf_inspect_s32_decimal.c buf_inspect_s32_hexadecimal.c buf_inspect_s32_octal.c buf_inspect_s64.c buf_inspect_s64_binary.c buf_inspect_s64_decimal.c buf_inspect_s64_hexadecimal.c buf_inspect_s64_octal.c buf_inspect_s8.c buf_inspect_s8_binary.c buf_inspect_s8_decimal.c buf_inspect_s8_hexadecimal.c buf_inspect_s8_octal.c buf_inspect_sw.c buf_inspect_sw_binary.c buf_inspect_sw_decimal.c buf_inspect_sw_hexadecimal.c buf_inspect_sw_octal.c buf_inspect_u16.c buf_inspect_u16_binary.c buf_inspect_u16_decimal.c buf_inspect_u16_hexadecimal.c buf_inspect_u16_octal.c buf_inspect_u32.c buf_inspect_u32_binary.c buf_inspect_u32_decimal.c buf_inspect_u32_hexadecimal.c buf_inspect_u32_octal.c buf_inspect_u64.c buf_inspect_u64_binary.c buf_inspect_u64_decimal.c buf_inspect_u64_hexadecimal.c buf_inspect_u64_octal.c buf_inspect_u8.c buf_inspect_u8_binary.c buf_inspect_u8_decimal.c buf_inspect_u8_hexadecimal.c buf_inspect_u8_octal.c buf_inspect_uw.c buf_inspect_uw_binary.c buf_inspect_uw_decimal.c buf_inspect_uw_hexadecimal.c buf_inspect_uw_octal.c buf_parse.c buf_parse_s16.c buf_parse_s32.c buf_parse_s64.c buf_parse_s8.c buf_parse_sw.c buf_parse_u16.c buf_parse_u32.c buf_parse_u64.c buf_parse_u8.c buf_parse_uw.c buf_rw.c buf_save.c call.c callable.c cast.c ceiling.c cfn.c character.c compare.c complex.c cow.c crypt.c crypt_sha512.c data.c deserialize.c env.c env_fork.c error.c error_handler.c eval.c f128.c f32.c f64.c fact.c fact_action.c fact_list.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_transaction.c facts_with.c facts_with_cursor.c fd.c file.c fn.c fn_clause.c frame.c hash.c ident.c inspect.c integer.c io.c kc3.c license.c list.c list_init.c log.c map.c module.c mutex.c operator.c pcomplex.c pcow.c pretty.c ptag.c ptr.c ptr_free.c queue.c quote.c ratio.c rwlock.c s16.c s32.c s64.c s8.c sequence.c serialize.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c sh.c sha1.c sign.c skiplist__alloc.c skiplist__fact.c skiplist_node__alloc.c skiplist_node__fact.c special_operator.c str.c struct.c struct_type.c sw.c sym.c tag.c tag_add.c tag_addi.c tag_band.c tag_bnot.c tag_bor.c tag_bxor.c tag_div.c tag_init.c tag_mod.c tag_mul.c tag_neg.c tag_shift_left.c tag_shift_right.c tag_sqrt.c tag_sub.c tag_type.c time.c to_lisp.c tuple.c u16.c u32.c u64.c u8.c ucd.c unquote.c uw.c var.c void.c wait.c '
+HEADERS='abs.h alist.h alloc.h array.h assert.h binding.h block.h bool.h buf.h buf_fd.h buf_file.h buf_getc.h buf_getchar.h buf_inspect.h buf_inspect_s16.h buf_inspect_s16_binary.h buf_inspect_s16_decimal.h buf_inspect_s16_hexadecimal.h buf_inspect_s16_octal.h buf_inspect_s32.h buf_inspect_s32_binary.h buf_inspect_s32_decimal.h buf_inspect_s32_hexadecimal.h buf_inspect_s32_octal.h buf_inspect_s64.h buf_inspect_s64_binary.h buf_inspect_s64_decimal.h buf_inspect_s64_hexadecimal.h buf_inspect_s64_octal.h buf_inspect_s8.h buf_inspect_s8_binary.h buf_inspect_s8_decimal.h buf_inspect_s8_hexadecimal.h buf_inspect_s8_octal.h buf_inspect_sw.h buf_inspect_sw_binary.h buf_inspect_sw_decimal.h buf_inspect_sw_hexadecimal.h buf_inspect_sw_octal.h buf_inspect_u16.h buf_inspect_u16_binary.h buf_inspect_u16_decimal.h buf_inspect_u16_hexadecimal.h buf_inspect_u16_octal.h buf_inspect_u32.h buf_inspect_u32_binary.h buf_inspect_u32_decimal.h buf_inspect_u32_hexadecimal.h buf_inspect_u32_octal.h buf_inspect_u64.h buf_inspect_u64_binary.h buf_inspect_u64_decimal.h buf_inspect_u64_hexadecimal.h buf_inspect_u64_octal.h buf_inspect_u8.h buf_inspect_u8_binary.h buf_inspect_u8_decimal.h buf_inspect_u8_hexadecimal.h buf_inspect_u8_octal.h buf_inspect_uw.h buf_inspect_uw_binary.h buf_inspect_uw_decimal.h buf_inspect_uw_hexadecimal.h buf_inspect_uw_octal.h buf_parse.h buf_parse_s16.h buf_parse_s32.h buf_parse_s64.h buf_parse_s8.h buf_parse_sw.h buf_parse_u16.h buf_parse_u32.h buf_parse_u64.h buf_parse_u8.h buf_parse_uw.h buf_rw.h buf_save.h call.h callable.h cast.h ceiling.h cfn.h character.h compare.h complex.h cow.h crypt.h data.h deserialize.h env.h env_fork.h error.h error_handler.h eval.h explicit_bzero.h f128.h f32.h f64.h fact.h fact_action.h fact_list.h facts.h facts_cursor.h facts_spec.h facts_spec_cursor.h facts_transaction.h facts_with.h facts_with_cursor.h fd.h file.h float.h fn.h fn_clause.h frame.h hash.h ident.h inspect.h integer.h io.h kc3.h kc3_main.h list.h list_init.h log.h map.h module.h mutex.h operator.h pcomplex.h pcow.h pretty.h ptag.h ptr.h ptr_free.h queue.h quote.h ratio.h rwlock.h s16.h s32.h s64.h s8.h sequence.h serialize.h set__fact.h set__tag.h set_cursor__fact.h set_cursor__tag.h set_item__fact.h set_item__tag.h sh.h sha1.h sign.h skiplist__alloc.h skiplist__fact.h skiplist_node__alloc.h skiplist_node__fact.h special_operator.h str.h struct.h struct_type.h sw.h sym.h tag.h tag_init.h tag_type.h time.h to_lisp.h tuple.h types.h u16.h u32.h u64.h u8.h ucd.h unquote.h uw.h var.h void.h wait.h '
+SOURCES='abs.c alist.c alloc.c array.c binding.c block.c bool.c buf.c buf_fd.c buf_file.c buf_getc.c buf_getchar.c buf_inspect.c buf_inspect_s16.c buf_inspect_s16_binary.c buf_inspect_s16_decimal.c buf_inspect_s16_hexadecimal.c buf_inspect_s16_octal.c buf_inspect_s32.c buf_inspect_s32_binary.c buf_inspect_s32_decimal.c buf_inspect_s32_hexadecimal.c buf_inspect_s32_octal.c buf_inspect_s64.c buf_inspect_s64_binary.c buf_inspect_s64_decimal.c buf_inspect_s64_hexadecimal.c buf_inspect_s64_octal.c buf_inspect_s8.c buf_inspect_s8_binary.c buf_inspect_s8_decimal.c buf_inspect_s8_hexadecimal.c buf_inspect_s8_octal.c buf_inspect_sw.c buf_inspect_sw_binary.c buf_inspect_sw_decimal.c buf_inspect_sw_hexadecimal.c buf_inspect_sw_octal.c buf_inspect_u16.c buf_inspect_u16_binary.c buf_inspect_u16_decimal.c buf_inspect_u16_hexadecimal.c buf_inspect_u16_octal.c buf_inspect_u32.c buf_inspect_u32_binary.c buf_inspect_u32_decimal.c buf_inspect_u32_hexadecimal.c buf_inspect_u32_octal.c buf_inspect_u64.c buf_inspect_u64_binary.c buf_inspect_u64_decimal.c buf_inspect_u64_hexadecimal.c buf_inspect_u64_octal.c buf_inspect_u8.c buf_inspect_u8_binary.c buf_inspect_u8_decimal.c buf_inspect_u8_hexadecimal.c buf_inspect_u8_octal.c buf_inspect_uw.c buf_inspect_uw_binary.c buf_inspect_uw_decimal.c buf_inspect_uw_hexadecimal.c buf_inspect_uw_octal.c buf_parse.c buf_parse_s16.c buf_parse_s32.c buf_parse_s64.c buf_parse_s8.c buf_parse_sw.c buf_parse_u16.c buf_parse_u32.c buf_parse_u64.c buf_parse_u8.c buf_parse_uw.c buf_rw.c buf_save.c call.c callable.c cast.c ceiling.c cfn.c character.c compare.c complex.c cow.c crypt.c crypt_sha512.c data.c deserialize.c env.c env_fork.c error.c error_handler.c eval.c f128.c f32.c f64.c fact.c fact_action.c fact_list.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_transaction.c facts_with.c facts_with_cursor.c fd.c file.c fn.c fn_clause.c frame.c hash.c ident.c inspect.c integer.c io.c kc3.c license.c list.c list_init.c log.c map.c module.c mutex.c operator.c pcomplex.c pcow.c pretty.c ptag.c ptr.c ptr_free.c queue.c quote.c ratio.c rwlock.c s16.c s32.c s64.c s8.c sequence.c serialize.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c sh.c sha1.c sign.c skiplist__alloc.c skiplist__fact.c skiplist_node__alloc.c skiplist_node__fact.c special_operator.c str.c struct.c struct_type.c sw.c sym.c tag.c tag_add.c tag_addi.c tag_band.c tag_bnot.c tag_bor.c tag_bxor.c tag_div.c tag_init.c tag_mod.c tag_mul.c tag_neg.c tag_shift_left.c tag_shift_right.c tag_sqrt.c tag_sub.c tag_type.c time.c to_lisp.c tuple.c u16.c u32.c u64.c u8.c ucd.c unquote.c uw.c var.c void.c wait.c '
+LO_SOURCES=' ../libtommath/bn_cutoffs.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_double.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_rand_platform.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c abs.c alist.c alloc.c array.c binding.c block.c bool.c buf.c buf_fd.c buf_file.c buf_getc.c buf_getchar.c buf_inspect.c buf_inspect_s16.c buf_inspect_s16_binary.c buf_inspect_s16_decimal.c buf_inspect_s16_hexadecimal.c buf_inspect_s16_octal.c buf_inspect_s32.c buf_inspect_s32_binary.c buf_inspect_s32_decimal.c buf_inspect_s32_hexadecimal.c buf_inspect_s32_octal.c buf_inspect_s64.c buf_inspect_s64_binary.c buf_inspect_s64_decimal.c buf_inspect_s64_hexadecimal.c buf_inspect_s64_octal.c buf_inspect_s8.c buf_inspect_s8_binary.c buf_inspect_s8_decimal.c buf_inspect_s8_hexadecimal.c buf_inspect_s8_octal.c buf_inspect_sw.c buf_inspect_sw_binary.c buf_inspect_sw_decimal.c buf_inspect_sw_hexadecimal.c buf_inspect_sw_octal.c buf_inspect_u16.c buf_inspect_u16_binary.c buf_inspect_u16_decimal.c buf_inspect_u16_hexadecimal.c buf_inspect_u16_octal.c buf_inspect_u32.c buf_inspect_u32_binary.c buf_inspect_u32_decimal.c buf_inspect_u32_hexadecimal.c buf_inspect_u32_octal.c buf_inspect_u64.c buf_inspect_u64_binary.c buf_inspect_u64_decimal.c buf_inspect_u64_hexadecimal.c buf_inspect_u64_octal.c buf_inspect_u8.c buf_inspect_u8_binary.c buf_inspect_u8_decimal.c buf_inspect_u8_hexadecimal.c buf_inspect_u8_octal.c buf_inspect_uw.c buf_inspect_uw_binary.c buf_inspect_uw_decimal.c buf_inspect_uw_hexadecimal.c buf_inspect_uw_octal.c buf_parse.c buf_parse_s16.c buf_parse_s32.c buf_parse_s64.c buf_parse_s8.c buf_parse_sw.c buf_parse_u16.c buf_parse_u32.c buf_parse_u64.c buf_parse_u8.c buf_parse_uw.c buf_rw.c buf_save.c call.c callable.c cast.c ceiling.c cfn.c character.c compare.c complex.c cow.c crypt.c crypt_sha512.c data.c deserialize.c env.c env_fork.c error.c error_handler.c eval.c f128.c f32.c f64.c fact.c fact_action.c fact_list.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_transaction.c facts_with.c facts_with_cursor.c fd.c file.c fn.c fn_clause.c frame.c hash.c ident.c inspect.c integer.c io.c kc3.c license.c list.c list_init.c log.c map.c module.c mutex.c operator.c pcomplex.c pcow.c pretty.c ptag.c ptr.c ptr_free.c queue.c quote.c ratio.c rwlock.c s16.c s32.c s64.c s8.c sequence.c serialize.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c sh.c sha1.c sign.c skiplist__alloc.c skiplist__fact.c skiplist_node__alloc.c skiplist_node__fact.c special_operator.c str.c struct.c struct_type.c sw.c sym.c tag.c tag_add.c tag_addi.c tag_band.c tag_bnot.c tag_bor.c tag_bxor.c tag_div.c tag_init.c tag_mod.c tag_mul.c tag_neg.c tag_shift_left.c tag_shift_right.c tag_sqrt.c tag_sub.c tag_type.c time.c to_lisp.c tuple.c u16.c u32.c u64.c u8.c ucd.c unquote.c uw.c var.c void.c wait.c '
diff --git a/libkc3/str.c b/libkc3/str.c
index 29db4df..349376a 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -221,13 +221,13 @@ void str_clean (s_str *str)
{
assert(str);
if (str->free.p)
- free(str->free.p);
+ alloc_unmap(str->free.p, str->size + 1);
}
void str_delete (s_str *str)
{
str_clean(str);
- free(str);
+ alloc_unmap(str, sizeof(s_str));
}
bool * str_ends_with (const s_str *str, const s_str *end, bool *dest)
@@ -317,7 +317,7 @@ s_str * str_init_1_alloc (s_str *str, const char *p)
s_str tmp = {0};
assert(str);
size = strlen(p);
- tmp.free.p = alloc(size + 1);
+ tmp.free.p = alloc_map(size + 1);
if (! tmp.free.p)
return NULL;
tmp.size = size;
@@ -331,7 +331,7 @@ s_str * str_init_alloc (s_str *str, uw size)
{
s_str tmp = {0};
assert(str);
- tmp.free.p = alloc(size + 1);
+ tmp.free.p = alloc_map(size + 1);
if (! tmp.free.p)
return NULL;
tmp.size = size;
@@ -344,7 +344,7 @@ s_str * str_init_alloc_copy (s_str *str, uw size, const char *p)
{
s_str tmp = {0};
assert(str);
- tmp.free.p = alloc(size + 1);
+ tmp.free.p = alloc_map(size + 1);
if (! tmp.free.p)
return NULL;
tmp.size = size;
@@ -459,7 +459,7 @@ s_str * str_init_concatenate (s_str *str, const s_str *a,
assert(a);
assert(b);
tmp.size = a->size + b->size;
- tmp.free.p = alloc(tmp.size + 1);
+ tmp.free.p = alloc_map(tmp.size + 1);
if (! tmp.free.p)
return NULL;
tmp.ptr.p = tmp.free.p;
@@ -512,7 +512,7 @@ s_str * str_init_copy (s_str *str, const s_str *src)
s_str tmp = {0};
assert(str);
assert(src);
- tmp.free.p = alloc(src->size + 1);
+ tmp.free.p = alloc_map(src->size + 1);
if (! tmp.free.p)
return NULL;
tmp.size = src->size;
@@ -529,7 +529,7 @@ s_str * str_init_copy_1 (s_str *str, const char *src)
assert(str);
assert(src);
len = strlen(src);
- tmp.free.p = alloc(len + 1);
+ tmp.free.p = alloc_map(len + 1);
if (! tmp.free.p)
return NULL;
tmp.size = len;
@@ -757,17 +757,17 @@ s_str * str_init_ftime (s_str *str, s_time *time, const s_str *format)
if (! (utc = gmtime(&t)))
return NULL;
size = format->size * 32;
- if (! (buf = alloc(size)))
+ if (! (buf = alloc_map(size)))
return NULL;
if (! strftime(buf, size - 1, format->ptr.pchar, utc))
goto clean;
if (! str_init_1_alloc(&tmp, buf))
goto clean;
- free(buf);
+ alloc_unmap(buf, size);
*str = tmp;
return str;
clean:
- free(buf);
+ alloc_unmap(buf, size);
return NULL;
}
@@ -796,10 +796,10 @@ s_str * str_init_random_base64 (s_str *str, const s_tag *len)
return NULL;
}
random_bytes_len = ceil(log2(pow(64, result_len)) / 8);
- if (! (random_bytes = alloc(random_bytes_len)))
+ if (! (random_bytes = alloc_map(random_bytes_len)))
return NULL;
- if (! (result = alloc(result_len + 1))) {
- free(random_bytes);
+ if (! (result = alloc_map(result_len + 1))) {
+ alloc_unmap(random_bytes, random_bytes_len);
return NULL;
}
arc4random_buf(random_bytes, random_bytes_len);
@@ -841,7 +841,7 @@ s_str * str_init_random_base64 (s_str *str, const s_tag *len)
k++;
}
}
- free(random_bytes);
+ alloc_unmap(random_bytes, random_bytes_len);
return str_init(str, result, result_len, result);
}
@@ -1020,7 +1020,7 @@ sw str_length_utf8 (const s_str *str)
s_str * str_new (char *free, uw size, const char *p)
{
s_str *str;
- str = alloc(sizeof(s_str));
+ str = alloc_map(sizeof(s_str));
if (! str)
return NULL;
str_init(str, free, size, p);
@@ -1038,13 +1038,13 @@ s_str * str_new_cpy (const char *p, uw size)
{
char *a;
s_str *str;
- a = alloc(size);
+ a = alloc_map(size + 1);
if (! a)
return NULL;
memcpy(a, p, size);
str = str_new(a, size, a);
if (! str) {
- free(a);
+ alloc_unmap(a, size + 1);
return NULL;
}
return str;
@@ -1055,13 +1055,13 @@ s_str * str_new_copy (const s_str *src)
char *a;
s_str *dest;
assert(src);
- a = alloc(src->size);
+ a = alloc_map(src->size + 1);
if (! a)
return NULL;
memcpy(a, src->ptr.p, src->size);
dest = str_new(a, src->size, a);
if (! dest) {
- free(a);
+ alloc_unmap(a, src->size + 1);
return NULL;
}
return dest;
@@ -1160,7 +1160,7 @@ bool str_parse_eval (const s_str *str, s_tag *dest)
else if (list->tag.type == TAG_STR &&
! list_next(list)) {
tmp = list->tag;
- free(list);
+ list_delete(list);
}
else {
tag_init_call(&tmp);
diff --git a/libkc3/struct_type.c b/libkc3/struct_type.c
index ba26580..0b58e91 100644
--- a/libkc3/struct_type.c
+++ b/libkc3/struct_type.c
@@ -26,9 +26,11 @@
void struct_type_clean (s_struct_type *st)
{
+ uw size;
assert(st);
+ size = st->map.count * sizeof(uw);
map_clean(&st->map);
- free(st->offset);
+ alloc_unmap(st->offset, size);
}
void * struct_type_copy_data (const s_struct_type *st, void *dest,
@@ -59,7 +61,7 @@ void struct_type_delete (s_struct_type *st)
{
assert(st);
struct_type_clean(st);
- free(st);
+ alloc_unmap(st, sizeof(s_struct_type));
}
bool * struct_type_exists (const s_sym *module, bool *dest)
@@ -98,6 +100,7 @@ s_struct_type * struct_type_init (s_struct_type *st,
uw i;
bool must_clean = false;
uw offset;
+ uw offset_size;
const s_list *s;
uw size;
s_struct_type tmp = {0};
@@ -110,7 +113,8 @@ s_struct_type * struct_type_init (s_struct_type *st,
tmp.module = module;
if (! map_init(&tmp.map, count))
return NULL;
- tmp.offset = alloc(count * sizeof(uw));
+ offset_size = count * sizeof(uw);
+ tmp.offset = alloc_map(offset_size);
if (! tmp.offset) {
map_clean(&tmp.map);
return NULL;
@@ -124,7 +128,7 @@ s_struct_type * struct_type_init (s_struct_type *st,
err_puts("struct_type_init: invalid spec");
assert(! "struct_type_init: invalid spec");
map_clean(&tmp.map);
- free(tmp.offset);
+ alloc_unmap(tmp.offset, offset_size);
return NULL;
}
tuple = &s->tag.data.tuple;
@@ -132,13 +136,13 @@ s_struct_type * struct_type_init (s_struct_type *st,
type = tuple->tag[1].data.var.type;
if (! sym_type_size(&type, &size)) {
map_clean(&tmp.map);
- free(tmp.offset);
+ alloc_unmap(tmp.offset, offset_size);
return NULL;
}
}
else if (! tag_size(tuple->tag + 1, &size)) {
map_clean(&tmp.map);
- free(tmp.offset);
+ alloc_unmap(tmp.offset, offset_size);
return NULL;
}
tag_init_copy(tmp.map.key + i, tuple->tag + 0);
@@ -146,7 +150,7 @@ s_struct_type * struct_type_init (s_struct_type *st,
tag_type(tmp.map.value + i, &type);
if (! sym_must_clean(type, &must_clean)) {
map_clean(&tmp.map);
- free(tmp.offset);
+ alloc_unmap(tmp.offset, offset_size);
return NULL;
}
if (must_clean)
@@ -217,7 +221,7 @@ s_struct_type * struct_type_init_copy (s_struct_type *st,
return NULL;
tmp.module = src->module;
tmp.must_clean = src->must_clean;
- tmp.offset = alloc(tmp.map.count * sizeof(uw));
+ tmp.offset = alloc_map(tmp.map.count * sizeof(uw));
if (! tmp.offset) {
map_clean(&tmp.map);
return NULL;
@@ -250,11 +254,11 @@ s_struct_type * struct_type_new (const s_sym *module,
{
s_struct_type *st;
assert(module);
- st = alloc(sizeof(s_struct_type));
+ st = alloc_map(sizeof(s_struct_type));
if (! st)
return NULL;
if (! struct_type_init(st, module, spec)) {
- free(st);
+ alloc_unmap(st, sizeof(s_struct_type));
return NULL;
}
return st;
diff --git a/libkc3/sym.c b/libkc3/sym.c
index 7543346..86e92cb 100644
--- a/libkc3/sym.c
+++ b/libkc3/sym.c
@@ -201,7 +201,7 @@ bool sym_character_is_reserved (character c)
void sym_delete (s_sym *sym)
{
str_clean(&sym->str);
- free(sym);
+ alloc_unmap(sym, sizeof(s_sym));
}
void sym_delete_all (void)
@@ -215,7 +215,7 @@ void sym_delete_all (void)
sym_list = sym_list->next;
if (tmp->free_sym)
sym_delete(tmp->free_sym);
- free(tmp);
+ alloc_unmap(tmp, sizeof(s_sym_list));
}
}
@@ -546,7 +546,7 @@ s_sym_list * sym_list_new (const s_sym *sym, s_sym *free_sym,
s_sym_list *next)
{
s_sym_list *sym_list;
- sym_list = alloc(sizeof(s_sym_list));
+ sym_list = alloc_map(sizeof(s_sym_list));
if (! sym_list)
return NULL;
sym_list->sym = sym;
@@ -707,17 +707,17 @@ const s_sym * sym_new (const s_str *src)
{
s_sym *sym = NULL;
s_sym_list *tmp = NULL;
- sym = alloc(sizeof(s_sym));
+ sym = alloc_map(sizeof(s_sym));
if (! sym)
return NULL;
if (! str_init_copy(&sym->str, src)) {
- free(sym);
+ alloc_unmap(sym, sizeof(s_sym));
return NULL;
}
tmp = sym_list_new(sym, sym, g_sym_list);
if (! tmp) {
str_clean(&sym->str);
- free(sym);
+ alloc_unmap(sym, sizeof(s_sym));
return NULL;
}
g_sym_list = tmp;
diff --git a/libkc3/tag_addi.c b/libkc3/tag_addi.c
index 7f57331..53e0ee1 100644
--- a/libkc3/tag_addi.c
+++ b/libkc3/tag_addi.c
@@ -25,30 +25,30 @@ s_tag * tag_addi (s_tag *a, s_tag *b, s_tag *dest)
assert(a);
assert(b);
assert(dest);
- c = alloc(sizeof(s_complex));
+ c = alloc_map(sizeof(s_complex));
if (! c)
return NULL;
type = &g_sym_Complex;
if (! complex_init_cast(&ca, &type, a)) {
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
if (! complex_init_cast(&cb, &type, b)) {
complex_clean(&ca);
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
if (! tag_sub(&ca.x, &cb.y, &c->x)) {
complex_clean(&cb);
complex_clean(&ca);
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
if (! tag_add(&ca.y, &cb.x, &c->y)) {
tag_clean(&c->x);
complex_clean(&cb);
complex_clean(&ca);
- free(c);
+ alloc_unmap(c, sizeof(s_complex));
return NULL;
}
complex_clean(&cb);
diff --git a/libkc3/types.h b/libkc3/types.h
index 41d7955..8a7052f 100644
--- a/libkc3/types.h
+++ b/libkc3/types.h
@@ -174,8 +174,8 @@ typedef enum {
} e_tag_type;
/* structs */
-typedef struct alloc s_alloc;
-typedef struct arg s_arg;
+typedef struct alloc_ s_alloc;
+ // typedef struct arg s_arg;
typedef struct array s_array;
typedef struct array_dimension s_array_dimension;
typedef struct binding s_binding;
@@ -266,9 +266,9 @@ typedef bool (* f_sequence_button) (s_sequence *seq, u8 button, sw x,
/* 1 */
-struct alloc {
- uw size;
- void *start;
+struct alloc_ {
+ void *mapped;
+ uw size;
};
struct array_dimension {
@@ -636,11 +636,13 @@ struct tag {
/* 7 */
+ /*
struct arg {
const s_sym *name;
s_type type;
s_arg *next;
};
+ */
struct binding {
const s_sym *name;