Fast and reasonably complete (framebuffer) terminal emulator (Zig fork)

Limit bump allocated terminal instances to 1

mintsuki 9cb38e20 1d6e5855

Changed files
+19 -3
backends
+19 -3
backends/fb.c
···
#include <stdint.h>
#include <stddef.h>
+
#include <stdbool.h>
#include "../flanterm.h"
#include "fb.h"
···
bump_alloc_ptr = next_ptr;
return ret;
}
+
+
static bool bump_allocated_instance = false;
#endif
···
struct flanterm_fb_context *ctx = (void *)_ctx;
if (_free == NULL) {
+
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
+
if (bump_allocated_instance == true) {
+
bump_alloc_ptr = 0;
+
bump_allocated_instance = false;
+
}
+
#endif
return;
}
···
size_t margin
) {
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
-
size_t orig_bump_alloc_ptr = bump_alloc_ptr;
-
// Limit terminal size if needed
if (width > FLANTERM_FB_WIDTH_LIMIT || height > FLANTERM_FB_HEIGHT_LIMIT) {
size_t width_limit = width > FLANTERM_FB_WIDTH_LIMIT ? FLANTERM_FB_WIDTH_LIMIT : width;
···
if (_malloc == NULL) {
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
+
if (bump_allocated_instance == true) {
+
return NULL;
+
}
_malloc = bump_alloc;
#else
return NULL;
···
flanterm_context_reinit(_ctx);
flanterm_fb_full_refresh(_ctx);
+
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
+
if (_malloc == bump_alloc) {
+
bump_allocated_instance = true;
+
}
+
#endif
+
return _ctx;
fail:
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
if (_malloc == bump_alloc) {
-
bump_alloc_ptr = orig_bump_alloc_ptr;
+
bump_alloc_ptr = 0;
return NULL;
#endif