bugGNU Octave - Bugs: bug #59122, jsonencode change's user's warning...

 
 

bug #59122: jsonencode change's user's warning setting for "Octave:classdef-to-struct"

Submitter:  Rik <rik5>
Submitted:  Thu 17 Sep 2020 02:54:36 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 21 Sep 2020 05:04:05 PM UTC, comment #5: 

Indeed it does.  In fact, I need to write something about this on either Discourse, or directly to the Octave maintainers list.

A straightforward lambda expression (which begins with '[') will return a lambda type object.  However, frame.add_fcn () is expecting a pointer to a function.  Lambda expressions and function pointers are very close and often can be converted from one to the other (of course, there are some exceptions).  In this case, the '+' tells the compiler that I want a function pointer type.

Rik <rik5>
Group administrator
Mon 21 Sep 2020 04:45:12 PM UTC, comment #4: 

I'm trying to understand why there is a `+` in front of the lambda expression. Does that have a special purpose?

Markus Mützel <mmuetzel>
Group administrator
Fri 18 Sep 2020 07:02:16 PM UTC, comment #3: 

Thanks Markus, this works for me.  I made a small change in this cset http://hg.savannah.gnu.org/hgweb/octave/rev/f4ed4be5d809.

Declaring a static function that consists of a single line feels like a heavyweight solution.  Instead, I used the C++ lambda feature (anonymous, lightweight function).  I think it makes the code a little easier to read since I declare the cleanup action immediately before adding it the unwind protect frame.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Fri 18 Sep 2020 05:19:16 PM UTC, comment #2: 

I pushed a change here:
https://hg.savannah.gnu.org/hgweb/octave/rev/b6bed53f059f

Marking as ready for test.

Markus Mützel <mmuetzel>
Group administrator
Fri 18 Sep 2020 08:01:25 AM UTC, comment #1: 

Oops! I think this is a bug carried over from my JsonStuff implementation. Yeah, it should stash the original warning state and revert to that, rather than unconditionally re-enabling the error. Sorry!

Andrew Janke <apjanke>
Thu 17 Sep 2020 02:54:36 PM UTC, original submission:  

When classdef objects or a containers.Map object are encoded to JSON they are first converted to structs.  The C++ code disables the warning ID "Octave:classdef-to-struct" and then turns it back on after conversion.  However, if the user had this ID turned off to begin with then this code changes the setting without the user's consent.

Code in jsonencode.cc:


      set_warning_state ("Octave:classdef-to-struct", "off");
      encode_struct (writer, obj.scalar_map_value (), ConvertInfAndNaN);
      set_warning_state ("Octave:classdef-to-struct", "on");


Sample m-file code


octave:2> warning ("off", "Octave:classdef-to-struct")
octave:3> jsonencode (containers.Map ());
octave:4> warning ("query", "Octave:classdef-to-struct")
"Octave:classdef-to-struct" warning state is "on"


Rik <rik5>
Group administrator

 

(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 mmuetzel (Posted a comment)
  • -email is unavailable- added by apjanke (Posted a comment)
  • -email is unavailable- added by rik5 (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-09-18 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2020-09-18 mmuetzel StatusConfirmed Ready For Test

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code