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.
This commit is contained in:
Jan Nieuwenhuizen 2019-02-10 06:56:06 +01:00
parent f43af6acc3
commit d3e694c529
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
3 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -18,13 +18,10 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#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[");