From df86a3609181328d9b33a47f46ae27f8afd83a83 Mon Sep 17 00:00:00 2001 From: Sebastian Gutsche Date: Wed, 12 Jun 2019 22:07:41 +0200 Subject: [PATCH] Compatibility with GAP.jl * Added installation of GAPTypes.jl to configure when compilation with Julia is requested * Made MPtr, Bag, and LargeBag Julia types instances of GapObj --- configure.ac | 3 +++ doc/changes/changes-4.10.xml | 5 +++++ src/julia_gc.c | 29 ++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index be43d2e1e1..59003fed8e 100644 --- a/configure.ac +++ b/configure.ac @@ -534,6 +534,9 @@ AS_IF([test "x$with_julia" != xno ],[ AS_IF([ test $? != 0 ], [AC_MSG_ERROR([failed to obtain JULIA_LIBS from julia-config.jl])]) JULIA_LIBS=${JULIA_LIBS//\'/} AC_MSG_RESULT([${JULIA_LIBS}]) + AC_MSG_NOTICE([installing GAPTypes.jl]) + ${JULIA} -e 'import Pkg; Pkg.add("GAPTypes")' + AS_IF([ test $? != 0 ], [AC_MSG_ERROR([failed to install GAPTypes.jl])]) ], [ AS_IF( [ test "x$with_gc" = xjulia ], diff --git a/doc/changes/changes-4.10.xml b/doc/changes/changes-4.10.xml index 209cae142a..9bd71da7d2 100644 --- a/doc/changes/changes-4.10.xml +++ b/doc/changes/changes-4.10.xml @@ -668,6 +668,11 @@ Specify the Julia binary instead of the Julia prefix Export Julia CFLAGS, LDFLAGS, and LIBS to sysinfo.gap (&Hash;3248https://github.com/gap-system/gap/pull/3248). + +Change MPtr Julia type of ⪆ objects to be a subtype of the abstract Julia GapObj type +provided by the Julia package GAPTypes.jl +(&Hash;3497https://github.com/gap-system/gap/pull/3497). + Improved and extended functionality: diff --git a/src/julia_gc.c b/src/julia_gc.c index b42c32383d..f2d48036ba 100644 --- a/src/julia_gc.c +++ b/src/julia_gc.c @@ -816,6 +816,25 @@ void InitBags(UInt initial_size, Bag * stack_bottom, UInt stack_align) max_pool_obj_size = jl_gc_max_internal_obj_size(); jl_gc_enable_conservative_gc_support(); jl_init(); + + // Import GAPTypes module to have access to GapObj abstract type. + // Needs to be done before setting any GC states + jl_eval_string("import GAPTypes"); + if (jl_exception_occurred()) { + Panic("could not import GAPTypes module into Julia"); + } + // Get GapObj abstract julia type + jl_module_t * gaptypes_module = + (jl_module_t *)jl_get_global(jl_main_module, jl_symbol("GAPTypes")); + if (jl_exception_occurred()) { + Panic("Could not read global GAPTypes variable from Julia"); + } + jl_datatype_t * gapobj_type = + (jl_datatype_t *)jl_get_global(gaptypes_module, jl_symbol("GapObj")); + if (jl_exception_occurred()) { + Panic("could not read GapObj variable from Julia"); + } + JuliaTLS = jl_get_ptls_states(); // These callbacks potentially require access to the Julia // TLS and thus need to be installed after initialization. @@ -827,14 +846,18 @@ void InitBags(UInt initial_size, Bag * stack_bottom, UInt stack_align) Module = jl_new_module(jl_symbol("ForeignGAP")); Module->parent = jl_main_module; + + // Import GapObj type into ForeignGAP module + jl_module_use(Module, gaptypes_module, jl_symbol("GapObj")); + jl_set_const(jl_main_module, jl_symbol("ForeignGAP"), (jl_value_t *)Module); datatype_mptr = jl_new_foreign_type( - jl_symbol("MPtr"), Module, jl_any_type, MPtrMarkFunc, NULL, 1, 0); - datatype_bag = jl_new_foreign_type(jl_symbol("Bag"), Module, jl_any_type, + jl_symbol("MPtr"), Module, gapobj_type, MPtrMarkFunc, NULL, 1, 0); + datatype_bag = jl_new_foreign_type(jl_symbol("Bag"), Module, gapobj_type, BagMarkFunc, JFinalizer, 1, 0); datatype_largebag = - jl_new_foreign_type(jl_symbol("LargeBag"), Module, jl_any_type, + jl_new_foreign_type(jl_symbol("LargeBag"), Module, gapobj_type, BagMarkFunc, JFinalizer, 1, 1); // export datatypes to Julia level