## memalloc-a4-unix.pkg
## Author: Matthias Blume (blume@tti-c.org)
# Compiled by:
#
src/lib/c-glue-lib/ram/memory.lib# Memory allocation (via malloc) for Unix.
# Size of address: 4 bytes.
package cmem_allot: (weak) Cmemalloc { # Cmemalloc is from
src/lib/c-glue-lib/ram/memalloc.api exception OUT_OF_MEMORY;
Addr = one_word_unt::Unt;
Addr' = Addr;
package dl= dynamic_linkage; # dynamic_linkage is from
src/lib/c-glue-lib/ram/linkage-dlopen.pkg fun main's s
=
dl::lib_symbol (dl::main_lib, s);
malloc_h = main's "malloc";
free_h = main's "free";
fun sys_malloc (n: one_word_unt::Unt)
=
{ w_p = raw_mem_inline_t::rawccall
: (one_word_unt::Unt, one_word_unt::Unt, List( (Void, Unt) -> String )) -> one_word_unt::Unt;
a = w_p (dl::address malloc_h, n, []);
if (a == 0u0) raise exception OUT_OF_MEMORY;
else a;
fi;
};
fun sys_free (a: one_word_unt::Unt)
=
{ p_u = raw_mem_inline_t::rawccall
: (one_word_unt::Unt, one_word_unt::Unt, List( (Void, String) -> Void )) -> Void;
p_u (dl::address free_h, a, []);
};
fun allot bytes
=
sys_malloc (unt::to_large_unt bytes);
fun free a
=
sys_free a;
};
## Copyright (c) 2004 by The Fellowship of SML/NJ
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.