From a60cc1e98c6c6b97bdf7ed20b4b455cf745ea8df Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 21 Jun 2009 17:26:36 +0900 Subject: [PATCH] fixing bug in loading init.scm file --- Makefile | 4 ++-- eval.c | 2 ++ main.c | 8 ++++---- sexp.c | 8 ++++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8566af34..0875ec19 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ XCPPFLAGS := $(CPPFLAGS) -Iinclude endif XLDFLAGS := $(LDFLAGS) $(GCLDFLAGS) -lm -XCFLAGS := $(CFLAGS) -Wall -O2 -g +XCFLAGS := $(CFLAGS) -Wall -g INCLUDES = include/chibi/sexp.h include/chibi/config.h include/chibi/install.h @@ -100,7 +100,7 @@ install: chibi-scheme uninstall: rm -f $(BINDIR)/chibi-scheme* - rm -f $(LIBDIR)/libchibischeme$(SO) + rm -f $(LIBDIR)/libchibi-scheme$(SO) cd $(INCDIR) && rm -f $(INCLUDES) include/chibi/eval.h rm -f $(MODDIR)/*.scm diff --git a/eval.c b/eval.c index f920fae6..b5faadd9 100644 --- a/eval.c +++ b/eval.c @@ -1828,6 +1828,8 @@ static sexp sexp_open_output_file (sexp ctx, sexp path) { static sexp sexp_close_port (sexp ctx, sexp port) { fclose(sexp_port_stream(port)); + if (sexp_port_buf(port)) + free(sexp_port_buf(port)); return SEXP_VOID; } diff --git a/main.c b/main.c index b09a2f87..42f2d858 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* main.c -- chibi-scheme command-line app using */ +/* main.c -- chibi-scheme command-line app */ /* Copyright (c) 2009 Alex Shinn. All rights reserved. */ /* BSD-style license: http://synthcode.com/license.txt */ @@ -24,11 +24,11 @@ sexp find_module_file (sexp ctx, char *file) { flen = strlen(file); path = (char*) malloc(mlen+flen+2); memcpy(path, chibi_module_dir, mlen); - path[mlen+1] = '/'; + path[mlen] = '/'; memcpy(path+mlen+1, file, flen); - path[mlen+flen] = '\0'; + path[mlen+flen+1] = '\0'; if (! stat(path, &buf)) - res = sexp_c_string(ctx, path, mlen+flen+1); + res = sexp_c_string(ctx, path, mlen+flen+2); else res = SEXP_FALSE; free(path); diff --git a/sexp.c b/sexp.c index aade93c1..82c0b73d 100644 --- a/sexp.c +++ b/sexp.c @@ -625,12 +625,15 @@ sexp sexp_get_output_string (sexp ctx, sexp port) { sexp sexp_make_input_string_port (sexp ctx, sexp str) { FILE *in = fmemopen(sexp_string_data(str), sexp_string_length(str), "r"); - return sexp_make_input_port(ctx, in, SEXP_FALSE); + sexp res = sexp_make_input_port(ctx, in, SEXP_FALSE); + sexp_port_cookie(res) = str; /* for gc preservation */ + return res; } sexp sexp_make_output_string_port (sexp ctx) { sexp res = sexp_make_output_port(ctx, NULL, SEXP_FALSE); - sexp_port_stream(res) = open_memstream(&sexp_port_buf(res), &sexp_port_size(res)); + sexp_port_stream(res) + = open_memstream(&sexp_port_buf(res), &sexp_port_size(res)); return res; } @@ -656,6 +659,7 @@ sexp sexp_make_output_port (sexp ctx, FILE* out, sexp name) { sexp_port_stream(p) = out; sexp_port_name(p) = name; sexp_port_line(p) = 0; + sexp_port_buf(p) = NULL; return p; }