Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make (Un)HideGlobalVariables obsolete #3185

Merged
merged 1 commit into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions lib/global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -274,42 +274,3 @@ DeclareGlobalFunction("BindConstant");
## </ManSection>
##
DeclareGlobalFunction("TemporaryGlobalVarName");


#############################################################################
##
#F HideGlobalVariables(<str1>[,<str2>,...]))
##
## <ManSection>
## <Func Name="HideGlobalVariables" Arg='str1[,str2,...]'/>
##
## <Description>
## temporarily makes global variables <Q>undefined</Q>. The arguments to
## <C>HideGlobalVariables</C> are strings. If there is a global variable defined
## whose identifier is equal to one of the strings it will be <Q>hidden</Q>.
## This means that identifier and value will be safely stored on a stack
## and the variable will be undefined afterwards. A call to
## <C>UnhideGlobalVariables</C> 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.
## </Description>
## </ManSection>
##
DeclareGlobalFunction("HideGlobalVariables");


#############################################################################
##
#F UnhideGlobalVariables(<str1>[,<str2>,...])
#F UnhideGlobalVariables()
##
## <ManSection>
## <Func Name="UnhideGlobalVariables" Arg='str1[,str2,...]'/>
## <Func Name="UnhideGlobalVariables" Arg=''/>
##
## <Description>
## The second version unhides all variables that are still hidden.
## </Description>
## </ManSection>
##
DeclareGlobalFunction("UnhideGlobalVariables");
83 changes: 0 additions & 83 deletions lib/global.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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+2<l then
# move
HIDDEN_GVARS{[p..l-3]}:=HIDDEN_GVARS{[p+3..l]};
fi;
# remove
Unbind(HIDDEN_GVARS[l-2]);
Unbind(HIDDEN_GVARS[l-1]);
Unbind(HIDDEN_GVARS[l]);
l:=l-3;
which:=Filtered(which,i->i<>str);
fi;
fi;
p:=p-3;
od;
if all then
HIDDEN_GVARS:=[];
fi;
end);
45 changes: 45 additions & 0 deletions lib/obsolete.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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(<str1>[,<str2>,...]))
##
## <ManSection>
## <Func Name="HideGlobalVariables" Arg='str1[,str2,...]'/>
##
## <Description>
## temporarily makes global variables <Q>undefined</Q>. The arguments to
## <C>HideGlobalVariables</C> are strings. If there is a global variable defined
## whose identifier is equal to one of the strings it will be <Q>hidden</Q>.
## This means that identifier and value will be safely stored on a stack
## and the variable will be undefined afterwards. A call to
## <C>UnhideGlobalVariables</C> 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.
## </Description>
## </ManSection>
##
## This function was never documented.
##
## Still used in anupq, nq, resclasses, rcwa (01/2019)
DeclareGlobalFunction("HideGlobalVariables");


#############################################################################
##
#F UnhideGlobalVariables(<str1>[,<str2>,...])
#F UnhideGlobalVariables()
##
## <ManSection>
## <Func Name="UnhideGlobalVariables" Arg='str1[,str2,...]'/>
## <Func Name="UnhideGlobalVariables" Arg=''/>
##
## <Description>
## The second version unhides all variables that are still hidden.
## </Description>
## </ManSection>
##
## This function was never documented.
##
## Still used in anupq, nq, resclasses, rcwa (01/2019)
DeclareGlobalFunction("UnhideGlobalVariables");
91 changes: 91 additions & 0 deletions lib/obsolete.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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+2<l then
# move
HIDDEN_GVARS{[p..l-3]}:=HIDDEN_GVARS{[p+3..l]};
fi;
# remove
Unbind(HIDDEN_GVARS[l-2]);
Unbind(HIDDEN_GVARS[l-1]);
Unbind(HIDDEN_GVARS[l]);
l:=l-3;
which:=Filtered(which,i->i<>str);
fi;
fi;
p:=p-3;
od;
if all then
HIDDEN_GVARS:=[];
fi;
end);