Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash; can upvar support #0? #6

Open
lehenbauer opened this issue Jul 29, 2015 · 2 comments
Open

crash; can upvar support #0? #6

lehenbauer opened this issue Jul 29, 2015 · 2 comments

Comments

@lehenbauer
Copy link

I presume the code below coredumps because tsp upvar accepts but doesn't support #0. Would this be hard to add? We call the routine below a lot and avoid running subst on conclusionCode unless the referenced global variable is true. If analysis_subst_if could be defined as a tsp::proc and since most of the time the referenced variable is false, it seems like this tsp would be a clear performance win.

Alternatively I'm looking for a way to get the contents of a global variable inside a tsp::proc where the name of the global variable is in a variable.

package require tsp

tsp::proc analysis_subst_if {varName ident conclusionCode} {
    #tsp::procdef void -args var var var
    #tsp::int mute
    #tsp::boolean var
    #tsp::compile assert

    global mute

    if {$mute} {
        return
    }

    upvar #0 $varName var

    if {!$var} {
        return
    }

    analysis $ident [uplevel [list subst $conclusionCode]] [style_from_var $varName]
}

set var1 0
set var2 1

analysis_subst_if var1 foo "this should not emit"
analysis_subst_if var2 foo "this should emit"
@lehenbauer
Copy link
Author

This compiles and works if the upvar target, var, is defined as a var instead of a boolean and a separate boolean var is used...

    #tsp::var var
    #tsp::boolean bool

...

    upvar #0 $varName var
    set bool $var

    if {!$bool} {
        return
    }

@lehenbauer
Copy link
Author

Perhaps tsp should be using Tcl_UpVar to link a local obj to the correct frame and variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant