<commit_before>// Fixed size rational numbers exposed to Python

#define NPY_NO_DEPRECATED_API

#include <stdint.h>
#include <math.h>
#include <Python/Python.h>
#include <Python/structmember.h>
#include <numpy/arrayobject.h>
#include <numpy/ufuncobject.h>

// Relevant arithmetic exceptions

static void set_overflow(void) {
    PyGILState_STATE state = PyGILState_Ensure(); // Need to grab the GIL to dodge a bug in numpy
    if (!PyErr_Occurred())
        PyErr_SetString(PyExc_OverflowError,"overflow in rational arithmetic");
    PyGILState_Release(state);
}

static void set_zero_divide(void) {
    PyGILState_STATE state = PyGILState_Ensure(); // Need to grab the GIL to dodge a bug in numpy
    if (!PyErr_Occurred())
        PyErr_SetString(PyExc_ZeroDivisionError,"zero divide in rational arithmetic");
    PyGILState_Release(state);
}

// Integer arithmetic utilities

static inline int32_t safe_neg(int32_t x) {
    if (x==(int32_t)1<<31)
        set_overflow();
    return -x;
}

static inline int32_t safe_abs32(int32_t x) {
    if (x>=0)
        return x;
    int32_t nx = -x;
    if (nx<0)
        set_overflow();
    return nx;
}

static inline int64_t safe_abs64(int64_t x) {
    if (x>=0)<commit_msg>Disable GIL acquiring by default<commit_after>// Fixed size rational numbers exposed to Python

#define NPY_NO_DEPRECATED_API

#include <stdint.h>
#include <math.h>
#include <Python/Python.h>
#include <Python/structmember.h>
#include <numpy/arrayobject.h>
#include <numpy/ufuncobject.h>

// Relevant arithmetic exceptions

// Uncomment the following line to work around a bug in numpy
//#define ACQUIRE_GIL

static void set_overflow(void) {
#ifdef ACQUIRE_GIL
    PyGILState_STATE state = PyGILState_Ensure(); // Need to grab the GIL to dodge a bug in numpy
#endif
    if (!PyErr_Occurred())
        PyErr_SetString(PyExc_OverflowError,"overflow in rational arithmetic");
#ifdef ACQUIRE_GIL
    PyGILState_Release(state);
#endif
}

static void set_zero_divide(void) {
#ifdef ACQUIRE_GIL
    PyGILState_STATE state = PyGILState_Ensure(); // Need to grab the GIL to dodge a bug in numpy
#endif
    if (!PyErr_Occurred())
        PyErr_SetString(PyExc_ZeroDivisionError,"zero divide in rational arithmetic");
#ifdef ACQUIRE_GIL
    PyGILState_Release(state);
#endif
}

// Integer arithmetic utilities

static inline int32_t safe_neg(int32_t x) {
    if (x==(int32_t)1<<31)
        set_overflow();
    return -x;
}

static inline int32_t safe_abs32(int32_t x) {
    if (x>=0)
        return x;
    int32_t nx = -x;
    if (nx<0)
        set_overflow();
    return nx;
}

static inline int64_t safe_abs64(int64_t x) {
    if (x>=0)
{'fraction_non_alphanumeric': 0.10249621785173979, 'fraction_numerical': 0.019667170953101363, 'mean_word_length': 3.953183520599251, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, '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': '6734316', 'n_tokens_mistral': 997, 'n_tokens_neox': 941, 'n_words': 250}