Lisp IO 问题
我是一个 lisp 菜鸟,试图使用 sbcl v1.0.50 学习 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~%"))
==compile.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
我已经尝试了一段时间了解发生了什么,但是嗯。帮助 将不胜感激!
安德斯
I am a lisp noob trying to learn lisp using sbcl v1.0.50.
I am writing a simple logger and running into a memory fault which
I do not understand, but which seems to be related to how I compile my
script. I have boiled it down to the following:
===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~%"))
==compile.lisp==
#! /usr/bin/sbcl --script
(load "main.lisp")
(save-lisp-and-die "program" :toplevel #'main :executable t)
When I compile and run the program it crashes:
> ./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
I have tried for a while to understand what is going on, but hmm. Help
would be appreciated!
Anders
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您打开一个流,然后转储图像。
然后启动转储的图像并尝试写入流。
您不能期望流在程序运行之间保持打开状态,或者在启动图像时以某种方式自动打开。
如果启动图像,请打开流然后写入。
另请参见宏WITH-OPEN-FILE。
您可能还想在 SBCL 邮件列表上讨论这个问题。 SBCL 应该给出更好的错误报告。
一般来说,您需要了解转储图像的工作原理以及限制是什么。通常不能:
等等……
You open a stream and then you dump an image.
Then you start the dumped image and try to write to the stream.
You can't expect that the stream stays open between program runs or gets automatically opened somehow when you start an image.
If you start the image, open the stream and then write to it.
See also the macro WITH-OPEN-FILE.
You may also want to discuss this on the SBCL mailing list. SBCL should give a better error report.
Generally you need to understand how dumping an image works and what the restrictions are. Typically one can't:
and more...