<commit_before>#include "signal_handler.h"
#include <signal.h>
#include <stdlib.h>

#if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
#define IS_WINDOWS
#endif

#if defined(IS_WINDOWS)
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal
static const int bsg_native_signals[] = {SIGILL, SIGABRT, SIGFPE, SIGSEGV};
#else
static const int bsg_native_signals[] = {SIGILL, SIGTRAP, SIGABRT,
                                         SIGBUS, SIGFPE,  SIGSEGV};
#endif

static const int SIGNAL_COUNT = sizeof(bsg_native_signals) / sizeof(int);
static void (*prev_handlers[SIGNAL_COUNT])(int);

void becs_signal_install(void (*func)(int)) {
  for (int i = 0; i < SIGNAL_COUNT; i++) {
    const int sig = bsg_native_signals[i];
    prev_handlers[i] = signal(sig, func);
  }
}

void becs_signal_uninstall() {
  for (int i = 0; i < SIGNAL_COUNT; i++) {
    const int sig = bsg_native_signals[i];
    signal(sig, prev_handlers[i]);
  }
}

void becs_signal_raise(int _sig) {
  for (int i = 0; i < SIGNAL_COUNT; i++) {
    const int sig = bsg_native_signals[i];
    if (sig == _sig) {
      void (*prev)(int) = prev_handlers[i];
      if (prev == SIG_DFL) {
        raise(_sig);
      } else if (prev != NULL && prev != SIG_IGN) {
        prev(_sig);
      }
    }
  }
}
<commit_msg>fix(sync): avoid file scope dynamic array size for gcc<commit_after>#include "signal_handler.h"
#include <signal.h>
#include <stdlib.h>

#if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
#define IS_WINDOWS
#endif

#if defined(IS_WINDOWS)
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal
static const int bsg_native_signals[] = {SIGILL, SIGABRT, SIGFPE, SIGSEGV};
#define SIGNAL_COUNT 4
#else
static const int bsg_native_signals[] = {SIGILL, SIGTRAP, SIGABRT,
                                         SIGBUS, SIGFPE,  SIGSEGV};
#define SIGNAL_COUNT 6
#endif

static void (*prev_handlers[SIGNAL_COUNT])(int);

void becs_signal_install(void (*func)(int)) {
  for (int i = 0; i < SIGNAL_COUNT; i++) {
    const int sig = bsg_native_signals[i];
    prev_handlers[i] = signal(sig, func);
  }
}

void becs_signal_uninstall() {
  for (int i = 0; i < SIGNAL_COUNT; i++) {
    const int sig = bsg_native_signals[i];
    signal(sig, prev_handlers[i]);
  }
}

void becs_signal_raise(int _sig) {
  for (int i = 0; i < SIGNAL_COUNT; i++) {
    const int sig = bsg_native_signals[i];
    if (sig == _sig) {
      void (*prev)(int) = prev_handlers[i];
      if (prev == SIG_DFL) {
        raise(_sig);
      } else if (prev != NULL && prev != SIG_IGN) {
        prev(_sig);
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.14541301865245526, 'fraction_numerical': 0.006090597639893415, 'mean_word_length': 3.4093959731543624, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3312222', 'n_tokens_mistral': 998, 'n_tokens_neox': 967, 'n_words': 224}