Node:spld examples, Previous:All-in-one Executables, Up:The Application Builder
sicstus
) can be created using
% spld --main=prolog -o sicstus
This will create a development system which is dynamically linked and has no pre-linked foreign resources.
% spld --static -D --resources=random -o main -ltk8.0 -ltcl8.0
This will create a statically linked executable called main
which
has the resource random
pre-linked (statically). The linker will
receive -ltk8.0 -ltcl8.0
which will work under UNIX (if Tcl/Tk is
installed correctly) but will probably fail under Windows.
--userhook
option to perform
initializations in development systems before SP_initialize()
is
called. It also demonstrates how to use this mechanism to redefine the
memory manager bottom layer.
/* -------------------------------------------------------------- * userhook.c - an example of how to use SU_initialize() to * define your own memory manager bottom layer. * * The following commands create a sicstus-executable 'msicstus' * which uses malloc() as its own memory manager bottom layer. * This is more or less equivalent to specifying "-m" to the * regular 'sicstus' executable, except that these memory hooks * print out messages when they are called. * -------------------------------------------------------------- */ #include <stdio.h> #include <stdlib.h> #include <sicstus/sicstus.h> /* for mallopt() */ #ifdef linux #include <malloc.h> #endif void * my_alloc_hook (unsigned int size, unsigned int align, unsigned int *actual_size) { void *mem; printf ("Inside my_alloc_hook(%d,%d,%p) -> ", size, align, actual_size); if (align > sizeof (double)) size += align; mem = malloc (size); *actual_size = size; if (mem) printf ("%p\n", mem); else printf ("NULL (malloc failed to allocate memory)\n"); return mem; } void * my_init_alloc_hook (unsigned int size, unsigned int align, unsigned int *actual_size) { printf ("Inside my_init_alloc_hook(%d,%d,%p)\n", size, align, actual_size); /* Do not use MMAP on Linux. */ #ifdef linux mallopt (M_MMAP_MAX, 0); #endif return my_alloc_hook (size, align, actual_size); } void * my_realloc_hook (void *ptr, unsigned int oldsize, unsigned int newsize, unsigned int align, unsigned int *actual_size) { void *mem; printf ("Inside my_realloc_hook(%p,%d,%d,%d,%p) -> ", ptr, oldsize, newsize, align, actual_size); if (align > sizeof (double)) newsize += align; mem = realloc (ptr, newsize); *actual_size = newsize; if (mem) printf ("%p\n", mem); else printf ("NULL (realloc() failed to re-allocate memory)\n"); return mem; } int my_free_hook (void *ptr, unsigned int size) { printf ("Inside my_free_hook(%p,%d)\n", ptr, size); free (ptr); return 1; } /* Entry point for initializations to be done before SP_initialize() */ int SU_initialize (int argc, char **argv) { SP_set_memalloc_hooks (MM_USE_OTHER, my_init_alloc_hook, my_alloc_hook, my_realloc_hook, my_free_hook); return 0; }
Compile userhook.c
like this:
% spld -D --userhook userhook.c -o ./msicstus Created "./msicstus" % ./msicstus Inside my_init_alloc_hook(524304,8,0xbfffc318) Inside my_alloc_hook(524304,8,0xbfffc318) -> 0x804b920 Inside my_alloc_hook(65536,8,0xbfff019c) -> 0x80cba38 Inside my_alloc_hook(65536,8,0xbfff019c) -> 0x80dba40 Inside my_alloc_hook(65536,8,0xbfff00d0) -> 0x80eba48 Inside my_alloc_hook(65544,8,0xbfff0110) -> 0x80fba50 Inside my_alloc_hook(65536,8,0xbfff019c) -> 0x810ba60 Inside my_alloc_hook(65536,8,0xbfff00f4) -> 0x811ba68 Inside my_alloc_hook(65536,8,0xbfff019c) -> 0x812ba70 Inside my_alloc_hook(65536,8,0xbfff019c) -> 0x813ba78 Inside my_alloc_hook(65536,8,0xbfff019c) -> 0x814ba80 Inside my_alloc_hook(65536,8,0xbfff019c) -> 0x815ba88 Inside my_alloc_hook(65536,8,0xbfff019c) -> 0x816ba90 SICStus 3.8b1 (x86-linux-glibc2.1): Fri Oct 29 11:24:24 CEST 1999 Licensed to SICS Inside my_free_hook(0x80fba50,65544) | ?-