From 43ad7afa3544f1024cccf5d46256ce8c8f22af47 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 6 Aug 2026 00:15:02 +0200 Subject: [PATCH] JuliaInterface: remove the unused GAP sync machinery `THREADSAFE_GAP_JL` is never defined, so `BEGIN_GAP_SYNC` and `END_GAP_SYNC` always expanded to no-ops, and `BeginGapSync` and `EndGapSync` were compiled into the kernel extension without ever being declared or called. The one function that did run, `InitGapSync`, merely initialized a mutex nobody locks and set a flag nobody reads. It also declared `extern int jl_n_threads` itself, which since Julia 1.9 conflicts with the `_Atomic(int)` declaration in julia.h. That went unnoticed as long as julia.h was not in scope in this file, but it breaks the build once GAP's src/gasman.h includes julia.h, see gap-system/gap#6490. AI disclosure: Claude Code (Opus 5) diagnosed the issue, drafted the change, and verified it locally. Co-Authored-By: Claude Opus 5 --- pkg/JuliaInterface/Makefile.in | 2 +- pkg/JuliaInterface/src/JuliaInterface.c | 9 ----- pkg/JuliaInterface/src/calls.c | 5 --- pkg/JuliaInterface/src/convert.c | 1 - pkg/JuliaInterface/src/sync.c | 44 ------------------------- pkg/JuliaInterface/src/sync.h | 32 ------------------ 6 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 pkg/JuliaInterface/src/sync.c delete mode 100644 pkg/JuliaInterface/src/sync.h diff --git a/pkg/JuliaInterface/Makefile.in b/pkg/JuliaInterface/Makefile.in index 416f081f9..8261943c4 100644 --- a/pkg/JuliaInterface/Makefile.in +++ b/pkg/JuliaInterface/Makefile.in @@ -4,7 +4,7 @@ KEXT_NAME = JuliaInterface SRCDIR = @SRCDIR@ VPATH += $(SRCDIR) -KEXT_SOURCES = src/JuliaInterface.c src/calls.c src/convert.c src/sync.c +KEXT_SOURCES = src/JuliaInterface.c src/calls.c src/convert.c # include shared GAP package build system GAPPATH = @GAPPATH@ diff --git a/pkg/JuliaInterface/src/JuliaInterface.c b/pkg/JuliaInterface/src/JuliaInterface.c index 9b228834d..aa4c794d2 100644 --- a/pkg/JuliaInterface/src/JuliaInterface.c +++ b/pkg/JuliaInterface/src/JuliaInterface.c @@ -14,7 +14,6 @@ #include "calls.h" #include "convert.h" -#include "sync.h" // With gap 4.15, the header julia_gc.h is available through gap_all.h. // To still support GAP 4.14, we include it conditionally. @@ -44,9 +43,7 @@ void handle_jl_exception(void) jl_value_t * string_object = jl_call1(JULIA_FUNC_take_inplace, JULIA_ERROR_IOBuffer); string_object = jl_array_to_string((jl_array_t *)string_object); - BEGIN_GAP_SYNC(); ErrorMayQuit("%s", (Int)jl_string_data(string_object), 0); - END_GAP_SYNC(); } jl_value_t * gap_box_gapffe(Obj value) @@ -154,11 +151,9 @@ static Obj FuncIS_JULIA_FUNC(Obj self, Obj obj) // Executes the string in the current julia session. static Obj FuncJuliaEvalString(Obj self, Obj string) { - BEGIN_GAP_SYNC(); RequireStringRep("JuliaEvalString", string); jl_value_t * result = jl_eval_string(CONST_CSTR_STRING(string)); - END_GAP_SYNC(); if (jl_exception_occurred()) { handle_jl_exception(); } @@ -179,7 +174,6 @@ static int gap_jl_boundp(jl_module_t * m, jl_sym_t * var) // currently bound to the julia identifier .. static Obj Func_JuliaGetGlobalVariableByModule(Obj self, Obj name, Obj module) { - BEGIN_GAP_SYNC(); RequireStringRep("_JuliaGetGlobalVariableByModule", name); jl_module_t * m = 0; @@ -194,7 +188,6 @@ static Obj Func_JuliaGetGlobalVariableByModule(Obj self, Obj name, Obj module) 0, 0); } jl_sym_t * symbol = jl_symbol(CONST_CSTR_STRING(name)); - END_GAP_SYNC(); #if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR >= 12 // WORKAROUND issue #1132 @@ -278,8 +271,6 @@ static Int InitKernel(StructInitInfo * module) ErrorMayQuit("Could not locate the GAP.FFE datatype", 0, 0); } - InitGapSync(); - // init filters and functions InitHdlrFuncsFromTable(GVarFuncs); diff --git a/pkg/JuliaInterface/src/calls.c b/pkg/JuliaInterface/src/calls.c index cc256fc72..043a0de45 100644 --- a/pkg/JuliaInterface/src/calls.c +++ b/pkg/JuliaInterface/src/calls.c @@ -12,7 +12,6 @@ #include "calls.h" #include "convert.h" -#include "sync.h" #include "JuliaInterface.h" @@ -35,7 +34,6 @@ Obj call_gap_func(Obj func, jl_value_t * args) size_t len = jl_nfields(args); Obj return_value = NULL; - BEGIN_GAP_SYNC(); if (IS_FUNC(func) && len <= 6) { switch (len) { case 0: @@ -85,7 +83,6 @@ Obj call_gap_func(Obj func, jl_value_t * args) } return_value = CallFuncList(func, arg_list); } - END_GAP_SYNC(); return return_value; } @@ -199,7 +196,6 @@ static Obj DoCallJuliaFuncXArg(Obj func, Obj args) // Obj WrapJuliaFunc(jl_value_t * function) { - BEGIN_GAP_SYNC(); Obj name = MakeImmString(jl_symbol_name(jl_gf_name(function))); Obj func = NewFunctionT(T_FUNCTION, sizeof(JuliaFuncBag), name, -1, ArgStringToList("arg"), 0); @@ -225,7 +221,6 @@ Obj WrapJuliaFunc(jl_value_t * function) SET_BODY_FUNC(func, body); CHANGED_BAG(body); CHANGED_BAG(func); - END_GAP_SYNC(); return func; } diff --git a/pkg/JuliaInterface/src/convert.c b/pkg/JuliaInterface/src/convert.c index b2c1b1768..bdf720e16 100644 --- a/pkg/JuliaInterface/src/convert.c +++ b/pkg/JuliaInterface/src/convert.c @@ -12,7 +12,6 @@ #include "convert.h" #include "calls.h" -#include "sync.h" #include "JuliaInterface.h" // Turn a GAP object into a Julia object. diff --git a/pkg/JuliaInterface/src/sync.c b/pkg/JuliaInterface/src/sync.c deleted file mode 100644 index 7e0cd9eec..000000000 --- a/pkg/JuliaInterface/src/sync.c +++ /dev/null @@ -1,44 +0,0 @@ -// -// This file is part of GAP.jl, a bidirectional interface between Julia and -// the GAP computer algebra system. -// -// Copyright of GAP.jl and its parts belongs to its developers. -// Please refer to its README.md file for details. -// -// SPDX-License-Identifier: LGPL-3.0-or-later -// -// Ensure not more than one Julia thread calls into the GAP kernel at a time. -// -// TODO: this is not actually fully implemented!! - -#include "sync.h" -#include -#include - -#ifndef HPCGAP -static pthread_mutex_t GapLock; -static int is_threaded; - -void InitGapSync(void) -{ - extern int jl_n_threads; - is_threaded = jl_n_threads > 1; - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&GapLock, &attr); - pthread_mutexattr_destroy(&attr); -} - -void BeginGapSync(void) -{ - if (is_threaded) - pthread_mutex_lock(&GapLock); -} - -void EndGapSync(void) -{ - if (is_threaded) - pthread_mutex_unlock(&GapLock); -} -#endif diff --git a/pkg/JuliaInterface/src/sync.h b/pkg/JuliaInterface/src/sync.h deleted file mode 100644 index 423a518f9..000000000 --- a/pkg/JuliaInterface/src/sync.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// This file is part of GAP.jl, a bidirectional interface between Julia and -// the GAP computer algebra system. -// -// Copyright of GAP.jl and its parts belongs to its developers. -// Please refer to its README.md file for details. -// -// SPDX-License-Identifier: LGPL-3.0-or-later -// -// Ensure not more than one Julia thread calls into the GAP kernel at a time. -// - -#ifndef JULIAINTERFACE_SYNC_H -#define JULIAINTERFACE_SYNC_H - -// #define THREADSAFE_GAP_JL 1 - -#include - -#if defined(HPCGAP) || !defined(THREADSAFE_GAP_JL) -#define BEGIN_GAP_SYNC() ((void)0) -#define END_GAP_SYNC() ((void)0) -#else -void BeginGapSync(void); -void EndGapSync(void); -#define BEGIN_GAP_SYNC() BeginGapSync() -#define END_GAP_SYNC() EndGapSync() -#endif - -void InitGapSync(void); - -#endif