From 65eb74004f5c62cb0e956886fd1f4cf8a64ffeba Mon Sep 17 00:00:00 2001 From: Risan Date: Sun, 15 Jun 2025 23:40:39 +0900 Subject: [PATCH 1/9] Differentiate gap vs standard lib headers The header io.h from MinGW is hidden by gap's io.h which is causing compilation error. This commit solves the problem by removing gap headers from -I in CPPFLAGS. Instead, we also add a directory extra/ that contains headers to be included by packages. --- Makefile.rules | 25 ++++++++++------- src/common.h | 26 +++++++++++++++++- src/debug.h | 44 ------------------------------ src/extra/compiled.h | 20 ++++++++++++++ src/extra/gap_all.h | 19 +++++++++++++ src/extra/libgap-api.h | 18 +++++++++++++ src/hpc/aobjects.c | 42 ++++++++++++++--------------- src/hpc/aobjects.h | 4 +-- src/hpc/atomic.h | 2 +- src/hpc/cpu.c | 2 +- src/hpc/cpu.h | 2 +- src/hpc/guards.h | 4 +-- src/hpc/misc.c | 2 +- src/hpc/misc.h | 2 +- src/hpc/region.c | 14 +++++----- src/hpc/region.h | 4 +-- src/hpc/serialize.c | 32 +++++++++++----------- src/hpc/serialize.h | 2 +- src/hpc/thread.c | 32 +++++++++++----------- src/hpc/thread.h | 6 ++--- src/hpc/threadapi.c | 56 +++++++++++++++++++-------------------- src/hpc/threadapi.h | 4 +-- src/hpc/tls.c | 4 +-- src/hpc/tls.h | 4 +-- src/hpc/tlsconfig.h | 2 +- src/hpc/traverse.c | 18 ++++++------- src/hpc/traverse.h | 2 +- src/main.c | 10 +------ src/system/system_all.h | 26 ++++++++++++++++++ tst/testkernel/dstruct.c | 4 +-- tst/testlibgap/api.c | 7 +++-- tst/testlibgap/trycatch.c | 2 +- 32 files changed, 251 insertions(+), 190 deletions(-) delete mode 100644 src/debug.h create mode 100644 src/extra/compiled.h create mode 100644 src/extra/gap_all.h create mode 100644 src/extra/libgap-api.h create mode 100644 src/system/system_all.h diff --git a/Makefile.rules b/Makefile.rules index 5a5f61fb33..027b669cc3 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -192,13 +192,10 @@ SYSINFO_CPPFLAGS = GAP_CPPFLAGS += -I$(builddir)/build SYSINFO_CPPFLAGS += -I$(abs_builddir)/build -# The other source files are relative to the srcdir -GAP_CPPFLAGS += -I$(srcdir)/src -SYSINFO_CPPFLAGS += -I$(abs_srcdir)/src - -# For backwards compatibility with certain packages and their kernel -# extensions, also add the root of the srcdir to the package CPPFLAGS -SYSINFO_CPPFLAGS += -I$(abs_srcdir) +# The other source files are bundled and exported through the few +# headers in the extra directory. +GAP_CPPFLAGS += -I$(srcdir)/src/extra -I$(srcdir)/src/system +SYSINFO_CPPFLAGS += -I$(abs_srcdir)/src/extra # Add GAP_DEFINES (from autoconf, contains -D flags) GAP_CPPFLAGS += $(GAP_DEFINES) @@ -405,7 +402,7 @@ DEPFLAGS = -MQ $(OBJFILE) -MMD -MP -MF $(DEPFILE) # DEPFILE and OBJFILE above) ######################################################################## -obj_deps = build/config.h build/version.h $(FFDATA_H) +obj_deps = build/config.h build/version.h $(FFDATA_H) build/common.h # Build rule for C++ source files @@ -548,6 +545,14 @@ ffgen: $(srcdir)/etc/ffgen.c src/common.h build/config.h build/ffdata.h build/ffdata.c: ffgen ./ffgen -b build/ffdata +######################################################################## +# Symlink common.h to the build directory for ffdata.h and version.h +######################################################################## + +build/common.h: $(abs_srcdir)/src/common.h + @$(MKDIR_P) $(@D) + ln -sf $< $@ + ######################################################################## # The "tags" target regenerates the tags file using Exuberant Ctags ######################################################################## @@ -669,7 +674,7 @@ install-gaproot: install-dirs CITATION # the following lines adjust variables for the installed sysinfo.gap -install-sysinfo: SYSINFO_CPPFLAGS = -I${includedir}/gap -I${includedir} $(GAP_DEFINES) +install-sysinfo: SYSINFO_CPPFLAGS = -I${includedir}/gap/extra $(GAP_DEFINES) install-sysinfo: SYSINFO_LDFLAGS = $(ABI_CFLAGS) install-sysinfo: SYSINFO_GAP = $(bindir)/gap install-sysinfo: SYSINFO_GAC = $(bindir)/gac @@ -686,6 +691,8 @@ install-headers: $(FFDATA_H) build/version.h $(INSTALL) -m 0644 $(builddir)/build/version.h $(DESTDIR)$(includedir)/gap $(INSTALL) -d -m 0755 $(DESTDIR)$(includedir)/gap/hpc $(INSTALL) -m 0644 $(srcdir)/src/hpc/*.h $(DESTDIR)$(includedir)/gap/hpc + $(INSTALL) -d -m 0755 $(DESTDIR)$(includedir)/gap/extra + $(INSTALL) -m 0644 $(srcdir)/src/extra/*.h $(DESTDIR)$(includedir)/gap/extra install-libgap: install-dirs $(LIBGAP_FULL) libgap.pc $(INSTALL) -d -m 0755 $(DESTDIR)$(libdir) diff --git a/src/common.h b/src/common.h index 3932c3020b..5855b79856 100644 --- a/src/common.h +++ b/src/common.h @@ -14,7 +14,31 @@ #include #include -#include "debug.h" +// GAP_ASSERT is a version of 'assert' which is enabled by the +// configure option --enable-debug +#ifdef GAP_KERNEL_DEBUG +#define GAP_ASSERT(x) assert(x) + +// Enable various GAP debugging features +#define COUNT_BAGS +#else +#define GAP_ASSERT(x) +#endif + +// Portable compile time assertion. +#if defined(static_assert) +// If available, use _Static_assert resp. static_assert from C11. +#define GAP_STATIC_ASSERT(cond, msg) static_assert(cond, msg) +#else +// If the compiler does not support _Static_assert resp. static_assert, +// fall back to a hack (the error message is a bit ugly in that case). +#define _intern_CONCAT_(X, Y) X ## Y +#define _intern_CONCAT(X, Y) _intern_CONCAT_(X,Y) +#define GAP_STATIC_ASSERT(cond, msg) \ + typedef char _intern_CONCAT(static_assertion_, __LINE__)[(cond)? 1 : -1] +#endif + +void InstallBacktraceHandlers(void); // check if we are on a 64 or 32 bit machine; in the former // case, define SYS_IS_64_BIT. diff --git a/src/debug.h b/src/debug.h deleted file mode 100644 index b618b0ffe4..0000000000 --- a/src/debug.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** This file is part of GAP, a system for computational discrete algebra. -** -** Copyright of GAP belongs to its developers, whose names are too numerous -** to list here. Please refer to the COPYRIGHT file for details. -** -** SPDX-License-Identifier: GPL-2.0-or-later -** -** This file declares kernel debugging functionality. -** -*/ - -#ifndef GAP_DEBUG_H -#define GAP_DEBUG_H - -// GAP_ASSERT is a version of 'assert' which is enabled by the -// configure option --enable-debug -#ifdef GAP_KERNEL_DEBUG -#define GAP_ASSERT(x) assert(x) - -// Enable various GAP debugging features -#define COUNT_BAGS -#else -#define GAP_ASSERT(x) -#endif - -// Portable compile time assertion. -#if defined(static_assert) -// If available, use _Static_assert resp. static_assert from C11. -#define GAP_STATIC_ASSERT(cond, msg) static_assert(cond, msg) -#else -// If the compiler does not support _Static_assert resp. static_assert, -// fall back to a hack (the error message is a bit ugly in that case). -#define _intern_CONCAT_(X, Y) X ## Y -#define _intern_CONCAT(X, Y) _intern_CONCAT_(X,Y) -#define GAP_STATIC_ASSERT(cond, msg) \ - typedef char _intern_CONCAT(static_assertion_, __LINE__)[(cond)? 1 : -1] -#endif - - -void InstallBacktraceHandlers(void); - -#endif diff --git a/src/extra/compiled.h b/src/extra/compiled.h new file mode 100644 index 0000000000..342d79ecf4 --- /dev/null +++ b/src/extra/compiled.h @@ -0,0 +1,20 @@ +/**************************************************************************** +** +** This file is part of GAP, a system for computational discrete algebra. +** +** Copyright of GAP belongs to its developers, whose names are too numerous +** to list here. Please refer to the COPYRIGHT file for details. +** +** SPDX-License-Identifier: GPL-2.0-or-later +** +** This header is provided for backwards compatibility with GAP kernel +** extensions that are not yet using the `gap_all.h` header (available since +** GAP 4.12). Most of these used `compiled.h` instead. +*/ + +#ifndef GAP_EXTRA_COMPILED_H +#define GAP_EXTRA_COMPILED_H + +#include "../compiled.h" + +#endif // GAP_EXTRA_COMPILED_H diff --git a/src/extra/gap_all.h b/src/extra/gap_all.h new file mode 100644 index 0000000000..4c8401ddb0 --- /dev/null +++ b/src/extra/gap_all.h @@ -0,0 +1,19 @@ +/**************************************************************************** +** +** This file is part of GAP, a system for computational discrete algebra. +** +** Copyright of GAP belongs to its developers, whose names are too numerous +** to list here. Please refer to the COPYRIGHT file for details. +** +** SPDX-License-Identifier: GPL-2.0-or-later +** +** This header includes most of the other GAP headers, and is meant to be +** included by GAP kernel extensions. +*/ + +#ifndef GAP_EXTRA_GAP_ALL_H +#define GAP_EXTRA_GAP_ALL_H + +#include "../gap_all.h" + +#endif // GAP_EXTRA_GAP_ALL_H diff --git a/src/extra/libgap-api.h b/src/extra/libgap-api.h new file mode 100644 index 0000000000..9c8358bfb2 --- /dev/null +++ b/src/extra/libgap-api.h @@ -0,0 +1,18 @@ +/**************************************************************************** +** +** This file is part of GAP, a system for computational discrete algebra. +** +** Copyright of GAP belongs to its developers, whose names are too numerous +** to list here. Please refer to the COPYRIGHT file for details. +** +** SPDX-License-Identifier: GPL-2.0-or-later +** +** This header includes LibGAP API, the API for using GAP as shared library. +*/ + +#ifndef GAP_EXTRA_LIBGAP_API_H +#define GAP_EXTRA_LIBGAP_API_H + +#include "../libgap-api.h" + +#endif // GAP_EXTRA_LIBGAP_API_H diff --git a/src/hpc/aobjects.c b/src/hpc/aobjects.c index abb467c9fa..0186e85380 100644 --- a/src/hpc/aobjects.c +++ b/src/hpc/aobjects.c @@ -10,27 +10,27 @@ ** This file contains the GAP interface for thread primitives. */ -#include "hpc/aobjects.h" - -#include "hpc/guards.h" -#include "hpc/thread.h" -#include "hpc/traverse.h" - -#include "ariths.h" -#include "bool.h" -#include "calls.h" -#include "error.h" -#include "fibhash.h" -#include "gaputils.h" -#include "gvars.h" -#include "io.h" -#include "lists.h" -#include "modules.h" -#include "objects.h" -#include "plist.h" -#include "precord.h" -#include "records.h" -#include "stringobj.h" +#include "aobjects.h" + +#include "guards.h" +#include "thread.h" +#include "traverse.h" + +#include "../ariths.h" +#include "../bool.h" +#include "../calls.h" +#include "../error.h" +#include "../fibhash.h" +#include "../gaputils.h" +#include "../gvars.h" +#include "../io.h" +#include "../lists.h" +#include "../modules.h" +#include "../objects.h" +#include "../plist.h" +#include "../precord.h" +#include "../records.h" +#include "../stringobj.h" #include // for labs diff --git a/src/hpc/aobjects.h b/src/hpc/aobjects.h index c5516b5486..0938f12c9a 100644 --- a/src/hpc/aobjects.h +++ b/src/hpc/aobjects.h @@ -11,8 +11,8 @@ #ifndef GAP_AOBJECTS_H #define GAP_AOBJECTS_H -#include "objects.h" -#include "hpc/atomic.h" +#include "../objects.h" +#include "atomic.h" #ifndef HPCGAP #error This header is only meant to be used with HPC-GAP diff --git a/src/hpc/atomic.h b/src/hpc/atomic.h index dcb96979e0..00d2c8b113 100644 --- a/src/hpc/atomic.h +++ b/src/hpc/atomic.h @@ -11,7 +11,7 @@ #ifndef GAP_ATOMIC_H #define GAP_ATOMIC_H -#include "common.h" +#include "../common.h" #ifndef HPCGAP #error This header is only meant to be used with HPC-GAP diff --git a/src/hpc/cpu.c b/src/hpc/cpu.c index e28f8f3b12..c99bb9cb96 100644 --- a/src/hpc/cpu.c +++ b/src/hpc/cpu.c @@ -8,7 +8,7 @@ ** SPDX-License-Identifier: GPL-2.0-or-later */ -#include "hpc/cpu.h" +#include "cpu.h" #include diff --git a/src/hpc/cpu.h b/src/hpc/cpu.h index 8750913306..7cbabd55c8 100644 --- a/src/hpc/cpu.h +++ b/src/hpc/cpu.h @@ -11,7 +11,7 @@ #ifndef GAP_HPC_CPU_H #define GAP_HPC_CPU_H -#include "common.h" +#include "../common.h" #ifndef HPCGAP #error This header is only meant to be used with HPC-GAP diff --git a/src/hpc/guards.h b/src/hpc/guards.h index 8e04e6a95a..b22572843e 100644 --- a/src/hpc/guards.h +++ b/src/hpc/guards.h @@ -11,8 +11,8 @@ #ifndef GAP_HPC_GUARD_H #define GAP_HPC_GUARD_H -#include "hpc/region.h" -#include "hpc/tls.h" +#include "region.h" +#include "tls.h" #ifndef HPCGAP #error This header is only meant to be used with HPC-GAP diff --git a/src/hpc/misc.c b/src/hpc/misc.c index a7b962adea..29cb8d0629 100644 --- a/src/hpc/misc.c +++ b/src/hpc/misc.c @@ -8,7 +8,7 @@ ** SPDX-License-Identifier: GPL-2.0-or-later */ -#include "hpc/misc.h" +#include "misc.h" #include #include diff --git a/src/hpc/misc.h b/src/hpc/misc.h index 124d76e390..8d7388c389 100644 --- a/src/hpc/misc.h +++ b/src/hpc/misc.h @@ -11,7 +11,7 @@ #ifndef GAP_HPC_MISC_H #define GAP_HPC_MISC_H -#include "common.h" +#include "../common.h" #ifndef HPCGAP #error This header is only meant to be used with HPC-GAP diff --git a/src/hpc/region.c b/src/hpc/region.c index 2838571991..4569c0bb96 100644 --- a/src/hpc/region.c +++ b/src/hpc/region.c @@ -8,17 +8,17 @@ ** SPDX-License-Identifier: GPL-2.0-or-later */ -#include "hpc/region.h" +#include "region.h" #ifdef USE_BOEHM_GC -#include "boehm_gc.h" +#include "../boehm_gc.h" #endif -#include "gasman.h" -#include "objects.h" +#include "../gasman.h" +#include "../objects.h" -// #include "hpc/misc.h" -#include "hpc/thread.h" -#include "hpc/guards.h" +// #include "misc.h" +#include "thread.h" +#include "guards.h" #include diff --git a/src/hpc/region.h b/src/hpc/region.h index beb4337cda..f5ade0c159 100644 --- a/src/hpc/region.h +++ b/src/hpc/region.h @@ -11,13 +11,13 @@ #ifndef GAP_REGION_H #define GAP_REGION_H -#include "common.h" +#include "../common.h" #ifndef HPCGAP #error This header is only meant to be used with HPC-GAP #endif -#include "hpc/atomic.h" +#include "atomic.h" typedef struct Region Region; diff --git a/src/hpc/serialize.c b/src/hpc/serialize.c index 4ac2904df9..3dcd730d93 100644 --- a/src/hpc/serialize.c +++ b/src/hpc/serialize.c @@ -8,22 +8,22 @@ ** SPDX-License-Identifier: GPL-2.0-or-later */ -#include "hpc/serialize.h" - -#include "bool.h" -#include "calls.h" -#include "error.h" -#include "gvars.h" -#include "modules.h" -#include "objset.h" -#include "plist.h" -#include "precord.h" -#include "rational.h" -#include "records.h" -#include "stringobj.h" -#include "trycatch.h" - -#include "hpc/aobjects.h" +#include "serialize.h" + +#include "../bool.h" +#include "../calls.h" +#include "../error.h" +#include "../gvars.h" +#include "../modules.h" +#include "../objset.h" +#include "../plist.h" +#include "../precord.h" +#include "../rational.h" +#include "../records.h" +#include "../stringobj.h" +#include "../trycatch.h" + +#include "aobjects.h" #include diff --git a/src/hpc/serialize.h b/src/hpc/serialize.h index 11e77b0222..3ad8d6effd 100644 --- a/src/hpc/serialize.h +++ b/src/hpc/serialize.h @@ -11,7 +11,7 @@ #ifndef GAP_SERIALIZE_H #define GAP_SERIALIZE_H -#include "common.h" +#include "../common.h" typedef struct SerializerState SerializerState; typedef struct DeserializerState DeserializerState; diff --git a/src/hpc/thread.c b/src/hpc/thread.c index e63e1ebe4c..420074bf93 100644 --- a/src/hpc/thread.c +++ b/src/hpc/thread.c @@ -8,22 +8,22 @@ ** SPDX-License-Identifier: GPL-2.0-or-later */ -#include "hpc/thread.h" - -#include "code.h" -#include "error.h" -#include "fibhash.h" -#include "gapstate.h" -#include "gvars.h" -#include "modules.h" -#include "plist.h" -#include "stats.h" -#include "stringobj.h" -#include "vars.h" - -#include "hpc/guards.h" -#include "hpc/misc.h" -#include "hpc/threadapi.h" +#include "thread.h" + +#include "../code.h" +#include "../error.h" +#include "../fibhash.h" +#include "../gapstate.h" +#include "../gvars.h" +#include "../modules.h" +#include "../plist.h" +#include "../stats.h" +#include "../stringobj.h" +#include "../vars.h" + +#include "guards.h" +#include "misc.h" +#include "threadapi.h" #include #include diff --git a/src/hpc/thread.h b/src/hpc/thread.h index d5b5007ba3..1b0b39b2c1 100644 --- a/src/hpc/thread.h +++ b/src/hpc/thread.h @@ -11,7 +11,7 @@ #ifndef GAP_THREAD_H #define GAP_THREAD_H -#include "common.h" +#include "../common.h" #if !defined(HPCGAP) @@ -26,8 +26,8 @@ #else -#include "hpc/tlsconfig.h" -#include "hpc/region.h" +#include "tlsconfig.h" +#include "region.h" // Maximum number of threads excluding the main thread #define MAX_THREADS 1023 diff --git a/src/hpc/threadapi.c b/src/hpc/threadapi.c index 9ff14e2591..0a11e5e1cc 100644 --- a/src/hpc/threadapi.c +++ b/src/hpc/threadapi.c @@ -10,34 +10,34 @@ ** This file contains the GAP interface for thread primitives. */ -#include "hpc/threadapi.h" - -#include "bool.h" -#include "calls.h" -#include "code.h" -#include "error.h" -#include "funcs.h" -#include "gvars.h" -#include "io.h" -#include "lists.h" -#include "modules.h" -#include "objects.h" -#include "plist.h" -#include "precord.h" -#include "read.h" -#include "records.h" -#include "set.h" -#include "stats.h" -#include "stringobj.h" -#include "trycatch.h" -#include "vars.h" - -#include "hpc/guards.h" -#include "hpc/misc.h" -#include "hpc/region.h" -#include "hpc/thread.h" -#include "hpc/tls.h" -#include "hpc/traverse.h" +#include "threadapi.h" + +#include "../bool.h" +#include "../calls.h" +#include "../code.h" +#include "../error.h" +#include "../funcs.h" +#include "../gvars.h" +#include "../io.h" +#include "../lists.h" +#include "../modules.h" +#include "../objects.h" +#include "../plist.h" +#include "../precord.h" +#include "../read.h" +#include "../records.h" +#include "../set.h" +#include "../stats.h" +#include "../stringobj.h" +#include "../trycatch.h" +#include "../vars.h" + +#include "guards.h" +#include "misc.h" +#include "region.h" +#include "thread.h" +#include "tls.h" +#include "traverse.h" #include #include diff --git a/src/hpc/threadapi.h b/src/hpc/threadapi.h index 5e064f03cd..5f136ba94d 100644 --- a/src/hpc/threadapi.h +++ b/src/hpc/threadapi.h @@ -11,9 +11,9 @@ #ifndef GAP_THREADAPI_H #define GAP_THREADAPI_H -#include "objects.h" +#include "../objects.h" -#include "gvars.h" +#include "../gvars.h" #include diff --git a/src/hpc/tls.c b/src/hpc/tls.c index 2f831f6ef2..49e621a436 100644 --- a/src/hpc/tls.c +++ b/src/hpc/tls.c @@ -8,8 +8,8 @@ ** SPDX-License-Identifier: GPL-2.0-or-later */ -#include "gapstate.h" -#include "hpc/thread.h" +#include "../gapstate.h" +#include "thread.h" #include diff --git a/src/hpc/tls.h b/src/hpc/tls.h index 80ee594c81..113264c576 100644 --- a/src/hpc/tls.h +++ b/src/hpc/tls.h @@ -11,7 +11,7 @@ #ifndef GAP_TLS_H #define GAP_TLS_H -#include "system.h" +#include "../system.h" #if !defined(HPCGAP) #error This header is only meant to be used with HPC-GAP @@ -60,7 +60,7 @@ // assembly code for pthread_getspecific() is implemented in a way // consistent with such code. -#include "hpc/tlsconfig.h" +#include "tlsconfig.h" #include diff --git a/src/hpc/tlsconfig.h b/src/hpc/tlsconfig.h index d2b6fad6ee..7c8caed57a 100644 --- a/src/hpc/tlsconfig.h +++ b/src/hpc/tlsconfig.h @@ -11,7 +11,7 @@ #ifndef GAP_TLSCONFIG_H #define GAP_TLSCONFIG_H -#include "common.h" +#include "../common.h" #if !defined(HPCGAP) #error This header is only meant to be used with HPC-GAP diff --git a/src/hpc/traverse.c b/src/hpc/traverse.c index 9a3900b28d..864ef5a13b 100644 --- a/src/hpc/traverse.c +++ b/src/hpc/traverse.c @@ -11,17 +11,17 @@ /* * Functionality to traverse nested object structures. */ -#include "hpc/traverse.h" +#include "traverse.h" -#include "bool.h" -#include "error.h" -#include "fibhash.h" -#include "gaputils.h" -#include "modules.h" -#include "plist.h" +#include "../bool.h" +#include "../error.h" +#include "../fibhash.h" +#include "../gaputils.h" +#include "../modules.h" +#include "../plist.h" -#include "hpc/guards.h" -#include "hpc/thread.h" +#include "guards.h" +#include "thread.h" #ifndef WARD_ENABLED diff --git a/src/hpc/traverse.h b/src/hpc/traverse.h index e75dac0b8c..5b5989f033 100644 --- a/src/hpc/traverse.h +++ b/src/hpc/traverse.h @@ -11,7 +11,7 @@ #ifndef GAP_TRAVERSE_H #define GAP_TRAVERSE_H -#include "common.h" +#include "../common.h" typedef struct TraversalState TraversalState; diff --git a/src/main.c b/src/main.c index 69d5e3dd95..c2e68525ea 100644 --- a/src/main.c +++ b/src/main.c @@ -9,16 +9,8 @@ */ #include "common.h" -#include "sysfiles.h" -#include "sysroots.h" -#include "sysstr.h" -#include "system.h" - -#ifdef HPCGAP -#include "hpc/thread.h" -#endif - #include "config.h" +#include "system_all.h" #include // for getenv, realpath, ... #include // for snprintf diff --git a/src/system/system_all.h b/src/system/system_all.h new file mode 100644 index 0000000000..5364b44f34 --- /dev/null +++ b/src/system/system_all.h @@ -0,0 +1,26 @@ +/**************************************************************************** +** +** This file is part of GAP, a system for computational discrete algebra. +** +** Copyright of GAP belongs to its developers, whose names are too numerous +** to list here. Please refer to the COPYRIGHT file for details. +** +** SPDX-License-Identifier: GPL-2.0-or-later +** +** This header includes the system GAP headers, and is meant to be used only +** by main.c. +*/ + +#ifndef GAP_SYSTEM_SYSTEM_ALL_H +#define GAP_SYSTEM_SYSTEM_ALL_H + +#include "../sysfiles.h" +#include "../sysroots.h" +#include "../sysstr.h" +#include "../system.h" + +#ifdef HPCGAP +#include "../hpc/thread.h" +#endif + +#endif // GAP_SYSTEM_SYSTEM_ALL_H diff --git a/tst/testkernel/dstruct.c b/tst/testkernel/dstruct.c index d219dd3b1b..0da28f7d19 100644 --- a/tst/testkernel/dstruct.c +++ b/tst/testkernel/dstruct.c @@ -15,7 +15,7 @@ static int int_cmp(int a, int b) #define ELEM_TYPE int #define COMPARE int_cmp -#include "baltree.h" +#include "gap/baltree.h" void ShowTree(intTree * btree) { @@ -84,7 +84,7 @@ void TestScapegoatTrees(void) #define ELEM_TYPE int #define COMPARE int_cmp -#include "dynarray.h" +#include "gap/dynarray.h" void ShowArray(intArray * arr) { diff --git a/tst/testlibgap/api.c b/tst/testlibgap/api.c index ab232cf4ca..f2f6cc81db 100644 --- a/tst/testlibgap/api.c +++ b/tst/testlibgap/api.c @@ -11,7 +11,6 @@ */ #include "common.h" -#include "intobj.h" #include @@ -100,7 +99,7 @@ void matrices(void) Obj mat, val, row, ret; mat = GAP_NewPlist(1); - val = INTOBJ_INT(42); + val = GAP_NewObjIntFromInt(42); assert(!GAP_IsMatrixOrMatrixObj(mat)); // empty list, not yet a matrix assert(!GAP_IsMatrixObj(mat)); @@ -113,8 +112,8 @@ void matrices(void) assert(!GAP_IsMatrix(val)); row = GAP_NewPlist(2); - GAP_AssList(row, 1, INTOBJ_INT(1)); - GAP_AssList(row, 2, INTOBJ_INT(2)); + GAP_AssList(row, 1, GAP_NewObjIntFromInt(1)); + GAP_AssList(row, 2, GAP_NewObjIntFromInt(2)); GAP_AssList(mat, 1, row); assert(!GAP_IsMatrixOrMatrixObj(row)); assert(!GAP_IsMatrixObj(row)); diff --git a/tst/testlibgap/trycatch.c b/tst/testlibgap/trycatch.c index 55dd1e781d..393bd298f7 100644 --- a/tst/testlibgap/trycatch.c +++ b/tst/testlibgap/trycatch.c @@ -1,7 +1,7 @@ /* * Small program to test libgap linkability and basic working */ -#include "trycatch.h" +#include "gap_all.h" #include "common.h" static int level = 0; From 9bfbda221eaa803869675e5f41656f6f4157ea8c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 12 Jul 2025 02:01:50 +0200 Subject: [PATCH 2/9] Simplify main.c handling again --- Makefile.rules | 6 +++--- src/main.c | 10 +++++++++- src/system/system_all.h | 26 -------------------------- 3 files changed, 12 insertions(+), 30 deletions(-) delete mode 100644 src/system/system_all.h diff --git a/Makefile.rules b/Makefile.rules index 027b669cc3..da1a51a0bf 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -194,7 +194,7 @@ SYSINFO_CPPFLAGS += -I$(abs_builddir)/build # The other source files are bundled and exported through the few # headers in the extra directory. -GAP_CPPFLAGS += -I$(srcdir)/src/extra -I$(srcdir)/src/system +GAP_CPPFLAGS += -I$(srcdir)/src/extra SYSINFO_CPPFLAGS += -I$(abs_srcdir)/src/extra # Add GAP_DEFINES (from autoconf, contains -D flags) @@ -511,9 +511,9 @@ gap$(EXEEXT): build/obj/src/main.c.o $(OBJS) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GA $(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) $< $(OBJS) $(GAP_LIBS) -o $@ # generate a modified copy of main.c for use by the `gap-install` binary -build/main.c: src/main.c config.status +build/main.c: sysinfo.gap @echo "#define SYS_DEFAULT_PATHS \"$(libdir)/gap;$(datarootdir)/gap\"" > $@ - @cat $< >> $@ + @echo "#include \"$(abs_srcdir)/src/main.c\"" > $@ # build rule for the gap executable used by the `install-bin` target build/gap-install: build/obj/build/main.c.o libgap$(SHLIB_EXT) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS diff --git a/src/main.c b/src/main.c index c2e68525ea..69d5e3dd95 100644 --- a/src/main.c +++ b/src/main.c @@ -9,8 +9,16 @@ */ #include "common.h" +#include "sysfiles.h" +#include "sysroots.h" +#include "sysstr.h" +#include "system.h" + +#ifdef HPCGAP +#include "hpc/thread.h" +#endif + #include "config.h" -#include "system_all.h" #include // for getenv, realpath, ... #include // for snprintf diff --git a/src/system/system_all.h b/src/system/system_all.h deleted file mode 100644 index 5364b44f34..0000000000 --- a/src/system/system_all.h +++ /dev/null @@ -1,26 +0,0 @@ -/**************************************************************************** -** -** This file is part of GAP, a system for computational discrete algebra. -** -** Copyright of GAP belongs to its developers, whose names are too numerous -** to list here. Please refer to the COPYRIGHT file for details. -** -** SPDX-License-Identifier: GPL-2.0-or-later -** -** This header includes the system GAP headers, and is meant to be used only -** by main.c. -*/ - -#ifndef GAP_SYSTEM_SYSTEM_ALL_H -#define GAP_SYSTEM_SYSTEM_ALL_H - -#include "../sysfiles.h" -#include "../sysroots.h" -#include "../sysstr.h" -#include "../system.h" - -#ifdef HPCGAP -#include "../hpc/thread.h" -#endif - -#endif // GAP_SYSTEM_SYSTEM_ALL_H From 24e75382ddd113ec94ec7b87b5eca1803b6c8818 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 12 Jul 2025 02:07:36 +0200 Subject: [PATCH 3/9] Change ffdata to not use common.h --- etc/ffgen.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/etc/ffgen.c b/etc/ffgen.c index 0b225cad96..c002e9a39d 100644 --- a/etc/ffgen.c +++ b/etc/ffgen.c @@ -62,7 +62,7 @@ void emit_code(FILE * dest, int header) fprintf(dest, "#ifndef GAP_FFDATA_H\n"); fprintf(dest, "#define GAP_FFDATA_H\n"); fprintf(dest, "\n"); - fprintf(dest, "#include \"common.h\"\n"); + fprintf(dest, "#include \n"); fprintf(dest, "\n"); fprintf(dest, "enum {\n"); fprintf(dest, " NUM_SHORT_FINITE_FIELDS = %d,\n", num_ff); @@ -72,18 +72,18 @@ void emit_code(FILE * dest, int header) fprintf(dest, " VAL_BITS_FFE = %d\n", needed_bits(MAX_FF - 1)); fprintf(dest, "};\n"); fprintf(dest, "\n"); - fprintf(dest, "extern const UInt4 SizeFF[NUM_SHORT_FINITE_FIELDS+1];\n"); - fprintf(dest, "extern const UInt1 DegrFF[NUM_SHORT_FINITE_FIELDS+1];\n"); - fprintf(dest, "extern const UInt4 CharFF[NUM_SHORT_FINITE_FIELDS+1];\n"); + fprintf(dest, "extern const uint32_t SizeFF[NUM_SHORT_FINITE_FIELDS+1];\n"); + fprintf(dest, "extern const uint8_t DegrFF[NUM_SHORT_FINITE_FIELDS+1];\n"); + fprintf(dest, "extern const uint32_t CharFF[NUM_SHORT_FINITE_FIELDS+1];\n"); fprintf(dest, "\n"); if (num_ff < 65536) - fprintf(dest, "typedef UInt2 FF;\n"); + fprintf(dest, "typedef uint16_t FF;\n"); else - fprintf(dest, "typedef UInt4 FF;\n"); + fprintf(dest, "typedef uint32_t FF;\n"); if (MAX_FF <= 65536) - fprintf(dest, "typedef UInt2 FFV;\n"); + fprintf(dest, "typedef uint16_t FFV;\n"); else - fprintf(dest, "typedef UInt4 FFV;\n"); + fprintf(dest, "typedef uint32_t FFV;\n"); fprintf(dest, "\n"); fprintf(dest, "#endif // GAP_FFDATA_H\n"); } @@ -94,7 +94,7 @@ void emit_code(FILE * dest, int header) fprintf(dest, " * to find them. Indices start at 1.\n"); fprintf(dest, " */\n"); fprintf(dest, "\n"); - fprintf(dest, "const UInt1 DegrFF[NUM_SHORT_FINITE_FIELDS+1] = {\n"); + fprintf(dest, "const uint8_t DegrFF[NUM_SHORT_FINITE_FIELDS+1] = {\n"); fprintf(dest, " %3d,", 0); for (i = 0, j = 1; i <= MAX_FF; i++) { if (is_ff[i]) { @@ -109,7 +109,7 @@ void emit_code(FILE * dest, int header) fprintf(dest, "\n"); fprintf(dest, "};\n"); fprintf(dest, "\n"); - fprintf(dest, "const UInt4 CharFF[NUM_SHORT_FINITE_FIELDS+1] = {\n"); + fprintf(dest, "const uint32_t CharFF[NUM_SHORT_FINITE_FIELDS+1] = {\n"); fprintf(dest, " %9d,", 0); for (i = 0, j = 1; i <= MAX_FF; i++) { if (is_ff[i]) { @@ -124,7 +124,7 @@ void emit_code(FILE * dest, int header) fprintf(dest, "\n"); fprintf(dest, "};\n"); fprintf(dest, "\n"); - fprintf(dest, "const UInt4 SizeFF[NUM_SHORT_FINITE_FIELDS+1] = {\n"); + fprintf(dest, "const uint32_t SizeFF[NUM_SHORT_FINITE_FIELDS+1] = {\n"); fprintf(dest, " %9d,", 0); for (i = 0, j = 1; i <= MAX_FF; i++) { if (is_ff[i]) { From 1bba54a1999fe8af6ffc69d9fcba4d57358cfadc Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 12 Jul 2025 02:09:07 +0200 Subject: [PATCH 4/9] Don't include common.h in version.h --- src/version.h.in | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/version.h.in b/src/version.h.in index ced22cc7b7..1a8f835589 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -13,9 +13,6 @@ #ifndef GAP_VERSION_H #define GAP_VERSION_H -#include "common.h" - - /**************************************************************************** ** ** GAP_KERNEL_MAJOR_VERSION From c8dd1e13506b98e32060d70f39c08b9c2e91761e Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 12 Jul 2025 02:09:55 +0200 Subject: [PATCH 5/9] No need for build/common.h symlink anymore --- Makefile.rules | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Makefile.rules b/Makefile.rules index da1a51a0bf..3885f6d1c9 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -402,7 +402,7 @@ DEPFLAGS = -MQ $(OBJFILE) -MMD -MP -MF $(DEPFILE) # DEPFILE and OBJFILE above) ######################################################################## -obj_deps = build/config.h build/version.h $(FFDATA_H) build/common.h +obj_deps = build/config.h build/version.h $(FFDATA_H) # Build rule for C++ source files @@ -539,20 +539,12 @@ build/c_%.c: $(srcdir)/lib/%.g build/gap-nocomp$(EXEEXT) # The "ffdata" target regenerates build/ffdata.{c,h} using etc/ffgen.c ######################################################################## -ffgen: $(srcdir)/etc/ffgen.c src/common.h build/config.h +ffgen: $(srcdir)/etc/ffgen.c build/config.h $(QUIET_CC)$(CC) -Wall -Wextra $(GAP_CPPFLAGS) $< -o $@ build/ffdata.h build/ffdata.c: ffgen ./ffgen -b build/ffdata -######################################################################## -# Symlink common.h to the build directory for ffdata.h and version.h -######################################################################## - -build/common.h: $(abs_srcdir)/src/common.h - @$(MKDIR_P) $(@D) - ln -sf $< $@ - ######################################################################## # The "tags" target regenerates the tags file using Exuberant Ctags ######################################################################## From 4eb1b46dc7f0ed45def1aeade80003039f1773b0 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 12 Jul 2025 02:14:43 +0200 Subject: [PATCH 6/9] Restore debug.h --- src/common.h | 26 +------------------------- src/debug.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 src/debug.h diff --git a/src/common.h b/src/common.h index 5855b79856..3932c3020b 100644 --- a/src/common.h +++ b/src/common.h @@ -14,31 +14,7 @@ #include #include -// GAP_ASSERT is a version of 'assert' which is enabled by the -// configure option --enable-debug -#ifdef GAP_KERNEL_DEBUG -#define GAP_ASSERT(x) assert(x) - -// Enable various GAP debugging features -#define COUNT_BAGS -#else -#define GAP_ASSERT(x) -#endif - -// Portable compile time assertion. -#if defined(static_assert) -// If available, use _Static_assert resp. static_assert from C11. -#define GAP_STATIC_ASSERT(cond, msg) static_assert(cond, msg) -#else -// If the compiler does not support _Static_assert resp. static_assert, -// fall back to a hack (the error message is a bit ugly in that case). -#define _intern_CONCAT_(X, Y) X ## Y -#define _intern_CONCAT(X, Y) _intern_CONCAT_(X,Y) -#define GAP_STATIC_ASSERT(cond, msg) \ - typedef char _intern_CONCAT(static_assertion_, __LINE__)[(cond)? 1 : -1] -#endif - -void InstallBacktraceHandlers(void); +#include "debug.h" // check if we are on a 64 or 32 bit machine; in the former // case, define SYS_IS_64_BIT. diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000000..b618b0ffe4 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** This file is part of GAP, a system for computational discrete algebra. +** +** Copyright of GAP belongs to its developers, whose names are too numerous +** to list here. Please refer to the COPYRIGHT file for details. +** +** SPDX-License-Identifier: GPL-2.0-or-later +** +** This file declares kernel debugging functionality. +** +*/ + +#ifndef GAP_DEBUG_H +#define GAP_DEBUG_H + +// GAP_ASSERT is a version of 'assert' which is enabled by the +// configure option --enable-debug +#ifdef GAP_KERNEL_DEBUG +#define GAP_ASSERT(x) assert(x) + +// Enable various GAP debugging features +#define COUNT_BAGS +#else +#define GAP_ASSERT(x) +#endif + +// Portable compile time assertion. +#if defined(static_assert) +// If available, use _Static_assert resp. static_assert from C11. +#define GAP_STATIC_ASSERT(cond, msg) static_assert(cond, msg) +#else +// If the compiler does not support _Static_assert resp. static_assert, +// fall back to a hack (the error message is a bit ugly in that case). +#define _intern_CONCAT_(X, Y) X ## Y +#define _intern_CONCAT(X, Y) _intern_CONCAT_(X,Y) +#define GAP_STATIC_ASSERT(cond, msg) \ + typedef char _intern_CONCAT(static_assertion_, __LINE__)[(cond)? 1 : -1] +#endif + + +void InstallBacktraceHandlers(void); + +#endif From 9998b19cadddc56362e36fae138660f1c0d08aa1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 12 Jul 2025 02:21:04 +0200 Subject: [PATCH 7/9] extend comment --- Makefile.rules | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.rules b/Makefile.rules index 3885f6d1c9..5791597a80 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -192,8 +192,11 @@ SYSINFO_CPPFLAGS = GAP_CPPFLAGS += -I$(builddir)/build SYSINFO_CPPFLAGS += -I$(abs_builddir)/build -# The other source files are bundled and exported through the few -# headers in the extra directory. +# The other source files are bundled and exported through the few headers in +# the `src/extra/` directory. We deliberately do not add `src/` itself as an +# include directory to improve portability: it helps avoid clashes between our +# headers and system headers (e.g. for `io.h` this would otherwise be a +# problem on MinGW). GAP_CPPFLAGS += -I$(srcdir)/src/extra SYSINFO_CPPFLAGS += -I$(abs_srcdir)/src/extra From dc98c90dfa9befedf57425fd7b296aa2034b9589 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 12 Jul 2025 02:26:52 +0200 Subject: [PATCH 8/9] oops --- Makefile.rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.rules b/Makefile.rules index 5791597a80..b637036d4b 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -516,7 +516,7 @@ gap$(EXEEXT): build/obj/src/main.c.o $(OBJS) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GA # generate a modified copy of main.c for use by the `gap-install` binary build/main.c: sysinfo.gap @echo "#define SYS_DEFAULT_PATHS \"$(libdir)/gap;$(datarootdir)/gap\"" > $@ - @echo "#include \"$(abs_srcdir)/src/main.c\"" > $@ + @echo "#include \"$(abs_srcdir)/src/main.c\"" >> $@ # build rule for the gap executable used by the `install-bin` target build/gap-install: build/obj/build/main.c.o libgap$(SHLIB_EXT) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS From 272ecabc52ad856cc0498940bf18f1855e043b1c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 12 Jul 2025 19:25:33 +0200 Subject: [PATCH 9/9] update comment --- Makefile.rules | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.rules b/Makefile.rules index b637036d4b..f69cf6e172 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -513,7 +513,8 @@ libgap$(SHLIB_EXT): $(LIBGAP_FULL) gap$(EXEEXT): build/obj/src/main.c.o $(OBJS) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS $(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) $< $(OBJS) $(GAP_LIBS) -o $@ -# generate a modified copy of main.c for use by the `gap-install` binary +# generate a special main.c which sets SYS_DEFAULT_PATHS and then includes +# regular main.c; this is used to build the `gap-install` binary build/main.c: sysinfo.gap @echo "#define SYS_DEFAULT_PATHS \"$(libdir)/gap;$(datarootdir)/gap\"" > $@ @echo "#include \"$(abs_srcdir)/src/main.c\"" >> $@