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
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:
dump the state of open streams
keep network connections open
keep windows open
and more...
Related
I saw this question Emacs error "Failed to initialize color list unarchiver" when I call it in the terminal but it didn't help. I get the similar error but for m1 chip instead of intel x86 I think:
2022-04-14 17:08:00.370 Emacs-arm64-12[24779:1101019] Failed to initialize color list unarchiver: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: non-keyed archive cannot be decoded by NSKeyedUnarchiver}
I added the command I was told to my .emacs but it didn't help:
(meta_learning) brandomiranda~/coq4brando/cs598 ❯ cat ~/.emacs
;; Open .v files with Proof General's Coq mode
(load "~/.emacs.d/lisp/PG/generic/proof-site")
(add-to-list 'load-path "~/evil")
(require 'evil)
(evil-mode 1)
(load-file (let ((coding-system-for-read 'utf-8))
(shell-command-to-string "agda-mode locate")))
(delete-file "~/Library/Colors/Emacs.clr")
why is this error happening and how do I remove it?
There is an unexplained behavior for me for the moment, appreciate any clues.
Background
I have a locally running instance of wordpress via PHP built-in development webserver php -S localhost:8000 -t /doc/root/wordpress. The site works, I can fetch it with curl "http://localhost:8000/" successfully, I can open it in a web browser also.
But simple programs like:
(drakma:http-request "http://localhost:8000/")
or
(dexador:get "http://localhost:8000/")
-- both fail.
drakma fails with the backtrace:
Condition USOCKET:CONNECTION-REFUSED-ERROR was signalled.
[Condition of type USOCKET:CONNECTION-REFUSED-ERROR]
Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1004CC9B93}>)
Backtrace:
0: (USOCKET::HANDLE-CONDITION #<SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR {100435B3A3}> #<USOCKET:STREAM-USOCKET {100435AE33}>)
1: (SB-KERNEL::%SIGNAL #<SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR {100435B3A3}>)
2: (ERROR SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR :ERRNO 61 :SYSCALL "connect")
3: (SB-BSD-SOCKETS:SOCKET-ERROR "connect" 61)
4: (SB-BSD-SOCKETS::CALL-WITH-SOCKET-ADDR #<SB-BSD-SOCKETS:INET-SOCKET 127.0.0.1:49431, fd: 16 {100435AD23}> (#(127 0 0 1) 8000) #<CLOSURE (FLET SB-BSD-SOCKETS::WITH-SOCKET-ADDR-THUNK :IN SB-BSD-SOCKETS:..
5: ((:METHOD SB-BSD-SOCKETS:SOCKET-CONNECT (SB-BSD-SOCKETS:SOCKET)) #<SB-BSD-SOCKETS:INET-SOCKET 127.0.0.1:49431, fd: 16 {100435AD23}> #(127 0 0 1) 8000) [fast-method]
6: ((FLET "WITHOUT-INTERRUPTS-BODY-22" :IN USOCKET:SOCKET-CONNECT))
7: (USOCKET:SOCKET-CONNECT "localhost" 8000 :PROTOCOL :STREAM :ELEMENT-TYPE FLEXI-STREAMS:OCTET :TIMEOUT 20 :DEADLINE NIL :NODELAY :IF-SUPPORTED :LOCAL-HOST NIL :LOCAL-PORT NIL)
8: (DRAKMA:HTTP-REQUEST #<PURI:URI http://localhost:8000/>)
9: (SB-INT:SIMPLE-EVAL-IN-LEXENV (DRAKMA:HTTP-REQUEST "http://localhost:8000/") #<NULL-LEXENV>)
10: (EVAL (DRAKMA:HTTP-REQUEST "http://localhost:8000/"))
11: (SWANK::EVAL-REGION "(drakma:http-request \"http://localhost:8000/\") ..)
12: ((LAMBDA NIL :IN SWANK-REPL::REPL-EVAL))
13: (SWANK-REPL::TRACK-PACKAGE #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100435A53B}>)
14: (SWANK::CALL-WITH-RETRY-RESTART "Retry SLIME REPL evaluation request." #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100435A4DB}>)
15: (SWANK::CALL-WITH-BUFFER-SYNTAX NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100435A4BB}>)
16: (SWANK-REPL::REPL-EVAL "(drakma:http-request \"http://localhost:8000/\") ..)
17: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK-REPL:LISTENER-EVAL "(drakma:http-request \"http://localhost:8000/\") ..)
18: (EVAL (SWANK-REPL:LISTENER-EVAL "(drakma:http-request \"http://localhost:8000/\") ..)
19: (SWANK:EVAL-FOR-EMACS (SWANK-REPL:LISTENER-EVAL "(drakma:http-request \"http://localhost:8000/\") ..)
20: (SWANK::PROCESS-REQUESTS NIL)
21: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
22: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
23: (SWANK/SBCL::CALL-WITH-BREAK-HOOK #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1004CD008B}>)
24: ((FLET SWANK/BACKEND:CALL-WITH-DEBUGGER-HOOK :IN "/Users/ihar/.roswell/lisp/slime/2019.02.02/swank/sbcl.lisp") #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {..
25: (SWANK::CALL-WITH-BINDINGS ((*STANDARD-INPUT* . #<SWANK/GRAY::SLIME-INPUT-STREAM {1004BC9E93}>)) #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1004CD00AB}>)
26: (SWANK::HANDLE-REQUESTS #<SWANK::MULTITHREADED-CONNECTION {10079AA873}> NIL)
27: ((FLET SB-UNIX::BODY :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
28: ((FLET "WITHOUT-INTERRUPTS-BODY-4" :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
29: ((FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
30: ((FLET "WITHOUT-INTERRUPTS-BODY-1" :IN SB-THREAD::CALL-WITH-MUTEX))
31: (SB-THREAD::CALL-WITH-MUTEX #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE) {3A67D6B}> #<SB-THREAD:MUTEX "thread result lock" owner: #<SB-THREAD:THREAD "..
32: (SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE #<SB-THREAD:THREAD "repl-thread" RUNNING {1004CC9B93}> NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::SPAWN-REPL-THREAD) {1004CC9B3B}> NIL)
33: ("foreign function: call_into_lisp")
34: ("foreign function: new_thread_trampoline")
35: ("foreign function: _pthread_body")
36: ("foreign function: _pthread_body")
37: ("foreign function: thread_start")
Interesting, if I change the URI to any other on the internet:
(drakma:http-request "https://stackoverflow.com")
-- then it works fine.
So the problem, probably, somewhere in the context of my local machine and local php-server. What could be wrong with these simple function calls?
My notes
in the backtrace I see this line (USOCKET:SOCKET-CONNECT "localhost" 8000 :PROTOCOL :STREAM :ELEMENT-TYPE FLEXI-STREAMS:OCTET :TIMEOUT 20 :DEADLINE NIL :NODELAY :IF-SUPPORTED :LOCAL-HOST NIL :LOCAL-PORT NIL). The keys :local-host and :local-port are both nil. Probably that's the issue, because according to the usocket specs those params are responsible for calling bind() on local address (is it somehow different than calling non-local address?).
I also haven't found in the specs for drakma:http-request any special parameters to specify that I'm requesting a local server. According to the example, https://edicl.github.io/drakma/#ex-basic-auth, requesting any URI is simple and goes without any differentiation of 'local address' vs non-local.
Summing up
Why requesting "http://localhost:8000" doesn't work with drakma or dexador. Does anybody can confirm the same behavior for local web servers?
Is the bind() syscall somehow different for local and non-local addresses?
P.S. I already asked the similar question and first it seemed like the problem was with old software versions. Now I found additional details of the problem and rephrased it, so I'm making another question here.
Update 1
Maybe, the problem is connected to the particular PHP built-it webserver for development, because the issue is reproducible only with the PHP webserver + SBCL + Drakma. But PHP webserver serves fine for curl, a Go client, a web browser.
PHP version:
PHP 7.3.1 (cli) (built: Jan 10 2019 13:16:34) ( NTS ) Copyright (c)
1997-2018 The PHP Group Zend Engine v3.3.1, Copyright (c) 1998-2018
Zend Technologies
with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies
-- installed with brew install php.
Steps to reproduce
The server:
php -S localhost:7070
Then try with clients:
curl "http://localhost:7070"
-- works fine (status code 404 is expected and received).
Lisp:
(drakma:http-request "http://localhost:7070")
-- fails (status code 404 is expected but connection refused is returned).
Who wants details, there is a discussion where Stas Boukarev helped to debug the problem.
Running php -S localhost:7070 starts a server listening on ipv6 address on my computer, so requesting the ipv4 address 127.0.0.1:7070 doesn't work in that case.
So the server must be started with explicit ipv4 address php -S 127.0.0.1:7070 instead to work correctly.
I am using Emacs 25.3 under windows 10 platform.
It works fine until one time I started it and got the following message:
Warning (initialization): An error occurred while loading ‘
c:/Users/shore/AppData/Roaming/.emacs’:
Wrong type argument: listp, <html>
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.
As instructed I used --debug-init option to start and got the following message:
Debugger entered--Lisp error: (wrong-type-argument listp <html>)
package--read-archive-file("archives/gnu/archive-contents")
package-read-archive-contents("gnu")
package-read-all-archive-contents()
package-initialize()
eval-buffer(#<buffer *load*> nil "c:/Users/shore/AppData/Roaming/.emacs" nil t) ; Reading at buffer position 275
load-with-code-conversion("c:/Users/shore/AppData/Roaming/.emacs" "c:/Users/shore/AppData/Roaming/.emacs" t t)
load("~/.emacs" t t)
[init-file-user system-type delayed-warnings-list user-init-file inhibit-default-init inhibit-startup-screen ms-dos "~" "/_emacs" windows-nt "/.emacs" directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" initialization format-message "`_emacs' init file is deprecated, please use `.emacs'" "~/_emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default"] 7]()
command-line()
normal-top-level()
Can anyone tell me where my problem is and how to fix it?
It's telling you that when it tried to read file archives/gnu/archive-contents it expected to read Lisp (more specifically a Lisp list). Instead, it encountered <html> (presumably text in the file).
A guess is that you somehow downloaded or picked up an HTML file (perhaps one that describes the archive file or that has links to download it) instead of downloading or picking up a file of Lisp code. Try once again to obtain that archive file.
I use emacs24 in archlinux.If i use the slime packages from marmalade.org,then when i use M-x slime the error is:
debugger invoked on a SB-INT:SIMPLE-FILE-ERROR in thread
#<THREAD "initial thread" RUNNING {AB007A9}>:
Couldn't load
"/home/sinners/.emacs.d/elpa/slime-20100404.1/swank-loader.lisp": file does
not exist.
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
but if i use the slime-cvs packages from the offical site,the error is:
Debugger entered: (("Error in timer" slime-attempt-connection (#<process inferior-lisp> nil 2) (void-variable --cl-accu--)))
#[257 "\302\303\304\300\301F\"\207" [slime-attempt-connection (#<process inferior-lisp> nil 2) debug nil "Error in timer"] 7 "\n\n(fn DATA)"]((void-variable --cl-accu--))
funcall(#[257 "\302\303\304\300\301F\"\207" [slime-attempt-connection (#<process inferior-lisp> nil 2) debug nil "Error in timer"] 7 "\n\n(fn DATA)"] (void-variable --cl-accu--))
slime-timer-call(slime-attempt-connection #<process inferior-lisp> nil 2)
apply(slime-timer-call (slime-attempt-connection #<process inferior-lisp> nil 2))
byte-code("r\301\302H\303H\"\210)\301\207" [timer apply 5 6] 4)
timer-event-handler([t 20271 59188 161536 0.3 slime-timer-call (slime-attempt-connection #<process inferior-lisp> nil 2) nil])
anyone can help me?
Problem with --cl-accu-- variable signs about breakage of emacs cl package in presence of lexical scoping. Try to go to slime.el in your slime distribution, find string
;; lexical-binding: t in the ;; Local Variables: section at the end of the file and change it to ;; lexical-binding: nil. And remove old slime.elc file if you have one.
I had the exact same problem, which was solved by deleting the slime.elc file, that I had compiled earlier using byte-recompile-directory. I didn't try compiling it again.
I'm not sure, but this problem can be due to different versions of SLIME and SWANK. However you should just use pacman to install a lisp implementation (I think that SBCL is the most popular implementation on Linux) and then use quicklisp to install everything else.
See this blog post to see how to install SWANK and SLIME with quicklisp.
I'm having trouble getting SBCL to start under slime. I've messed things up and I don't know how to recover. This was working fine until I...
Had a problem loading a package via asdf. At which point I started debugging the asdf.lisp provided with SBCL to see what was going wrong. The sole change I made was to put a (break) in which I removed once I'd figured out what was wrong. All was fine until the next time I tried to start SBCL.
Then I got a swank compilation error saying that the asdf.fasl was older than the asdf.lisp file. That made sense to me so I recompiled the asdf.fasl. The output I'm now getting is:
(progn (load "c:\\emacs-23.1\\site-lisp\\slime\\swank-loader.lisp" :verbose t) (funcall (read-from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "c:\\Users\\GILESR~1\\AppData\\Local\\Temp\\slime.3068" :coding-system "iso-latin-1-unix"))
This is SBCL 1.0.37, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
This is experimental prerelease support for the Windows platform: use
at your own risk. "Your Kitten of Death awaits!"
*
; loading #P"c:\\emacs-23.1\\site-lisp\\slime\\swank-loader.lisp"
; loading #P"c:\\hacking\\emacs\\.slime\\fasl\\2010-07-30\\sbcl-1.0.37-win32-x86\\swank-backend.fasl"
; loading #P"c:\\hacking\\emacs\\.slime\\fasl\\2010-07-30\\sbcl-1.0.37-win32-x86\\swank-source-path-parser.fasl"
; loading #P"c:\\hacking\\emacs\\.slime\\fasl\\2010-07-30\\sbcl-1.0.37-win32-x86\\swank-source-file-cache.fasl"
; compiling file "c:\\emacs-23.1\\site-lisp\\slime\\swank-sbcl.lisp" (written 22 JUL 2010 08:15:02 AM):
; file: c:\emacs-23.1\site-lisp\slime\swank-sbcl.lisp
; in: EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
; (REQUIRE 'SWANK-BACKEND::SB-BSD-SOCKETS)
;
; caught ERROR:
; (during compile-time-too processing)
; The function ASDF::MODULE-PROVIDE-ASDF is undefined.
; (REQUIRE 'SWANK-BACKEND::SB-INTROSPECT)
;
; caught ERROR:
; (during compile-time-too processing)
; The function ASDF::MODULE-PROVIDE-ASDF is undefined.
; (REQUIRE 'SWANK-BACKEND::SB-POSIX)
;
; caught ERROR:
; (during compile-time-too processing)
; The function ASDF::MODULE-PROVIDE-ASDF is undefined.
; (REQUIRE 'SWANK-BACKEND::SB-CLTL2)
;
; caught ERROR:
; (during compile-time-too processing)
; The function ASDF::MODULE-PROVIDE-ASDF is undefined.
;
; compilation unit aborted
; caught 1 fatal ERROR condition
; caught 4 ERROR conditions
;
; compilation aborted because of fatal error:
; SB-INT:SIMPLE-READER-PACKAGE-ERROR at 1839 (line 62, column 18) on #<SB-SYS:FD-STREAM
; for "file c:\\emacs-23.1\\site-lisp\\slime\\swank-sbcl.lisp"
; {24564B89}>:
; package "SB-POSIX" not found
; ; compilation aborted after 0:00:00.045
;;
;; Error while compiling c:\emacs-23.1\site-lisp\slime\swank-sbcl.lisp:
;; COMPILE-FILE returned NIL.
;; Aborting.
So it's not finding some stuff it needs in my recompiled asdf. In order to resolve this I've done a complete uninstall and reinstall of SBCL. No joy. I've got nothing in my .sbclrc either.
Update: On viewing the asdf.lisp source code the missing functions are definitely in the file. The thing that's preventing them from compiling is I think the line:
#+(and sbcl sbcl-hooks-require)
My knowledge of lisp is currently not sufficient to compile the asdf file in the environment to trigger the above conditional compilation statement.
I've sorted the problem using the following steps:
Fire up sbcl from Windows start menu.
Run the following code to add the sbcl-hooks-require symbol to the feature list:
(push :sbcl-hooks-require features)
Recompile asdf.lisp. In order to do this I needed to recompile asdf outside of the installed C:\Program files\Steel... directory as the UAC on Windows Vista will stop the fasl being written. For example:
(compile-file "C:\foobar\asdf.lisp")
Copy the generated fasl back to C:\Program files\Steel... to overwrite the original fasl.
Update: The formatting on stackoverflow has knocked out some of the code bits. The code should be as follows:
(push :sbcl-hooks-require *features*)
(compile-file "C:\\foobar\\asdf.lisp")