bugGNU Octave - Bugs: bug #48171, Third output argument of uiputfile...

 
 

bug #48171: Third output argument of uiputfile undefined when user presses Cancel

Submitted by:  Guillaume <gyom>
Submitted on:  Wed 08 Jun 2016 10:27:03 AM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Wed 08 Jun 2016 07:16:05 PM UTC, comment #6: 

Okay, I cleaned up some of the surrounding code here (http://hg.savannah.gnu.org/hgweb/octave/rev/3ef630a564f8) but didn't bother to switch to a case statement.

Rik <rik5>
Project Administrator
Wed 08 Jun 2016 06:47:15 PM UTC, comment #5: 

The way the Qt side of the link is coded, it will never return a list with fewer than 2 elements. We could certainly make the function that calls the link object more robust to be defensive against future breakage, but at present the Qt implementation always returns a list of length >= 2.

Mike Miller <mtmiller>
Project Administrator
Wed 08 Jun 2016 06:32:27 PM UTC, comment #4: 

Incidentally, there are multiple problems with the link dialogs.  I'm going to file another one about the filename which is returned being incorrect.

Rik <rik5>
Project Administrator
Wed 08 Jun 2016 06:31:21 PM UTC, comment #3: 

Is there any danger that Qt will return anything other than 2,3, or 3+ elements?  I coded a slightly different fix which I have attached where I initialize all the outputs to 0.0 and override as necessary based on a switch statement.

diff -r f250714c629d -r a0ab0551018b libinterp/corefcn/octave-link.cc
--- a/libinterp/corefcn/octave-link.cc        Tue Jun 07 16:00:45 2016 -0700
+++ b/libinterp/corefcn/octave-link.cc        Wed Jun 08 11:26:56 2016 -0700
@@ -230,32 +230,37 @@ Undocumented internal function.\n\
   // If 3, then retval is filename, directory, and selected index.
   if (nel <= 3)
     {
-      int idx = 0;
-      for (std::list<std::string>::iterator it = items_lst.begin ();
-           it != items_lst.end (); it++)
+      retval = (octave_value (0.0), octave_value (0.0), octave_value (0.0));
+
+      std::list<std::string>::reverse_iterator it = items_lst.rbegin ();
+
+      switch (nel)
         {
-          retval(idx++) = *it;
+        case 3:
+          if (! it->empty ())
+            retval(2) = atoi (it->c_str ());
+          it++;

-          if (idx == 1 && retval(0).string_value ().length () == 0)
-            retval(0) = 0;
+        case 2:
+          if (! it->empty ())
+            retval(1) = *it;
+          it++;

-          if (idx == 3)
-            retval(2) = atoi (retval(2).string_value ().c_str ());
+        case 1:
+          if (! it->empty ())
+            retval(0) = *it;
         }
     }
   else
     {
       // Multiple files.
-      nel = items_lst.size () - 2;
+      nel = nel - 2;
       Cell items (dim_vector (1, nel));

       std::list<std::string>::iterator it = items_lst.begin ();

-      for (int idx = 0; idx < nel; idx++)
-        {
-          items.xelem (idx) = *it;
-          it++;
-        }
+      for (int idx = 0; idx < nel; idx++, it++)
+        items.xelem (idx) = *it;

       retval = ovl (items, *it++, atoi (it->c_str ()));
     }

(file #37435)

Rik <rik5>
Project Administrator
Wed 08 Jun 2016 05:42:35 PM UTC, comment #2: 

Fixed on the default branch with the following change:

http://hg.savannah.gnu.org/hgweb/octave/rev/2049e123bf7b

Mike Miller <mtmiller>
Project Administrator
Wed 08 Jun 2016 04:22:21 PM UTC, comment #1: 

Confirmed.  Incidentally, it works if you run the cli version of Octave which does not have access to Qt by starting with '--no-gui-libs'

Rik <rik5>
Project Administrator
Wed 08 Jun 2016 10:27:03 AM UTC, original submission:  

When the user presses the Cancel button in the uiputfile window, the third output variable should be 0 but is instead undefined:

>> [retfile,retpath,retidx] = uiputfile
warning: uiputfile: some elements in list of return values are undefined
warning: called from
    uiputfile at line 129 column 1
retfile = 0
retpath = 0
retidx = [](0x0)

A breakpoint in the uiputfile.m function at the line calling _octave_link_file_dialog_ gives:

debug> [retfile, retpath, retindex] = __octave_link_file_dialog__ (outargs{:})
retfile = 0
retpath = 0
retindex =

error: octave_base_value::print (): wrong type argument '<unknown type>'

Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #37435:  octlink.diff added by rik5 (2KiB - application/x-download)

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-06-08 rik5 Attached File- => Added octlink.diff, #37435
    2016-06-08 mtmiller StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2016-06-08 rik5 StatusNone => Confirmed

    Back to the top


    Powered by Savane 3.5