bugGNU Octave - Bugs: bug #41315, pause(): every other call fails

 
 

bug #41315: pause(): every other call fails

Submitted by:  Felipe G. Nievinski <fgnievinski>
Submitted on:  Wed 22 Jan 2014 11:01:20 PM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  3.8.0 Operating System:  Microsoft Windows

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)

Mon 01 Feb 2016 06:09:46 AM UTC, comment #8: 

Fixed.  Closing report.

Rik <rik5>
Project Administrator
Mon 25 Jan 2016 04:22:20 PM UTC, comment #7: 

Well, I have checked this again.
The correct behavior is:

>> tic, pause, toc; <enter>
<enter again>
Elapsed time is xxx seconds

There is a problem in version 4.0.0, as described in the original submission, when the first "tic, pause, toc" worked well, but
the second one gave and answer of "Elapsed time is 0 seconds."
after the first <enter>.

It was fixed in 4.0.1 (checked on 4.0.1-rc3), and it works
on 4.1.0+, without the new patch.

So this bug should be closed as fixed. see http://wiki.octave.org/Status_of_bugs

Avinoam Kalma <avinoam>
Project Member
Mon 25 Jan 2016 01:43:02 AM UTC, comment #6: 

Thanks for testing that Avinoam.

No, that is not the right behaviour...  It should require one key press.

Can you confirm that without my patch it also required two presses of <enter>?  That is the opposite from the behaviour in the original post.  Perhaps someone had already fixed it without closing this bug report.

Just for reference, could you please try the attached patch (after removing the old one), and let me know what output it returns?

Thanks again.

(file #36158)

Lachlan Andrew <lachlan>
Sun 24 Jan 2016 10:14:02 PM UTC, comment #5: 

continue of comment #4: Is it the right behavior?

Avinoam Kalma <avinoam>
Project Member
Sun 24 Jan 2016 10:09:22 PM UTC, comment #4: 

In current version

 tic, pause, toc

needs two times <enter> to display "Elapsed time is...".
It wan't changed with Lachlan's patch (under Windows).

Avinoam Kalma <avinoam>
Project Member
Sat 23 Jan 2016 01:33:03 AM UTC, comment #3: 

If Felipe is pressing enter, which produces \r\n, then it is unsurprising that one press registers as two characters.  Since most systems don't have a key that returns \r without \n, a simple fix would be to ignore a \r, as the attached patch does.  An alternative would be to fix  raw_mode()  to force CR/NL to map to NL on the input, which

This doesn't address the issue of ignoring all keys except enter, but at least gives something workable.

I haven't tested this since I don't currently have access to Windows. Felipe, could you please test it?

(file #36134)

Lachlan Andrew <lachlan>
Thu 23 Jan 2014 12:24:28 AM UTC, comment #2: 

This works perfectly on a Linux platform, but fails in both the CLI and GUI versions on a Windows platform.  It seems that this is likely due to the difference in tty standards between a POSIX O/S like Linux and Microsoft's own implementations.

The relevant routine is octave_kbhit in libinterp/corefcn/sysdep.cc.

int
octave_kbhit (bool wait)
{
#ifdef HAVE__KBHIT
  int c = (! wait && ! _kbhit ()) ? 0 : std::cin.get ();
#else
  raw_mode (true, wait);

  // Get current handler.
  octave_interrupt_handler saved_interrupt_handler
    = octave_ignore_interrupts ();

  // Restore it, disabling system call restarts (if possible) so the
  // read can be interrupted.

  octave_set_interrupt_handler (saved_interrupt_handler, false);

  int c = std::cin.get ();

  if (std::cin.fail () || std::cin.eof ())
    std::cin.clear ();

  // Restore it, enabling system call restarts (if possible).
  octave_set_interrupt_handler (saved_interrupt_handler, true);

  raw_mode (false, true);
#endif

  return c;
}

On my system I HAVE__KBHIT is unset so the #else branch is being used.

Another easy way to see the problem is to directly use the kbhit function.  It should grab a single character, but instead is waiting for a <RETURN> key.

x = kbhit ()

Finally, it looks like the raw_mode() function is possibly the root cause as it tries to fiddle with the terminal properties.

Rik <rik5>
Project Administrator
Wed 22 Jan 2014 11:02:07 PM UTC, comment #1: 

likely related: pause only wakes up with enter, not just any character as stated in the docs.

Felipe G. Nievinski <fgnievinski>
Wed 22 Jan 2014 11:01:20 PM UTC, original submission:  

>> tic, pause, toc

Elapsed time is 1.10706 seconds.
>> tic, pause, toc
Elapsed time is 0 seconds.
>> tic, pause, toc

Elapsed time is 1.17607 seconds.
>> tic, pause, toc
Elapsed time is 0 seconds.
>> tic, pause, toc

Elapsed time is 1.05306 seconds.
>> tic, pause, toc
Elapsed time is 0 seconds.

Felipe G. Nievinski <fgnievinski>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #36158:  bug_41315_test.cset added by lachlan (1KiB - application/octet-stream)
file #36134:  bug_41315_ignore_CR.cset added by lachlan (1KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by avinoam (Posted a comment)
  • -email is unavailable- added by lachlan (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by fgnievinski (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-02-01 rik5 StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2016-01-25 lachlan Attached File- => Added bug_41315_test.cset, #36158
    2016-01-23 lachlan Attached File- => Added bug_41315_ignore_CR.cset, #36134
    2014-01-23 rik5 StatusNone => Confirmed

    Back to the top


    Powered by Savane 3.5