<commit_before>#include <Python.h>

PyObject *slow_module = NULL;


PyObject *
slow(char *name, PyObject *args, PyObject *kwds)
{
    PyObject *func = NULL;
    PyObject *out = NULL;

    if (slow_module == NULL) {
        slow_module = PyImport_ImportModule("bottleneck.slow");
    }

    if (slow_module != NULL) {
        func = PyObject_GetAttrString(slow_module, name);
        if (func && PyCallable_Check(func)) {
            out = PyObject_Call(func, args, kwds);
            if (out == NULL) {
                Py_DECREF(func);
                return NULL;
            }
        }
        else {
            if (PyErr_Occurred())
                PyErr_Print();
        }
        Py_XDECREF(func);
    }
    else {
        PyErr_Print();
        fprintf(stderr, "Failed to load \"%s\"\n", name);
        return NULL;
    }<commit_msg>handle runtime errors in slow.c<commit_after>#include <Python.h>

static PyObject *slow_module = NULL;


PyObject *
slow(char *name, PyObject *args, PyObject *kwds)
{
    PyObject *func = NULL;
    PyObject *out = NULL;

    if (slow_module == NULL) {
        /* bottleneck.slow has not been imported during the current
         * python session. Only import it once per session to save time*/
        slow_module = PyImport_ImportModule("bottleneck.slow");
        if (slow_module == NULL) {
            PyErr_SetString(PyExc_RuntimeError,
                            "Cannot import bottleneck.slow");
            return NULL;
        }
    }

    func = PyObject_GetAttrString(slow_module, name);
    if (func == NULL) {
        PyErr_Format(PyExc_RuntimeError,
                     "Cannot import %s from bottleneck.slow", name);
        return NULL;
    }
    if (PyCallable_Check(func)) {
        out = PyObject_Call(func, args, kwds);
        if (out == NULL) {
            Py_XDECREF(func);
            return NULL;
        }
    }
    else {
        Py_XDECREF(func);
        PyErr_Format(PyExc_RuntimeError,
                     "bottleneck.slow.%s is not callable", name);
        return NULL;
    }
    Py_XDECREF(func);
{'fraction_non_alphanumeric': 0.10907335907335908, 'fraction_numerical': 0.0, 'mean_word_length': 1.9404255319148935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3474508', 'n_tokens_mistral': 654, 'n_tokens_neox': 637, 'n_words': 153}