From c4d3711c6e4bb2f9207fd97deff00b8f64cedf06 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 1 Jul 2022 00:52:01 +0200 Subject: [PATCH] Avoid using InstallValue on non-plain objects InstallValue and friends are the only reason we need the somewhat dangerous kernel function `CLONE_OBJ`. It has known issues when used on e.g. families (which we already try to reject) and types. If we can eliminate all uses of it on component and positional objects, then we could potentially replace it by a simpler implementation (which would reject attempts to use it on such non-plain objects), which would also help avoid pitfalls in HPC-GAP. --- lib/cyclotom.gi | 18 ++++++++++++++++++ lib/fldabnum.gd | 4 ++-- lib/fldabnum.gi | 18 ------------------ lib/random.gd | 4 ++-- lib/random.gi | 4 ++-- lib/rational.gi | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/cyclotom.gi b/lib/cyclotom.gi index 56bf90f59c..81e747dd9d 100644 --- a/lib/cyclotom.gi +++ b/lib/cyclotom.gi @@ -17,6 +17,24 @@ ## +############################################################################# +## +#V Cyclotomics . . . . . . . . . . . . . . . . . . field of all cyclotomics +## +BindGlobal( "Cyclotomics", Objectify( NewType( + CollectionsFamily( CyclotomicsFamily ), + IsField and IsAttributeStoringRep ), + rec() ) ); +SetName( Cyclotomics, "Cyclotomics" ); +SetLeftActingDomain( Cyclotomics, Rationals ); +SetIsFiniteDimensional( Cyclotomics, false ); +SetIsFinite( Cyclotomics, false ); +SetIsWholeFamily( Cyclotomics, true ); +SetDegreeOverPrimeField( Cyclotomics, infinity ); +SetDimension( Cyclotomics, infinity ); +SetRepresentative(Cyclotomics, 0); + + ############################################################################# ## #M Conductor( ) . . . . . . . . . . . . . . . . . . . . . for a list diff --git a/lib/fldabnum.gd b/lib/fldabnum.gd index 8976554eac..6d7b8ebf9a 100644 --- a/lib/fldabnum.gd +++ b/lib/fldabnum.gd @@ -243,7 +243,7 @@ InstallIsomorphismMaintenance( GaloisStabilizer, ## ## <#/GAPDoc> ## -DeclareGlobalVariable( "Rationals", "field of rationals" ); +DeclareGlobalName( "Rationals" ); DeclareSynonym( "IsRationals", IsCyclotomicCollection and IsField and IsPrimeField ); @@ -705,7 +705,7 @@ DeclareGlobalFunction( "LenstraBase" ); ## ## <#/GAPDoc> ## -DeclareGlobalVariable( "Cyclotomics", "domain of all cyclotomics" ); +DeclareGlobalName( "Cyclotomics" ); ############################################################################# diff --git a/lib/fldabnum.gi b/lib/fldabnum.gi index 2413828b8f..c0d83acb78 100644 --- a/lib/fldabnum.gi +++ b/lib/fldabnum.gi @@ -1649,24 +1649,6 @@ InstallMethod( Coefficients, end ); -############################################################################# -## -#V Cyclotomics . . . . . . . . . . . . . . . . . . field of all cyclotomics -## -InstallValue( Cyclotomics, Objectify( NewType( - CollectionsFamily( CyclotomicsFamily ), - IsField and IsAttributeStoringRep ), - rec() ) ); -SetName( Cyclotomics, "Cyclotomics" ); -SetLeftActingDomain( Cyclotomics, Rationals ); -SetIsFiniteDimensional( Cyclotomics, false ); -SetIsFinite( Cyclotomics, false ); -SetIsWholeFamily( Cyclotomics, true ); -SetDegreeOverPrimeField( Cyclotomics, infinity ); -SetDimension( Cyclotomics, infinity ); -SetRepresentative(Cyclotomics, 0); - - ############################################################################# ## ## Automorphisms of abelian number fields diff --git a/lib/random.gd b/lib/random.gd index a2851498d3..a6d6d43807 100644 --- a/lib/random.gd +++ b/lib/random.gd @@ -213,8 +213,8 @@ if IsHPCGAP then MakeThreadLocal( "GlobalRandomSource" ); MakeThreadLocal( "GlobalMersenneTwister" ); else - DeclareGlobalVariable( "GlobalRandomSource" ); - DeclareGlobalVariable( "GlobalMersenneTwister" ); + DeclareGlobalName( "GlobalRandomSource" ); + DeclareGlobalName( "GlobalMersenneTwister" ); fi; ############################################################################# diff --git a/lib/random.gi b/lib/random.gi index 0f285d4ee0..e7ad11b966 100644 --- a/lib/random.gi +++ b/lib/random.gi @@ -156,7 +156,7 @@ if IsHPCGAP then BindThreadLocalConstructor("GlobalRandomSource", {} -> RandomSource(IsGAPRandomSource, GET_RANDOM_SEED_COUNTER())); else - InstallValue(GlobalRandomSource, RandomSource(IsGAPRandomSource, 1)); + BindGlobal("GlobalRandomSource", RandomSource(IsGAPRandomSource, 1)); fi; @@ -228,7 +228,7 @@ if IsHPCGAP then BindThreadLocalConstructor("GlobalMersenneTwister", {} -> RandomSource(IsMersenneTwister, String(GET_RANDOM_SEED_COUNTER()))); else -InstallValue(GlobalMersenneTwister, RandomSource(IsMersenneTwister, "1")); +BindGlobal("GlobalMersenneTwister", RandomSource(IsMersenneTwister, "1")); fi; # default random method for lists and pairs of integers using the Mersenne diff --git a/lib/rational.gi b/lib/rational.gi index 1a2c919f43..e9d21f242a 100644 --- a/lib/rational.gi +++ b/lib/rational.gi @@ -16,7 +16,7 @@ ## #V Rationals . . . . . . . . . . . . . . . . . . . . . . field of rationals ## -InstallValue( Rationals, Objectify( NewType( +BindGlobal( "Rationals", Objectify( NewType( CollectionsFamily( CyclotomicsFamily ), IsRationals and IsAttributeStoringRep ), rec() ) ); SetName( Rationals, "Rationals" );