Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack scanning for the Julia GC when GAP is used as a library. #3432

Merged
merged 2 commits into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ enum {
};


/****************************************************************************
**
*F IsUsingLibGap() . . . . . . . . 1 if GAP is being used a library, else 0
*/
int IsUsingLibGap(void);

/****************************************************************************
**
*F InitializeGap( <argc>, <argv>, <handleSignals> ) . . . . . . . init GAP
Expand Down
14 changes: 13 additions & 1 deletion src/julia_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "sysmem.h"
#include "system.h"
#include "vars.h"
#include "gap.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -660,7 +661,18 @@ static void GapRootScanner(int full)
// current_task != root_task.
char * stackend = (char *)jl_task_stack_buffer(task, &size, &tid);
stackend += size;
if (JuliaTLS->tid == 0 && JuliaTLS->root_task == task) {
// The following test overrides the stackend if the following two
// conditions hold:
//
// 1. GAP is not being used as a library, but is the main program
// and in charge of the main() function.
// 2. The stack of the current task is that of the main task of the
// main thread.
//
// The reason is that if Julia is being initialized from GAP, it
// cannot always reliably find the top of the stack for that task,
// so we have to fall back to GAP for that.
if (!IsUsingLibGap() && JuliaTLS->tid == 0 && JuliaTLS->root_task == task) {
stackend = (char *)GapStackBottom;
}

Expand Down
9 changes: 9 additions & 0 deletions src/libgap-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
#include "streams.h"
#include "stringobj.h"

static int UsingLibGap = 0;

int IsUsingLibGap(void)
{
return UsingLibGap;
}


//
// Setup and initialisation
Expand All @@ -41,6 +48,8 @@ void GAP_Initialize(int argc,
GAP_CallbackFunc errorCallback,
int handleSignals)
{
UsingLibGap = 1;

InitializeGap(&argc, argv, handleSignals);
SetExtraMarkFuncBags(markBagsCallback);
STATE(JumpToCatchCallback) = errorCallback;
Expand Down