我是一个尝试使用 sbcl v1.0.50 学习 lisp 的 lisp 菜鸟。
我正在编写一个简单的记录器并遇到了我不理解的内存错误,但这似乎与我如何编译我的脚本有关。我把它归结为以下几点:
===logger.lisp===
(defparameter *log-stream* (open "/tmp/global-log"
:direction :output
:if-does-not-exist :create
:if-exists :append))
===main.lisp===
(load "logger.lisp")
(defun main ()
(format *log-stream* "Hello world~%"))
==编译.lisp==
#! /usr/bin/sbcl --script
(load "main.lisp")
(save-lisp-and-die "program" :toplevel #'main :executable t)
当我编译并运行程序时它崩溃了:
> ./compile.lisp
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into foo:
writing 6352 bytes from the read-only space at 0x20000000
writing 4064 bytes from the static space at 0x20100000
writing 43057152 bytes from the dynamic space at 0x1000000000
> ./program
CORRUPTION WARNING in SBCL pid 21860(tid 140737353914112):
Memory fault at f6977000 (pc=0x1000036365, sp=0x7ffff6b7f8d0)
The integrity of this image is possibly compromised.
Continuing with fingers crossed.
unhandled SB-SYS:MEMORY-FAULT-ERROR in thread #<SB-THREAD:THREAD
"initial thread" RUNNING
{10029118D1}>:
Unhandled memory fault at #x7FFFF6977000.
0: (SB-DEBUG::MAP-BACKTRACE
#<CLOSURE (LAMBDA #) {100291A3C9}>
:START
0
:COUNT
128)
1: (BACKTRACE 128 #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDERR* {100001CEB1}>)
2: (SB-DEBUG::DEBUGGER-DISABLED-HOOK
#<SB-SYS:MEMORY-FAULT-ERROR {10029180E1}>
#<unavailable argument>)
3: (SB-DEBUG::RUN-HOOK
*INVOKE-DEBUGGER-HOOK*
#<SB-SYS:MEMORY-FAULT-ERROR {10029180E1}>)
4: (INVOKE-DEBUGGER #<SB-SYS:MEMORY-FAULT-ERROR {10029180E1}>)
5: (ERROR SB-SYS:MEMORY-FAULT-ERROR :ADDRESS 140737330507776)
6: (SB-SYS:MEMORY-FAULT-ERROR)
7: ("foreign function: #x4174A0")
8: ("foreign function: #x417580")
9: (SB-IMPL::OUTPUT-BYTES/UTF-8
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>
"AAAA"
NIL
0
4)
10: (SB-IMPL::FD-SOUT
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>
"AAAA"
0
4)
11: (SB-IMPL::%WRITE-STRING
"AAAA"
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>
0
NIL)
12: ((LAMBDA (STREAM &OPTIONAL &REST SB-FORMAT::ARGS))
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>)
13: (FORMAT
#<SB-SYS:FD-STREAM for "file /tmp/global-log" {10001B8A81}>
#<FUNCTION (LAMBDA #) {100002F6C9}>)
14: ((FLET #:WITHOUT-INTERRUPTS-BODY-[RESTART-LISP]30))
15: ((LABELS SB-IMPL::RESTART-LISP))
unhandled condition in --disable-debugger mode, quitting
我已经尝试了一段时间来了解发生了什么,但是嗯。帮助将不胜感激!
安德斯