Skip to content

Instantly share code, notes, and snippets.

@tmccombs
Forked from jfhbrook/libffi-unix.lisp
Last active September 13, 2022 05:07
Show Gist options
  • Save tmccombs/f6130972bc28c8ae6dc5 to your computer and use it in GitHub Desktop.
Save tmccombs/f6130972bc28c8ae6dc5 to your computer and use it in GitHub Desktop.
;;;;Modify ~/quicklisp/dists/quicklisp/software/fsbv-20101006-git to look like
;;;;this:
;; CFFI-Grovel definitions for unix systems.
;; Liam Healy 2009-02-22 09:24:33EST libffi-unix.lisp
;; Time-stamp: <2009-08-23 09:51:01EDT libffi-unix.lisp>
;; $Id: $
(in-package :fsbv)
#+linux
(define "_GNU_SOURCE")
;; When installed through Mac Ports, FSBV include files
;; will be found in /opt/local/include.
#+darwin
(cc-flags "-I/opt/local/include/")
#-darwin
;; HERE IT IS
;; Temporary fix until a newer version fixes this
;; The fix is on master as of commit 5b4093
;; This will dyamically get the right header file, assumming sbcl, and pkg-config are installed.
#+(and linux sbcl)
(cc-flags #.(string-trim (string #\NEWLINE)
(with-output-to-string (s)
(sb-ext:run-program "/usr/bin/pkg-config"
'("--cflags" "libffi") :output s))))
#+darwin
(include "ffi/ffi.h")
#-darwin
(include "ffi.h")
(cenum status
((:OK "FFI_OK"))
((:bad-typedef "FFI_BAD_TYPEDEF"))
((:bad-abi "FFI_BAD_ABI")))
(cenum abi
((:default-abi "FFI_DEFAULT_ABI"))
((:sysv "FFI_SYSV"))
((:unix64 "FFI_UNIX64")))
(ctype ffi-abi "ffi_abi")
(ctype sizet "size_t")
(ctype ushort "unsigned short")
(ctype unsigned "unsigned")
(cstruct ffi-type "struct _ffi_type"
(size "size" :type sizet)
(alignment "alignment" :type ushort)
(type "type" :type ushort)
(elements "elements" :type :pointer))
#|
;;; Will not compile
;;; error: invalid application of ‘sizeof’ to incomplete type ‘struct ffi_cif’
;;; When structs are defined with the name at the end, apparently they
;;; are intended to be "opaque types".
(cstruct ffi-cif "struct ffi_cif"
(abi "abi" :type ffi-abi)
(nargs "nargs" :type unsigned)
(arg-types "arg_types" :type :pointer)
(return-type "rtype" :type :pointer)
(bytes "bytes" :type :unsigned)
(flags "flags" :type :unsigned))
|#
(constant (+type-void+ "FFI_TYPE_VOID"))
(constant (+type-int+ "FFI_TYPE_INT"))
(constant (+type-float+ "FFI_TYPE_FLOAT"))
(constant (+type-double+ "FFI_TYPE_DOUBLE"))
(constant (+type-longdouble+ "FFI_TYPE_LONGDOUBLE"))
(constant (+type-uint8+ "FFI_TYPE_UINT8"))
(constant (+type-sint8+ "FFI_TYPE_SINT8"))
(constant (+type-uint16+ "FFI_TYPE_UINT16"))
(constant (+type-sint16+ "FFI_TYPE_SINT16"))
(constant (+type-uint32+ "FFI_TYPE_UINT32"))
(constant (+type-sint32+ "FFI_TYPE_SINT32"))
(constant (+type-uint64+ "FFI_TYPE_UINT64"))
(constant (+type-sint64+ "FFI_TYPE_SINT64"))
(constant (+type-struct+ "FFI_TYPE_STRUCT"))
(constant (+type-pointer+ "FFI_TYPE_POINTER"))
* (ql:quickload "gsll")
; loading system definition from
; /home/josh/quicklisp/dists/quicklisp/software/cffi_0.10.6/cffi-grovel.asd
; into #<PACKAGE "ASDF2">
; registering #<SYSTEM CFFI-GROVEL> as CFFI-GROVEL
; loading system definition from
; /home/josh/quicklisp/dists/quicklisp/software/alexandria-20101107-git/alexandria.asd
; into #<PACKAGE "ASDF2">
; registering #<SYSTEM :ALEXANDRIA> as ALEXANDRIA
; loading system definition from
; /home/josh/quicklisp/dists/quicklisp/software/cffi_0.10.6/cffi.asd into
; #<PACKAGE "ASDF2">
; registering #<SYSTEM :CFFI> as CFFI
; loading system definition from
; /home/josh/quicklisp/dists/quicklisp/software/babel-20101107-darcs/babel.asd
; into #<PACKAGE "ASDF2">
; registering #<SYSTEM BABEL> as BABEL
; loading system definition from
; /home/josh/quicklisp/dists/quicklisp/software/trivial-features-20101006-darcs/trivial-features.asd
; into #<PACKAGE "ASDF2">
; registering #<SYSTEM TRIVIAL-FEATURES> as TRIVIAL-FEATURES
To load "gsll":
Load 1 ASDF system:
gsll
; Loading "gsll"
...........; cc -m32 -I/home/josh/quicklisp/dists/quicklisp/software/cffi_0.10.6/ -fPIC -o /home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix /home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c
debugger invoked on a SIMPLE-ERROR in thread #<THREAD "initial thread" RUNNING {AB718E9}>: External process exited with code 1.
Command was: "cc" "-m32" "-I/home/josh/quicklisp/dists/quicklisp/software/cffi_0.10.6/" "-fPIC" "-o" "/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix" "/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c"
Output was:
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:7:17: error: ffi.h: No such file or directory
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c: In function ‘main’:
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:24: error: ‘FFI_OK’ undeclared (first use in this function)
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:24: error: (Each undeclared identifier is reported only once
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:24: error: for each function it appears in.)
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:29: error: ‘FFI_BAD_TYPEDEF’ undeclared (first use in this function)
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:34: error: ‘FFI_BAD_ABI’ undeclared (first use in this function)
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:45: error: ‘FFI_DEFAULT_ABI’ undeclared (first use in this function)
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:50: error: ‘FFI_SYSV’ undeclared (first use in this function)
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:55: error: ‘FFI_UNIX64’ undeclared (first use in this function)
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:63: error: ‘ffi_abi’ undeclared (first use in this function)
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:110: error: invalid application of ‘sizeof’ to incomplete type ‘struct _ffi_type’
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:115: error: dereferencing pointer to incomplete type
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:120: error: dereferencing pointer to incomplete type
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:125: error: dereferencing pointer to incomplete type
/home/josh/.cache/common-lisp/sbcl-1.0.38-2.fc12-linux-x86/home/josh/quicklisp/dists/quicklisp/software/fsbv-20101006-git/libffi-unix.c:130: error: dereferencing pointer to incomplete type
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [TRY-RECOMPILING] Try recompiling libffi
1: [RETRY ] Retry compiling component ("fsbv" "libffi").
2: [ACCEPT ] Continue, treating compiling component ("fsbv" "libffi") as having been successful.
3: [ABORT ] Give up on "gsll"
4: Exit debugger, returning to top level.
(CFFI-GROVEL::INVOKE "cc")[:EXTERNAL]
0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment