bugGNU Octave - Bugs: bug #59344, Run source('filename.m','caller')...

 
 

bug #59344: Run source('filename.m','caller') and Get a 'base' Context

Submitter:  Glite <linuxbckp>
Submitted:  Sat 24 Oct 2020 11:49:54 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 5.2.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 31 Oct 2020 07:15:40 AM UTC, comment #2: 

You are right.
I change b.m to:

function o=b(i)
    i+=3;
    callit
    source('callit.m','base')
    source('callit.m','caller')
    function o=d(i)
        source('callit.m','base')
        source('callit.m','caller')
    endfunction
    d(i)
endfunction

And the result is:

>> b(3)
here, i=6
here, i=1
here, i=1
here, i=1
here, i=6

It proves that the context changes and the behavior is correct.
Many thanks!
comment #1:

> This is correct behavior.  When you execute "b(3)" the "caller" context is the same as the "base" context since "b(3)" is called from the Octave prompt.  Since they are the same context, they must return the same results.
>
> Also, there is no change to the variable "i" because the script callit.m makes no assignment to it.
>
> If I modify callit.m to
>


> i = i + 1;
> a(i)


>
> and then execute
>


> octave:7> i = 1
> i = 1
> octave:8> b(3)
> here, i=7
> here, i=2
> here, i=3
> octave:9> i
> i = 3


>
> you can see that variables are changed in the base and caller context.

Glite <linuxbckp>
Sun 25 Oct 2020 10:45:37 PM UTC, comment #1: 

This is correct behavior.  When you execute "b(3)" the "caller" context is the same as the "base" context since "b(3)" is called from the Octave prompt.  Since they are the same context, they must return the same results.

Also, there is no change to the variable "i" because the script callit.m makes no assignment to it.

If I modify callit.m to


i = i + 1;
a(i)


and then execute


octave:7> i = 1
i = 1
octave:8> b(3)
here, i=7
here, i=2
here, i=3
octave:9> i
i = 3


you can see that variables are changed in the base and caller context.

Rik <rik5>
Group administrator
Sat 24 Oct 2020 11:49:54 PM UTC, original submission:  

I designed three programs to test this bug:
File: callit.m

a(i)

File: a.m

function o=a(i)
    fprintf("here, i=%d\n",i)
endfunction

File: b.m

function o=b(i)
    i+=3;
    callit
    source('callit.m','base')
    source('callit.m','caller')
endfunction

Then execute this chain:

>> i=1
i =  1
>> b(3)
here, i=6
here, i=1
here, i=1

It seems that calling source() function with 'base' and 'caller' parameter has the same result, but var i should be changed in 'caller' context.

Glite <linuxbckp>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by linuxbckp (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-10-25 rik5 StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
        Operating SystemMicrosoft Windows Any

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code