Skip to content

Commit

Permalink
Compatibility with GAP.jl
Browse files Browse the repository at this point in the history
* Added installation of GAPTypes.jl to configure when compilation
  with Julia is requested
* Made MPtr, Bag, and LargeBag Julia types instances of GapObj
  • Loading branch information
sebasguts authored and fingolfin committed Jun 17, 2019
1 parent ce16a7d commit 69c07d1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,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 ],
Expand Down
5 changes: 5 additions & 0 deletions doc/changes/changes-4.10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ Specify the Julia binary instead of the Julia prefix
Export Julia <C>CFLAGS</C>, <C>LDFLAGS</C>, and <C>LIBS</C> to <C>sysinfo.gap</C>
(<URL><LinkText>&Hash;3248</LinkText><Link>https://github.com/gap-system/gap/pull/3248</Link></URL>).
</Item>
<Item>
Change <C>MPtr</C> Julia type of &GAP; objects to be a subtype of the abstract Julia <C>GapObj</C> type
provided by the Julia package <C>GAPTypes.jl</C>
(<URL><LinkText>&Hash;3497</LinkText><Link>https://github.com/gap-system/gap/pull/3497</Link></URL>).
</Item>
</List>

Improved and extended functionality:
Expand Down
29 changes: 26 additions & 3 deletions src/julia_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,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.
Expand All @@ -828,14 +847,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
Expand Down

0 comments on commit 69c07d1

Please sign in to comment.