summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2013-11-16 23:24:42 -0500
committerMark H Weaver <mhw@netris.org>2013-11-18 00:14:23 -0500
commit750ac8c592e792e627444f476877f282525b132e (patch)
treeead60c4c32b65692ea88227be877ba23bcde86fb
parent363df6cf108763e24eb5cb149131a3fa3f400734 (diff)
downloadguile-750ac8c592e792e627444f476877f282525b132e.tar.gz
Improve error when 'include' form with relative path is not in a file.
Reported by Nala Ginrut <nalaginrut@gmail.com>. * module/ice-9/psyntax.scm (include): Give a proper error message when given a relative file name, and when the form is not in a file. * module/ice-9/psyntax-pp.scm: Regenerate.
-rw-r--r--module/ice-9/psyntax-pp.scm9
-rw-r--r--module/ice-9/psyntax.scm12
2 files changed, 17 insertions, 4 deletions
diff --git a/module/ice-9/psyntax-pp.scm b/module/ice-9/psyntax-pp.scm
index 254f7018b..7b801ad24 100644
--- a/module/ice-9/psyntax-pp.scm
+++ b/module/ice-9/psyntax-pp.scm
@@ -2974,7 +2974,14 @@
((read-file
(lambda (fn dir k)
(let ((p (open-input-file
- (if (absolute-file-name? fn) fn (in-vicinity dir fn)))))
+ (if (absolute-file-name? fn)
+ fn
+ (if dir
+ (in-vicinity dir fn)
+ (syntax-violation
+ 'include
+ "relative file name only allowed when the include form is in a file"
+ x))))))
(let ((enc (file-encoding p)))
(set-port-encoding! p (let ((t enc)) (if t t "UTF-8")))
(let f ((x (read p)) (result '()))
diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm
index 576fc3ff7..5f1bd8ae4 100644
--- a/module/ice-9/psyntax.scm
+++ b/module/ice-9/psyntax.scm
@@ -2952,9 +2952,15 @@
(define read-file
(lambda (fn dir k)
(let* ((p (open-input-file
- (if (absolute-file-name? fn)
- fn
- (in-vicinity dir fn))))
+ (cond ((absolute-file-name? fn)
+ fn)
+ (dir
+ (in-vicinity dir fn))
+ (else
+ (syntax-violation
+ 'include
+ "relative file name only allowed when the include form is in a file"
+ x)))))
(enc (file-encoding p)))
;; Choose the input encoding deterministically.