Skip to content

Commit

Permalink
Made julia error messages handled by GAP
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasguts committed Oct 15, 2018
1 parent 1298f6d commit 9c9aae8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 12 additions & 0 deletions JuliaInterface/src/JuliaInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include "JuliaInterface.h"

jl_value_t * JULIA_ERROR_IOBuffer;
jl_function_t * JULIA_FUNC_take_inplace;
jl_function_t * JULIA_FUNC_String_constructor;
jl_function_t * JULIA_FUNC_showerror;

#include "gap_macros.c"

Obj TheTypeJuliaObject;
Expand Down Expand Up @@ -910,6 +915,13 @@ static Int InitKernel(StructInitInfo * module)
CleanObjFuncs[T_JULIA_OBJ] = &JuliaObjCleanFunc;
IsMutableObjFuncs[T_JULIA_OBJ] = &JuliaObjIsMutableFunc;

// Initialize necessary variables for error handling
JULIA_ERROR_IOBuffer =
jl_eval_string("GAP_JULIA_ERROR_IO_BUFFER = Base.IOBuffer()");
JULIA_FUNC_take_inplace = jl_get_function(jl_base_module, "take!");
JULIA_FUNC_String_constructor = jl_get_function(jl_base_module, "String");
JULIA_FUNC_showerror = jl_get_function(jl_base_module, "showerror");

// Initialize GAP function pointers in Julia
JuliaInitializeGAPFunctionPointers();

Expand Down
16 changes: 12 additions & 4 deletions JuliaInterface/src/JuliaInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
#include "src/compiled.h" /* GAP headers */
#include <julia.h>

extern jl_value_t * JULIA_ERROR_IOBuffer;
extern jl_function_t * JULIA_FUNC_take_inplace;
extern jl_function_t * JULIA_FUNC_String_constructor;
extern jl_function_t * JULIA_FUNC_showerror;

#define JULIAINTERFACE_EXCEPTION_HANDLER \
if (jl_exception_occurred()) { \
jl_call2(jl_get_function(jl_base_module, "showerror"), \
jl_stderr_obj(), jl_exception_occurred()); \
jl_printf(jl_stderr_stream(), "\n"); \
ErrorMayQuit("JuliaError", 0, 0); \
jl_call2(JULIA_FUNC_showerror, JULIA_ERROR_IOBuffer, \
jl_exception_occurred()); \
jl_value_t * string_object = \
jl_call1(JULIA_FUNC_take_inplace, JULIA_ERROR_IOBuffer); \
string_object = \
jl_call1(JULIA_FUNC_String_constructor, string_object); \
ErrorMayQuit(jl_string_data(string_object), 0, 0); \
}

#define INITIALIZE_JULIA_CPOINTER(name) \
Expand Down
6 changes: 5 additions & 1 deletion JuliaInterface/tst/import.tst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ false
##
gap> ImportJuliaModuleIntoGAP( "Core" );
gap> ImportJuliaModuleIntoGAP( "No_Julia_Module_With_This_Name" );
Error, JuliaError
Error, ArgumentError: Package No_Julia_Module_With_This_Name not found in curr\
ent path:
- Run `import Pkg; Pkg.add("No_Julia_Module_With_This_Name")` to install the N\
o_Julia_Module_With_This_Name package.


##
gap> Julia;
Expand Down

0 comments on commit 9c9aae8

Please sign in to comment.