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

New mark function for Julia object #229

Merged
merged 2 commits into from
Apr 26, 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
12 changes: 11 additions & 1 deletion pkg/GAPJulia/JuliaInterface/src/JuliaInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "convert.h"

#include <src/compiled.h> // GAP headers
#include <src/julia_gc.h>

#include <julia_gcext.h>

Expand Down Expand Up @@ -329,6 +330,15 @@ static Obj FuncJuliaGetFieldOfObject(Obj self, Obj super_obj, Obj field_name)
return gap_julia(field_value);
}

// Mark the Julia pointer inside the GAP JuliaObj
static void MarkJuliaObject(Bag bag)
{
#ifdef DEBUG_MASTERPOINTERS
MarkJuliaObjSafe((void *)GET_JULIA_OBJ(bag));
#else
MarkJuliaObj((void *)GET_JULIA_OBJ(bag));
#endif
}

// Table of functions to export
static StructGVarFunc GVarFuncs[] = {
Expand Down Expand Up @@ -365,7 +375,7 @@ static Int InitKernel(StructInitInfo * module)

T_JULIA_OBJ = RegisterPackageTNUM("JuliaObject", JuliaObjectTypeFunc);

InitMarkFuncBags(T_JULIA_OBJ, &MarkOneSubBags);
InitMarkFuncBags(T_JULIA_OBJ, &MarkJuliaObject);

CopyObjFuncs[T_JULIA_OBJ] = &JuliaObjCopyFunc;
CleanObjFuncs[T_JULIA_OBJ] = &JuliaObjCleanFunc;
Expand Down
13 changes: 7 additions & 6 deletions pkg/GAPJulia/JuliaInterface/src/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static Obj DoCallJuliaFunc0Arg(Obj func);

typedef struct {
FuncBag f;
void * juliaFunc;
Obj juliaFunc;
} JuliaFuncBag;


Expand Down Expand Up @@ -87,7 +87,8 @@ inline Int IS_JULIA_FUNC(Obj obj)
inline jl_function_t * GET_JULIA_FUNC(Obj func)
{
GAP_ASSERT(IS_JULIA_FUNC(func));
return ((const JuliaFuncBag *)CONST_ADDR_OBJ(func))->juliaFunc;
return (jl_function_t *)GET_JULIA_OBJ(
((const JuliaFuncBag *)CONST_ADDR_OBJ(func))->juliaFunc);
}

static ALWAYS_INLINE Obj DoCallJuliaFunc(Obj func, const int narg, Obj * a)
Expand Down Expand Up @@ -202,7 +203,7 @@ Obj NewJuliaFunc(jl_function_t * function)
SET_HDLR_FUNC(func, 7, DoCallJuliaFuncXArg);

// store the the Julia function pointer
((JuliaFuncBag *)ADDR_OBJ(func))->juliaFunc = function;
((JuliaFuncBag *)ADDR_OBJ(func))->juliaFunc = NewJuliaObj(function);

// add a function body so that we can store some meta data about the
// origin of this function, for slightly more helpful printing of the
Expand All @@ -223,8 +224,8 @@ Obj NewJuliaFunc(jl_function_t * function)

static inline ObjFunc get_c_function_pointer(Obj func)
{
void * ptr = ((const JuliaFuncBag *)CONST_ADDR_OBJ(func))->juliaFunc;
return jl_unbox_voidpointer((jl_value_t *)ptr);
Obj ptr = ((const JuliaFuncBag *)CONST_ADDR_OBJ(func))->juliaFunc;
return jl_unbox_voidpointer(GET_JULIA_OBJ(ptr));
}

static Obj DoCallJuliaCFunc0Arg(Obj func)
Expand Down Expand Up @@ -338,7 +339,7 @@ Obj NewJuliaCFunc(void * function, Obj arg_names)
// store function pointer in the bag; since it gets marked by the GC, we
// store it as a valid julia obj (i.e., void ptr).
((JuliaFuncBag *)ADDR_OBJ(func))->juliaFunc =
jl_box_voidpointer(function);
NewJuliaObj(jl_box_voidpointer(function));

return func;
}