<commit_before>/*
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include "library/library_task_builder.h"
#include "library/message_builder.h"

namespace lean {

struct library_scopes_imp : public delegating_task_imp {
    io_state m_ios;
    log_tree::node m_lt;

    library_scopes_imp(std::unique_ptr<gtask_imp> && base, log_tree::node const & lt) :
        delegating_task_imp(std::forward<std::unique_ptr<gtask_imp>>(base)),
        m_ios(get_global_ios()), m_lt(lt) {}

    // TODO(gabriel): set logtree status to cancelled?

    void execute(void * result) override {
        scope_global_ios scope1(m_ios);
        scope_log_tree scope2(m_lt);
        if (m_lt) m_lt.set_state(log_tree::state::Running);
        try {
            delegating_task_imp::execute(result);
        } catch (interrupted) {
            m_lt.set_state(log_tree::state::Cancelled);
        }
    }
};<commit_msg>fix(library/library_task_builder): fix segfault in cancellation<commit_after>/*
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include "library/library_task_builder.h"
#include "library/message_builder.h"

namespace lean {

struct library_scopes_imp : public delegating_task_imp {
    io_state m_ios;
    log_tree::node m_lt;

    library_scopes_imp(std::unique_ptr<gtask_imp> && base, log_tree::node const & lt) :
        delegating_task_imp(std::forward<std::unique_ptr<gtask_imp>>(base)),
        m_ios(get_global_ios()), m_lt(lt) {}

    // TODO(gabriel): set logtree status to cancelled?

    void execute(void * result) override {
        scope_global_ios scope1(m_ios);
        scope_log_tree scope2(m_lt);
        if (m_lt) m_lt.set_state(log_tree::state::Running);
        try {
            delegating_task_imp::execute(result);
        } catch (interrupted) {
            if (m_lt) m_lt.set_state(log_tree::state::Cancelled);
        }
    }
};
{'fraction_non_alphanumeric': 0.11575875486381323, 'fraction_numerical': 0.007782101167315175, 'mean_word_length': 3.717889908256881, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7572285', 'n_tokens_mistral': 696, 'n_tokens_neox': 680, 'n_words': 138}