Exemple #1
0
static void get_exported(const env_node_t *n, std::map<wcstring, wcstring> *h)
{
    if (!n)
        return;

    if (n->new_scope)
        get_exported(global_env, h);
    else
        get_exported(n->next, h);

    var_table_t::const_iterator iter;
    for (iter = n->env.begin(); iter != n->env.end(); ++iter)
    {
        const wcstring &key = iter->first;
        const var_entry_t &val_entry = iter->second;

        if (val_entry.exportv && val_entry.val != ENV_NULL)
        {
            // Export the variable
            // Don't use std::map::insert here, since we need to overwrite existing
            // values from previous scopes
            (*h)[key] = val_entry.val;
        }
        else
        {
            // We need to erase from the map if we are not exporting,
            // since a lower scope may have exported. See #2132
            h->erase(key);
        }
    }
}
Exemple #2
0
static void update_export_array_if_necessary(bool recalc) {
    ASSERT_IS_MAIN_THREAD();
    if (recalc && !get_proc_had_barrier()) {
        set_proc_had_barrier(true);
        env_universal_barrier();
    }

    if (has_changed_exported) {
        std::map<wcstring, wcstring> vals;

        debug(4, L"env_export_arr() recalc");

        get_exported(top, &vals);

        if (uvars()) {
            const wcstring_list_t uni = uvars()->get_names(true, false);
            for (size_t i = 0; i < uni.size(); i++) {
                const wcstring &key = uni.at(i);
                const env_var_t val = uvars()->get(key);

                if (!val.missing() && val != ENV_NULL) {
                    // Note that std::map::insert does NOT overwrite a value already in the map,
                    // which we depend on here.
                    vals.insert(std::pair<wcstring, wcstring>(key, val));
                }
            }
        }

        std::vector<std::string> local_export_buffer;
        export_func(vals, local_export_buffer);
        export_array.set(local_export_buffer);
        has_changed_exported = false;
    }
}
Exemple #3
0
static void get_exported(const env_node_t *n, std::map<wcstring, wcstring> &h)
{
    if (!n)
        return;

    if (n->new_scope)
        get_exported(global_env, h);
    else
        get_exported(n->next, h);

    var_table_t::const_iterator iter;
    for (iter = n->env.begin(); iter != n->env.end(); ++iter)
    {
        const wcstring &key = iter->first;
        const var_entry_t &val_entry = iter->second;
        if (val_entry.exportv && (val_entry.val != ENV_NULL))
        {
            // Don't use std::map::insert here, since we need to overwrite existing values from previous scopes
            h[key] = val_entry.val;
        }
    }
}
Exemple #4
0
static void update_export_array_if_necessary(bool recalc)
{
    ASSERT_IS_MAIN_THREAD();
    if (recalc && ! get_proc_had_barrier())
    {
        set_proc_had_barrier(true);
        env_universal_barrier();
    }

    if (has_changed_exported)
    {
        std::map<wcstring, wcstring> vals;
        size_t i;

        debug(4, L"env_export_arr() recalc");

        get_exported(top, vals);

        wcstring_list_t uni;
        env_universal_get_names2(uni, 1, 0);
        for (i=0; i<uni.size(); i++)
        {
            const wcstring &key = uni.at(i);
            const wchar_t *val = env_universal_get(key.c_str());

            if (wcscmp(val, ENV_NULL))
            {
                // Note that std::map::insert does NOT overwrite a value already in the map,
                // which we depend on here
                vals.insert(std::pair<wcstring, wcstring>(key, val));
            }
        }

        std::vector<std::string> local_export_buffer;
        export_func(vals, local_export_buffer);
        export_array.set(local_export_buffer);
        has_changed_exported=false;
    }

}