<commit_before>#include "imap_engine.h"
#include "logger.h"
#include "uv_util.h"

static void imape_data_onthread_start(imape_data_t *id);

static void imape_pass_event(engine_t *imap_engine, event_t *ev){
    imape_t *imape = CONTAINER_OF(imap_engine, imape_t, engine);
    queue_append(&imape->event_q, &ev->link);
}

static derr_t imape_worker_new(imape_t *imape, imape_worker_t **out){
    derr_t e = E_OK;
    imape_worker_t *worker = malloc(sizeof(*worker));
    if(worker == NULL){
        *out = NULL;
        ORIG(&e, E_NOMEM, "unable to alloc worker");
    }

    link_init(&worker->link);
    worker->quitting = false;
    worker->imape = imape;
    worker->work_req.data = worker;

    *out = worker;

    return e;

}

static void imape_worker_free(imape_worker_t *worker){
    // currently nothing in the imape_worker_t needs cleanup
    free(worker);
}

static void worker_process_event(imape_data_t *id, event_t *ev){
    session_t *session = id->session;
    // this should *really* never happen, so it's not critical to handle it
    if(session != ev->session){
        LOG_ERROR("mismatched session!");
    }

    /* Note: we check id->data_state == DATA_STATE_CLOSED in all cases.  The
       error handling is very similar to what the main imape_t thread does,
       except that the imap_engine's checks can only guarantee protection
       against failure-to-start sessions.  Here we actually can guarantee
       protection aginst started-then-closed sessions, because the imap_worker
       is the only place where onthread_close is ever called. */
    if(id->data_state == DATA_STATE_CLOSED){
        ev->returner(ev);
        return;
    }

    // catch session close events
    if(ev->ev_type == EV_SESSION_CLOSE){
        imape_data_onthread_close(id);
        id->ref_down(ev->session, IMAPE_REF_CLOSE_EVENT);
        return;
    }

    // pass the event to the logic<commit_msg>fix segfault due to out-of-order check in imap_engine<commit_after>#include "imap_engine.h"
#include "logger.h"
#include "uv_util.h"

static void imape_data_onthread_start(imape_data_t *id);

static void imape_pass_event(engine_t *imap_engine, event_t *ev){
    imape_t *imape = CONTAINER_OF(imap_engine, imape_t, engine);
    queue_append(&imape->event_q, &ev->link);
}

static derr_t imape_worker_new(imape_t *imape, imape_worker_t **out){
    derr_t e = E_OK;
    imape_worker_t *worker = malloc(sizeof(*worker));
    if(worker == NULL){
        *out = NULL;
        ORIG(&e, E_NOMEM, "unable to alloc worker");
    }

    link_init(&worker->link);
    worker->quitting = false;
    worker->imape = imape;
    worker->work_req.data = worker;

    *out = worker;

    return e;

}

static void imape_worker_free(imape_worker_t *worker){
    // currently nothing in the imape_worker_t needs cleanup
    free(worker);
}

static void worker_process_event(imape_data_t *id, event_t *ev){
    session_t *session = id->session;
    // this should *really* never happen, so it's not critical to handle it
    if(session != ev->session){
        LOG_ERROR("mismatched session!");
    }

    // catch session close events
    if(ev->ev_type == EV_SESSION_CLOSE){
        imape_data_onthread_close(id);
        id->ref_down(ev->session, IMAPE_REF_CLOSE_EVENT);
        return;
    }

    /* Note: we check id->data_state == DATA_STATE_CLOSED in all cases.  The
       error handling is very similar to what the main imape_t thread does,
       except that the imap_engine's checks can only guarantee protection
       against failure-to-start sessions.  Here we actually can guarantee
       protection aginst started-then-closed sessions, because the imap_worker
       is the only place where onthread_close is ever called. */
    if(id->data_state == DATA_STATE_CLOSED){
        ev->returner(ev);
        return;
    }

    // pass the event to the logic
{'fraction_non_alphanumeric': 0.10368066355624676, 'fraction_numerical': 0.0, 'mean_word_length': 3.3262331838565022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '7168481', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1269, 'n_words': 340}