Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[source] is not yield-able

Closed / Fixed2412068fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-12-09 16:19:54
Short example:

# Start of a.tcl
proc main {} {
    uplevel #0  {
source b.tcl
    }
}

coroutine m main
# end of a.tcl

# start of b.tcl
yield
# end of b.tcl

On Running this as:

c:/tcl/8.6a4-2008-12-07/bin/tclsh86.exe a.tcl

I get this error:
cannot yield: C stack busy
    while executing
"yield"
    (file "b.tcl" line 1)
    invoked from within
"source b.tcl"
    ("uplevel" body line 2)
    invoked from within
"uplevel #0  {
source b.tcl
    }"
    (procedure "main" line 2)
    invoked from within
"main"
    invoked from within
"coroutine m main"
    (file "a.tcl" line 9)
dkf Ticket [2412068fff]: 3 changes [History diff]2008-12-09 23:25:45
venksiplain2008-12-12 00:26:04
As a very temporary workaround (that my work for only me):

rename ::source ::old_source

proc ::source args {
    if {[llength $args] > 1} {
uplevel 1 [linsert $args 0 ::old_source]
    } else {
set fi [open [lindex $args 0]]
set r [read $fi]
close $fi
uplevel 1 $r
    }
}

That takes care of my simple case where the users do not pass
flags to source.  But the proc must handle it because many tcl
libraries do.  This allows files which are sourced as just
"source <name>" to be able to use yield.
dkfplain2009-01-05 16:50:49
Turned out to be simpler than I expected, but I'm not sure that the TIP#280 dictionary generated by [info frame 0] at the top-level in a sourced file is quite correct in all cases (sourcing from ::unknown seems different in some circumstances). If anyone has problems, they can submit a bug report...
dkf Closed ticket [2412068fff]. [History diff]2009-01-05 16:50:50
dkfplain2009-01-05 19:28:22
I was mistaken, and the TIP#280 hairball has claimed me for sure. :-(

(Why there are so many subtle differences between different Eval-like APIs, I just do not know...)
dkf Open ticket [2412068fff]. [History diff]2009-01-05 19:28:23
dkfplain2009-01-05 20:30:25
problems now tracked in 2487771
dkf Closed ticket [2412068fff]. [History diff]2009-01-05 20:30:39
Log in (anonymous is fine) to add a comment.