Mercurial > octave
changeset 25203:72ea868ca63a stable
allow function parameters to be global (bug #53579)
* symrec.h (symbol_record::unbind_global_rep): New function.
* symscope.h (symbol_scope::refresh): Use it to also unbind global
symbols.
* test/bug-53579.tst: New file.
* test/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Apr 2018 00:07:06 -0400 |
parents | d12271fe1504 |
children | 22522ea137b4 cbe53b5ea5ce |
files | libinterp/corefcn/symrec.h libinterp/corefcn/symscope.h test/bug-53579.tst test/module.mk |
diffstat | 4 files changed, 27 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/symrec.h Tue Apr 10 23:58:10 2018 -0400 +++ b/libinterp/corefcn/symrec.h Wed Apr 11 00:07:06 2018 -0400 @@ -686,6 +686,8 @@ m_rep->bind_fwd_rep (fwd_scope, sr.m_rep); } + void unbind_global_rep (void) { m_rep->unbind_global_rep (); } + void unbind_fwd_rep (void) { m_rep->unbind_fwd_rep (); } octave_value dump (context_id context) const
--- a/libinterp/corefcn/symscope.h Tue Apr 10 23:58:10 2018 -0400 +++ b/libinterp/corefcn/symscope.h Wed Apr 11 00:07:06 2018 -0400 @@ -277,7 +277,9 @@ { symbol_record& sr = nm_sr.second; - if (! (sr.is_persistent () || sr.is_forwarded ())) + if (sr.is_global ()) + sr.unbind_global_rep (); + else if (! (sr.is_persistent () || sr.is_forwarded ())) sr.clear (m_context); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-53579.tst Wed Apr 11 00:07:06 2018 -0400 @@ -0,0 +1,21 @@ +%!function [raa, rbb, igaa, igbb] = sub1 (aa, bb) +%! global aa bb +%! aa = 1; +%! raa = aa; +%! rbb = bb; +%! igaa = isglobal ("aa"); +%! igbb = isglobal ("bb"); +%!endfunction + +%!test <*53579> +%! global aa bb +%! assert (isglobal ("aa")); +%! assert (isglobal ("bb")); +%! aa = 3; +%! xx = 5; +%! [raa, rbb, igaa, igbb] = sub1 (aa, xx); +%! assert (raa, 1); +%! assert (rbb, []); +%! assert (igaa); +%! assert (igbb); +%! assert (xx, 5);