<commit_before>#include "ptk/assert.h"
#include "stm32f4xx.h"

#if defined(PTK_USE_CC_STUBS)

void *operator new[](unsigned size) {
  ptk_halt("unimplemented: operator new[]()");
  // not reached
  return (void *) 0xffffffff;
}

void operator delete(void *ptr) {
  ptk_halt("unimplemented: operator delete()");
}

extern "C" {
  void __cxa_pure_virtual() {
    ptk_halt("unimplemented: pure virtual");
  }

  void *__dso_handle = NULL;

  void _exit(int status) {
    (void) status;
    ptk_halt("exit");
  }

  pid_t _getpid(void) {
    return 1;
  }

  void _kill(pid_t id) {
    (void) id;
  }

  void *_sbrk(int incr) {
    extern unsigned long _bss_end; // Defined by the linker
    static char *limit = 0;

    if (limit == 0) limit = (char *) &_bss_end;

    void *allocated = limit;

    char *stack = (char *) __get_MSP();
    if (limit + incr > stack) {
      ptk_halt("out of memory");
    }

    limit += incr;
    return allocated;
  }
};

#endif // defined(PTK_USE_CC_STUBS)
<commit_msg>comments<commit_after>#include "ptk/assert.h"
#include "stm32f4xx.h"

#if defined(PTK_USE_CC_STUBS)

void *operator new[](unsigned size) {
  ptk_halt("unimplemented: operator new[]()");
  // not reached
  return (void *) 0xffffffff;
}

void operator delete(void *ptr) {
  ptk_halt("unimplemented: operator delete()");
}

extern "C" {
  void __cxa_pure_virtual() {
    ptk_halt("unimplemented: pure virtual");
  }

  void *__dso_handle = NULL;

  void _exit(int status) {
    (void) status;
    ptk_halt("exit");
  }

  pid_t _getpid(void) {
    return 1;
  }

  void _kill(pid_t id) {
    (void) id;
  }

  void *_sbrk(int incr) {
    extern unsigned long _bss_end; // Defined by the linker
    static char *limit = 0;

    if (limit == 0) limit = (char *) &_bss_end;

    void *allocated = limit;

    char *main_stack_pointer = (char *) __get_MSP();
    if (limit + incr > main_stack_pointer) {
      ptk_halt("out of memory");
    }

    // NOTE: even if we get here, the stack can collide with the heap later on

    limit += incr;
    return allocated;
  }
};

#endif // defined(PTK_USE_CC_STUBS)

{'fraction_non_alphanumeric': 0.1398002853067047, 'fraction_numerical': 0.006657156443176415, 'mean_word_length': 3.191235059760956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '449270', 'n_tokens_mistral': 835, 'n_tokens_neox': 799, 'n_words': 197}