From d3e694c5298f61ae81ca3a89a05f0ce2447008b3 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 10 Feb 2019 06:56:06 +0100 Subject: [PATCH] core: Initialize g_buf dynamically, add MES_STRING_MAX override. * src/mes.c (g_buf, MAX_STRING): Move from strings.c. (gc_init_cells): Initialize g_buf dynamically. (main): Add environment override MES_MAX_STRING for MAX_STRING. * doc/mes.texi (Environment Variables): Document it. --- doc/mes.texi | 5 +++++ src/mes.c | 10 ++++++++++ src/strings.c | 5 +---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/mes.texi b/doc/mes.texi index 1b0a72cd..cef8cd0c 100644 --- a/doc/mes.texi +++ b/doc/mes.texi @@ -757,6 +757,11 @@ The initial size of the arena @pxref{5.3,,, sicp, SICP} in cells. Default: 20,0 The maximum size of the arena in cells. Default: 100,000,000. +@item MES_MAX_STRING +@vindex MES_MAX_STRING + +The maximum size of a string. Default: 524,288. + @item MES_DEBUG @vindex MES_DEBUG diff --git a/src/mes.c b/src/mes.c index 804b8080..ae4e7509 100644 --- a/src/mes.c +++ b/src/mes.c @@ -38,12 +38,16 @@ long STACK_SIZE = 20000; long JAM_SIZE = 20000; long GC_SAFETY = 2000; +long MAX_STRING = 524288; + char *g_arena = 0; typedef long SCM; int g_debug = 0; long g_free = 0; +char *g_buf = 0; + SCM g_continuations = 0; SCM g_symbols = 0; SCM g_stack = 0; @@ -1647,6 +1651,10 @@ gc_init_cells () ///((internal)) g_cells++; TYPE (0) = TCHAR; VALUE (0) = 'c'; + + // FIXME: remove MES_MAX_STRING, grow dynamically + g_buf = (char*)malloc (MAX_STRING); + return 0; } @@ -2276,6 +2284,8 @@ main (int argc, char *argv[]) GC_SAFETY = atoi (p); if (p = getenv ("MES_STACK")) STACK_SIZE = atoi (p); + if (p = getenv ("MES_MAX_STRING")) + MAX_STRING = atoi (p); g_stdin = STDIN; g_stdout = STDOUT; g_stderr = STDERR; diff --git a/src/strings.c b/src/strings.c index 7f03fa23..3aec0f9f 100644 --- a/src/strings.c +++ b/src/strings.c @@ -18,13 +18,10 @@ * along with GNU Mes. If not, see . */ -#define MAX_STRING 524288 -char g_buf[MAX_STRING]; - void assert_max_string (size_t i, char const* msg, char* string) { - if (i > MAX_STRING) // Mes must be able to make g_buf + if (i > MAX_STRING) { eputs (msg); eputs (":string too long[");