fixing bug in loading init.scm file

This commit is contained in:
Alex Shinn 2009-06-21 17:26:36 +09:00
parent cafb396745
commit a60cc1e98c
4 changed files with 14 additions and 8 deletions

View file

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

2
eval.c
View file

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

8
main.c
View file

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

8
sexp.c
View file

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