bugGNU Octave - Bugs: bug #53027, Strange behavior of globals with...

 
 

bug #53027: Strange behavior of globals with load

Submitter:  Lars Kindermann <larskindermann>
Submitted:  Wed 31 Jan 2018 08:19:02 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  siko1056
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 23 Mar 2018 10:42:18 AM UTC, comment #9: 

@jwe: Wow, with your changes for me everything works as expected for all the considered examples and some software (INTLAB) that I regularly use.  I consider this one as closed.

Kai Torben Ohlhus <siko1056>
Group Member
Fri 23 Mar 2018 03:47:06 AM UTC, comment #8: 

I pushed an additional changeset that allows the test in ntest53027b.m to pass and that also avoids a crash introduced in the previous changeset for the example code provided in bug #52722, which is now a test:

http://hg.savannah.gnu.org/hgweb/octave/rev/c16ad80274c9

John W. Eaton <jwe>
Group administrator
Thu 22 Mar 2018 10:28:00 PM UTC, comment #7: 

I pushed the following changeset, including some new tests.

http://hg.savannah.gnu.org/hgweb/octave/rev/2b040946dc69

Note that there is still one case that I discovered that I don't have a fix for yet.  See the comments in the new file test/bug-53027/ntest53027b.m for an explanation.

John W. Eaton <jwe>
Group administrator
Thu 22 Mar 2018 07:48:52 PM UTC, comment #6: 

Sure, thanks for looking into it.  As you predicted, the Matlab R2017b output of file #43631:


>> format compact
>> [m_exist, n_exist] = ntest ()
n_exist =
     0
m_exist =
     0
m_exist =
     0
n_exist =
     0


Octave 4.2.2 and 4.3.0+ (without my patch file #43629):


>> [m_exist, n_exist] = ntest ()
n_exist = 0
m_exist =  1
m_exist =  1
n_exist = 0


Kai Torben Ohlhus <siko1056>
Group Member
Thu 22 Mar 2018 04:17:14 PM UTC, comment #5: 

Kai:  I think the attached test is also wrong, with or without your change.  I think it should return 0 for both of the exist tests.  Can you confirm this behavior with Matlab?


(file #43631)

John W. Eaton <jwe>
Group administrator
Thu 22 Mar 2018 12:06:05 PM UTC, comment #4: 

For comment #1 I can confirm, that Octave 4.2.2 and Matlab R2017b behave this way.

The attached patch basically reverts the first two changes of jwe in libinterp/corefcn/symrec.h (cset http://hg.savannah.gnu.org/hgweb/octave/rev/2706adccf4e9#l3.1) and restores the behavior of comment #1.

For me this patch does not result in further regressions regarding the persistent issues in bug #52722 and can be applied soon with some comments and a test.

(file #43629)

Kai Torben Ohlhus <siko1056>
Group Member
Mon 12 Feb 2018 10:15:34 PM UTC, comment #3: 

Confirmed.

I'm uploading the script bugGlobal2.m which is taken from comment #1.

Also adding jwe to the CC list since he fixed the issue in bug #52722 which likely caused this one.

Rik <rik5>
Group administrator
Sun 11 Feb 2018 09:00:56 PM UTC, comment #2: 

I am pretty sure this is related to changeset 24456:2706adccf4e9 and bug #52722 "fix binding for global variables in script files".

Probably that patch fixes the bug for setting globals in functions but not for loading them with load().

Lars Kindermann <larskindermann>
Thu 01 Feb 2018 12:07:06 PM UTC, comment #1: 

It seems there is incorrectly created a second handle to the global X somewhere.

The bug is very nasty because many scripts now give bad results without any notice. It must habe been introduced within the last month or so. Here is a very basic script that demonstrates the error more clearly:


global X

function loadX()
 global X
 load fileX
end

X=1;
save fileX X

X=2;
load fileX
X

X=3;
loadX()
X

clear all
X


This should be the correct output (Version 4.0):

>> bugGlobal2
X =  1
X =  1
error: 'X' undefined near line 20 column 2
error: called from
    bugGlobal4 at line 20 column 2


And this is from current dev:

>> bugGlobal2

X =  1
X =  3
X =  3


Lars Kindermann <larskindermann>
Wed 31 Jan 2018 08:19:02 AM UTC, original submission:  

load() of a global inside a function leads to several strange effects:
- The value outside the function does not change  
- It cannot be cleared anymore

Test code (bugGlobal.m):

global X

function saveX
 global X
 disp "inside saveX"
 X=1
 save -binary fileX X
endfunction

function loadX
 global X
 disp "inside loadX:"
 X=2
 load fileX
 disp "inside loadX after load:"
 X
endfunction

disp "starting:"
X=0
saveX
disp "after saveX:"
X
loadX
disp "after loadX:"
X
load fileX
disp "after load:"
X
clear all
disp "after clear:"
X


This is the correct output of version 4.0

starting:
X = 0
inside saveX
X =  1
after saveX:
X =  1
inside loadX:
X =  2
inside loadX after load:
X =  1
after loadX:
X =  1
after load:
X =  1
after clear:
error: 'X' undefined near line 32 column 2
error: called from
    bugGlobal at line 32 column 2


This is the strange output of current dev

starting:
X = 0
inside saveX
X =  1
after saveX:
X =  1
inside loadX:
X =  2
inside loadX after load:
X =  1
after loadX:
X =  2
after load:
X =  1
after clear:
X =  1


This is the even stranger output of a second execution of the code

starting:
X = 0
inside saveX
X =  1
after saveX:
X = 0
inside loadX:
X =  2
inside loadX after load:
X =  1
after loadX:
X = 0
after load:
X =  1
after clear:
X =  1



Lars Kindermann <larskindermann>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #43631:  ntest.m added by jwe (195B - text/x-objcsrc)
file #43629:  bug53027.patch added by siko1056 (1KiB - text/x-patch)
file #43289:  bugGlobal2.m added by larskindermann (120B - text/x-objcsrc)
file #43137:  bugGlobal.m added by larskindermann (349B - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by rik5
  • -email is unavailable- added by larskindermann (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 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-23 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2018-03-22 jwe StatusPatch Submitted Ready For Test
    2018-03-22 jwe Attached File- Added ntest.m, #43631
    2018-03-22 siko1056 Assigned toNone siko1056
    2018-03-22 siko1056 Attached File- Added bug53027.patch, #43629
        StatusConfirmed Patch Submitted
    2018-03-22 siko1056 Item GroupIncorrect Result Regression
    2018-02-14 larskindermann Attached File- Added bugGlobal2.m, #43289
    2018-02-12 rik5 StatusNone Confirmed
    2018-02-12 rik5 Carbon-Copy- Added jwe
    2018-01-31 larskindermann Attached File- Added bugGlobal.m, #43137

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code