From f6dd75cc5490f2e84194fc18298d8f07fd90a673 Mon Sep 17 00:00:00 2001 From: Julien Fischer Date: Wed, 11 Jan 2012 04:58:12 +0000 Subject: [PATCH] Make it possible to initialise the Mercury runtime using an external interface Branches: main Make it possible to initialise the Mercury runtime using an external interface without providing the address of the base of the stack. This should work on most systems and can be useful when the top-level of a program is not written in C or C++. (In principle, this probably always worked, so the main change here is to document it.) util/mkinit.c: If mercury_init's stackbottom argument is NULL then don't set GC_stackbottom. doc/user_guide.texi: Extend the description of the mercury_init function in the standalone-interfaces section to include the above. --- doc/user_guide.texi | 2 ++ util/mkinit.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/user_guide.texi b/doc/user_guide.texi index 8bda892cf..86b949dc0 100644 --- a/doc/user_guide.texi +++ b/doc/user_guide.texi @@ -10774,6 +10774,8 @@ Note that the address of the stack base should be word aligned as some garbage collectors rely upon this. (This is why the type of the dummy variable in the above example is @code{void *}.) +If the value of @var{stackbottom} is @code{NULL} then the collector will attempt +to determine the address of the base of the stack itself. Note that modifying the argument vector, @var{argv}, after the Mercury runtime has been initialised will result in undefined behaviour since the runtime maintains a reference into @var{argv}. diff --git a/util/mkinit.c b/util/mkinit.c index d071cbfdd..5a46199fe 100644 --- a/util/mkinit.c +++ b/util/mkinit.c @@ -2,7 +2,7 @@ ** vim:sw=4 ts=4 expandtab */ /* -** Copyright (C) 1995-2008, 2010-2011 The University of Melbourne. +** Copyright (C) 1995-2008, 2010-2012 The University of Melbourne. ** This file may only be copied under the terms of the GNU General ** Public License - see the file COPYING in the Mercury distribution. */ @@ -380,11 +380,16 @@ static const char mercury_funcs1[] = " ** GC knows where it starts. This is necessary for AIX 4.1\n" " ** on RS/6000, and for gnu-win32 on Windows 95 or NT.\n" " ** It may also be helpful on other systems.\n" + " ** For the Boehm GC, if the stackbottom argument is NULL then\n" + " ** do not explicitly register the bottom of the stack, but\n" + " ** let the collector determine an appropriate value itself.\n" " */\n" " #if defined(MR_HGC)\n" " MR_hgc_set_stack_bot(stackbottom);\n" " #elif defined(MR_BOEHM_GC)\n" - " GC_stackbottom = stackbottom;\n" + " if (stackbottom != NULL) {\n" + " GC_stackbottom = stackbottom;\n" + " }\n" " #endif\n" "#endif\n" "\n"