Files
armorpaint/base/sources/iron_gc.c
T

129 lines
1.7 KiB
C
Raw Normal View History

2024-11-10 22:11:29 +01:00
#include "iron_gc.h"
#ifdef NO_GC
#include <memory.h>
2024-11-10 22:11:29 +01:00
#include <stdint.h>
2025-10-15 13:06:40 +02:00
#include <stdlib.h>
2025-11-11 12:33:29 +01:00
#include <string.h>
2024-11-10 22:11:29 +01:00
#define HEAP_SIZE 512 * 1024 * 1024
2025-10-15 13:06:40 +02:00
static uint8_t *heap = NULL;
static size_t heap_top = 0;
2024-11-10 22:11:29 +01:00
void *gc_alloc(size_t size) {
2025-10-15 13:06:40 +02:00
#ifdef HEAP_SIZE
2024-11-10 22:11:29 +01:00
size_t old_top = heap_top;
heap_top += size;
return &heap[old_top];
2025-10-15 13:06:40 +02:00
#else
2024-11-10 22:11:29 +01:00
return calloc(size, 1);
2025-10-15 13:06:40 +02:00
#endif
2024-11-10 22:11:29 +01:00
}
2025-10-15 13:06:40 +02:00
void gc_array(void *ptr, int *length) {}
2024-11-10 22:11:29 +01:00
2025-10-15 13:06:40 +02:00
void gc_leaf(void *ptr) {}
2024-11-10 22:11:29 +01:00
2025-10-15 13:06:40 +02:00
void gc_root(void *ptr) {}
2024-11-10 22:11:29 +01:00
2025-10-15 13:06:40 +02:00
void gc_unroot(void *ptr) {}
2024-11-10 22:11:29 +01:00
void *gc_cut(void *ptr, size_t pos, size_t size) {
return NULL;
}
void *gc_realloc(void *ptr, size_t size) {
2025-10-15 13:06:40 +02:00
#ifdef HEAP_SIZE
void *new_ptr = gc_alloc(size);
if (ptr != NULL) {
memcpy(new_ptr, ptr, size);
}
return new_ptr;
2025-10-15 13:06:40 +02:00
#else
2024-11-10 22:11:29 +01:00
return realloc(ptr, size);
2025-10-15 13:06:40 +02:00
#endif
2024-11-10 22:11:29 +01:00
}
void gc_free(void *ptr) {
2025-10-15 13:06:40 +02:00
#ifdef HEAP_SIZE
#else
2024-11-10 22:11:29 +01:00
free(ptr);
2025-10-15 13:06:40 +02:00
#endif
2024-11-10 22:11:29 +01:00
}
2025-10-15 13:06:40 +02:00
void gc_pause() {}
2024-11-10 22:11:29 +01:00
2025-10-15 13:06:40 +02:00
void gc_resume() {}
2024-11-10 22:11:29 +01:00
2025-10-15 13:06:40 +02:00
void gc_run() {}
2024-11-10 22:11:29 +01:00
void gc_start(void *bos) {
2025-10-15 13:06:40 +02:00
#ifdef HEAP_SIZE
2024-11-10 22:11:29 +01:00
heap = (uint8_t *)calloc(HEAP_SIZE, 1);
2025-10-15 13:06:40 +02:00
#endif
2024-11-10 22:11:29 +01:00
}
2025-10-15 13:06:40 +02:00
void gc_stop() {}
2024-11-10 22:11:29 +01:00
#else
#include <gc.h>
void *gc_alloc(size_t size) {
return _gc_calloc(size, sizeof(uint8_t));
}
void gc_array(void *ptr, int *length) {
_gc_array(ptr, length);
}
void gc_leaf(void *ptr) {
_gc_leaf(ptr);
}
void gc_root(void *ptr) {
_gc_root(ptr);
}
void gc_unroot(void *ptr) {
_gc_unroot(ptr);
}
void *gc_cut(void *ptr, size_t pos, size_t size) {
return _gc_cut(ptr, pos, size);
}
void *gc_realloc(void *ptr, size_t size) {
return ptr == NULL ? gc_alloc(size) : _gc_realloc(ptr, size);
}
void gc_free(void *ptr) {
if (ptr != NULL) {
_gc_free(ptr);
}
}
void gc_pause() {
_gc_pause();
}
void gc_resume() {
_gc_resume();
}
void gc_run() {
_gc_run();
}
void gc_start(void *bos) {
2025-10-15 13:06:40 +02:00
_gc_start(bos);
2024-11-10 22:11:29 +01:00
}
void gc_stop() {
2025-10-15 13:06:40 +02:00
_gc_stop();
2024-11-10 22:11:29 +01:00
}
#endif