Skip to content

Instantly share code, notes, and snippets.

@rpav

rpav/crash.lisp Secret

Created September 25, 2012 17:28
Show Gist options
  • Save rpav/fa8f380a218b55b4ae6a to your computer and use it in GitHub Desktop.
Save rpav/fa8f380a218b55b4ae6a to your computer and use it in GitHub Desktop.
SBCL-1.0.58 / CFFI crash
(eval-when (:compile-toplevel :load-toplevel :execute)
(asdf:load-system :cffi))
(defpackage :test-crash
(:use :cl :cffi))
(in-package :test-crash)
(eval-when (:compile-toplevel :load-toplevel :execute)
;; Change to appropriate path, of course:
(load-foreign-library "/home/rpav/test.so")
(defcfun call_callback :int
(fn :pointer)))
(defcenum status_t
(:success 0))
(declaim (inline make-point))
(defstruct point x y)
(defcallback my-callback status_t ()
(let* ((p (make-point :x 0.0 :y 0.0)))
(declare (dynamic-extent p))
(format t "~&~0,0T~A = ~S~%" "P" P))
:success)
(call_callback (cffi:callback my-callback))
/* This can be built simply:
$ gcc -shared -fPIC -o test.so test.c
*/
typedef int (*fn)(void);
int call_callback(fn ptr) {
return (*ptr)();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment