bug#81691: remote_expect mishandles return -level 2

Tom de Vries <[email protected]>
Newsgroups gmane.comp.sysutils.dejagnu.bugs
Message-ID <[email protected]>
Hi,

in the gdb testsuite we ran into a problem in multiple procs where we 
use this catch/return pattern:
...
     proc with_test_prefix { prefix body } {
         global pf_prefix

         set saved $pf_prefix
         append pf_prefix " " $prefix ":"
         set code [catch {uplevel 1 $body} result]
         set pf_prefix $saved

         if {$code == 1} {
             global errorInfo errorCode
             return -code $code -errorinfo $errorInfo \
                    -errorcode $errorCode $result
         } else {
             return -code $code $result
         }
     }
...

The problem is that a "return -level 1" and "return -level 2" in body 
have the same effect.

This can be fixed using:
...
-        set code [catch {uplevel 1 $body} result]
+        catch {uplevel 1 $body} result opts
          ...
-        if {$code == 1} {
-            global errorInfo errorCode
-            return -code $code -errorinfo $errorInfo \
-                   -errorcode $errorCode $result
-        } else {
-            return -code $code $result
-        }
+        return -options [dict incr opts -level 1] $result
...

I realized that remote_expect has the same problem.

I wrote a standalone reproducer:
...
$ cat reproduce.exp
#!/usr/bin/expect

try {
     proc exit {args} {}
     proc send_error {args} {}
     source /usr/share/dejagnu/runtest.exp
} on error {} {
}

source /usr/share/dejagnu/remote.exp

proc board_info {board what} {
     return $::spawn_id
}

foreach variant {0 1} {
     spawn /usr/bin/true

     proc inner {} {
	if {$::variant == 0} {
	    expect {
		eof {
		    return -level 2 "return -level 2"
		}
	    }
	} else {
	    remote_expect board 10 {
		eof {
		    return -level 2 "return -level 2"
		}
	    }
	}

	return "inner"
     }

     proc outer {} {
	inner
	return "outer"
     }

     set res [outer]
     puts "variant: $variant: res: $res"
}
$ ./reproduce.exp
spawn /usr/bin/true
variant: 0: res: return -level 2
spawn /usr/bin/true
variant: 1: res: outer
$
...

If remote_expect is expected to behave the same as expect, then variant 
1 should also produce "res: return -level 2".

Thanks,
- Tom




_______________________________________________
Bug-dejagnu mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-dejagnu
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.