From 7640d60539ef2302e62ed97d7961623da112c32b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 17 Jan 2019 11:14:23 +0100 Subject: [PATCH] Make (Un)HideGlobalVariables obsolete These functions were never documented, and so far in all cases where they appear, there seem to be better, more robust alternatives, such as reading and evaluating external code inside a function context with suitable locals set, or by adapting the (interface to) the external code. --- lib/global.gd | 39 --------------------- lib/global.gi | 83 -------------------------------------------- lib/obsolete.gd | 45 ++++++++++++++++++++++++ lib/obsolete.gi | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 122 deletions(-) diff --git a/lib/global.gd b/lib/global.gd index 85ac810102..5602e482b6 100644 --- a/lib/global.gd +++ b/lib/global.gd @@ -274,42 +274,3 @@ DeclareGlobalFunction("BindConstant"); ## ## DeclareGlobalFunction("TemporaryGlobalVarName"); - - -############################################################################# -## -#F HideGlobalVariables([,,...])) -## -## -## -## -## -## temporarily makes global variables undefined. The arguments to -## HideGlobalVariables are strings. If there is a global variable defined -## whose identifier is equal to one of the strings it will be hidden. -## This means that identifier and value will be safely stored on a stack -## and the variable will be undefined afterwards. A call to -## UnhideGlobalVariables will restore the old values. -## The main purpose of hiding variables will be for the temporary creation -## of global variables for reading in data created by other programs. -## -## -## -DeclareGlobalFunction("HideGlobalVariables"); - - -############################################################################# -## -#F UnhideGlobalVariables([,,...]) -#F UnhideGlobalVariables() -## -## -## -## -## -## -## The second version unhides all variables that are still hidden. -## -## -## -DeclareGlobalFunction("UnhideGlobalVariables"); diff --git a/lib/global.gi b/lib/global.gi index 13445d6234..0441ab2261 100644 --- a/lib/global.gi +++ b/lib/global.gi @@ -308,86 +308,3 @@ InstallGlobalFunction( TemporaryGlobalVarName, return gvar; end ); - - -if IsHPCGAP then - BindThreadLocal("HIDDEN_GVARS",[]); -else - HIDDEN_GVARS:=[]; -fi; - -InstallGlobalFunction(HideGlobalVariables,function(arg) -local p,i; - p:=Length(HIDDEN_GVARS); - for i in arg do - if IsString(i) then - p:=p+1; - HIDDEN_GVARS[p]:=i; - p:=p+2; - if ISBOUND_GLOBAL(i) then - # variable is assigned - HIDDEN_GVARS[p-1]:=VALUE_GLOBAL(i); - if IS_READ_ONLY_GLOBAL(i) then - HIDDEN_GVARS[p]:=true; - MAKE_READ_WRITE_GLOBAL(i); - else - HIDDEN_GVARS[p]:=false; - fi; - else - HIDDEN_GVARS[p-1]:=fail; # needs to be assigned - HIDDEN_GVARS[p]:=fail; - fi; - # temporarily remove the variable - UNBIND_GLOBAL(i); - else - Error("HideGlobalVariables requires the names as strings"); - fi; - od; -end); - -InstallGlobalFunction(UnhideGlobalVariables,function(arg) -local p,str,all,l,which; - all:=Length(arg)=0; # doe we want to unhide all? - which:=arg; - l:=Length(HIDDEN_GVARS); - p:=l-2; - while p>0 do - str:=HIDDEN_GVARS[p]; - # do we want to unhide the variable? - if all or str in which then - # remove the value - if ISBOUND_GLOBAL(str) then - if IS_READ_ONLY_GLOBAL(str) then - MAKE_READ_WRITE_GLOBAL(str); - fi; - UNBIND_GLOBAL(str); - fi; - - if HIDDEN_GVARS[p+2]<>fail then - #reassign a value - ASS_GVAR(str,HIDDEN_GVARS[p+1]); - if HIDDEN_GVARS[p+2]=true then - MAKE_READ_ONLY_GLOBAL(str); - fi; - fi; - - # remove the corresponding "HIDDEN_GVARS" entry - if not all then - if p+2i<>str); - fi; - fi; - p:=p-3; - od; - if all then - HIDDEN_GVARS:=[]; - fi; -end); diff --git a/lib/obsolete.gd b/lib/obsolete.gd index f455a8098a..323c2c09f0 100644 --- a/lib/obsolete.gd +++ b/lib/obsolete.gd @@ -690,3 +690,48 @@ DeclareObsoleteSynonym( "RecFields", "RecNames" ); if GAPInfo.CommandLineOptions.D then InfoRead1 := Print; fi; if not IsBound(InfoRead1) then InfoRead1 := Ignore; fi; if not IsBound(InfoRead2) then InfoRead2 := Ignore; fi; + + +############################################################################# +## +#F HideGlobalVariables([,,...])) +## +## +## +## +## +## temporarily makes global variables undefined. The arguments to +## HideGlobalVariables are strings. If there is a global variable defined +## whose identifier is equal to one of the strings it will be hidden. +## This means that identifier and value will be safely stored on a stack +## and the variable will be undefined afterwards. A call to +## UnhideGlobalVariables will restore the old values. +## The main purpose of hiding variables will be for the temporary creation +## of global variables for reading in data created by other programs. +## +## +## +## This function was never documented. +## +## Still used in anupq, nq, resclasses, rcwa (01/2019) +DeclareGlobalFunction("HideGlobalVariables"); + + +############################################################################# +## +#F UnhideGlobalVariables([,,...]) +#F UnhideGlobalVariables() +## +## +## +## +## +## +## The second version unhides all variables that are still hidden. +## +## +## +## This function was never documented. +## +## Still used in anupq, nq, resclasses, rcwa (01/2019) +DeclareGlobalFunction("UnhideGlobalVariables"); diff --git a/lib/obsolete.gi b/lib/obsolete.gi index f9cb1ade71..3e549aa5dd 100644 --- a/lib/obsolete.gi +++ b/lib/obsolete.gi @@ -958,3 +958,94 @@ BIND_GLOBAL( "SetFeatureObj", function ( obj, filter, val ) ResetFilterObj( obj, filter ); fi; end ); + + +if IsHPCGAP then + BindThreadLocal("HIDDEN_GVARS",[]); +else + HIDDEN_GVARS:=[]; +fi; + +InstallGlobalFunction(HideGlobalVariables,function(arg) +local p,i; + + InfoObsolete(1, "This usage of `HideGlobalVariables` is no longer", + "supported and will be removed eventually." ); + + p:=Length(HIDDEN_GVARS); + for i in arg do + if IsString(i) then + p:=p+1; + HIDDEN_GVARS[p]:=i; + p:=p+2; + if ISBOUND_GLOBAL(i) then + # variable is assigned + HIDDEN_GVARS[p-1]:=VALUE_GLOBAL(i); + if IS_READ_ONLY_GLOBAL(i) then + HIDDEN_GVARS[p]:=true; + MAKE_READ_WRITE_GLOBAL(i); + else + HIDDEN_GVARS[p]:=false; + fi; + else + HIDDEN_GVARS[p-1]:=fail; # needs to be assigned + HIDDEN_GVARS[p]:=fail; + fi; + # temporarily remove the variable + UNBIND_GLOBAL(i); + else + Error("HideGlobalVariables requires the names as strings"); + fi; + od; +end); + +InstallGlobalFunction(UnhideGlobalVariables,function(arg) +local p,str,all,l,which; + + InfoObsolete(1, "This usage of `UnhideGlobalVariables` is no longer", + "supported and will be removed eventually." ); + + all:=Length(arg)=0; # doe we want to unhide all? + which:=arg; + l:=Length(HIDDEN_GVARS); + p:=l-2; + while p>0 do + str:=HIDDEN_GVARS[p]; + # do we want to unhide the variable? + if all or str in which then + # remove the value + if ISBOUND_GLOBAL(str) then + if IS_READ_ONLY_GLOBAL(str) then + MAKE_READ_WRITE_GLOBAL(str); + fi; + UNBIND_GLOBAL(str); + fi; + + if HIDDEN_GVARS[p+2]<>fail then + #reassign a value + ASS_GVAR(str,HIDDEN_GVARS[p+1]); + if HIDDEN_GVARS[p+2]=true then + MAKE_READ_ONLY_GLOBAL(str); + fi; + fi; + + # remove the corresponding "HIDDEN_GVARS" entry + if not all then + if p+2i<>str); + fi; + fi; + p:=p-3; + od; + if all then + HIDDEN_GVARS:=[]; + fi; +end);