marijnh / Postmodern

A Common Lisp PostgreSQL programming interface
http://marijnhaverbeke.nl/postmodern
Other
400 stars 90 forks source link

Is it possible to create lisp execution binary using Postmodern? #344

Closed askdkc closed 7 months ago

askdkc commented 7 months ago

Is it possible to create an execution binary when using Postmodern?

I have code something like this:

;; sample.lisp

(ql:quickload :postmodern)
(use-package :postmodern)

(connect-toplevel "sampledb" "postgres" "postgres" "localhost")

;; Define Simple Search
(defun simple-search (keyword)
  (query (:select '* :from 'memos :where (:like 'content (format nil "%~a%" keyword)))))

(defun main ()
  (let ((result
      (simple-search "Milk")))
      (format t "~a~%" result)))

Using this code to create executable file like this:

sbcl --load sample.lisp \
     --eval "(sb-ext:save-lisp-and-die \"sample.exe\" :toplevel #'main :executable t)"

After running the executable:

./sample.exe

I got an error:

CORRUPTION WARNING in SBCL pid 48461 pthread 0x1f4c0bac0:
Memory fault at 0x104b54000 (pc=0x700359e9b4)
The integrity of this image is possibly compromised.
Continuing with fingers crossed.

debugger invoked on a SB-SYS:MEMORY-FAULT-ERROR in thread
#<THREAD "main thread" RUNNING {7008100003}>:
  Unhandled memory fault at #x104B54000.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit from the current thread.

(SB-IMPL::OUTPUT-UNSIGNED-BYTE-FULL-BUFFERED #<SB-SYS:FD-STREAM for "socket 127.0.0.1:64506, peer: 127.0.0.1:5432" {70033C48E3}> 80)
sabracrolleton commented 7 months ago

Do not use connect-toplevel when building an executable. Use with-connection.

 (defun main ()
    (with-connection '("sampledb" "postgres" "postgres" "localhost")
     (let ((result
          (simple-search "Milk")))
        (format t "~a~%" result))))
askdkc commented 7 months ago

@sabracrolleton

Thanks!! It worked!!

I've been wasting my whole day for this🥲