Skip to content

Commit 4aebc79

Browse files
authored
Merge pull request #13 from zevlg/misc-ffi-el-fixes
Fixes some problems I've found using ffi.el
2 parents c893cdd + db05bb4 commit 4aebc79

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

ffi.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ SLOT-NAME is a symbol and TYPE is an FFI type descriptor."
9898
(defmacro define-ffi-array (name type length &optional docstring)
9999
;; This is a hack until libffi gives us direct support.
100100
(let ((type-description
101-
(apply #'ffi--define-struct (make-list (eval length)
102-
(symbol-name type)))))
101+
(apply #'ffi--define-struct
102+
(make-list (eval length) (symbol-value type)))))
103103
`(defvar ,name ,type-description ,docstring)))
104104

105105
(defsubst ffi-aref (array type index)
@@ -109,7 +109,7 @@ SLOT-NAME is a symbol and TYPE is an FFI type descriptor."
109109
(declare (indent defun))
110110
`(let ((,(car binding) (ffi-allocate ,@(cdr binding))))
111111
(unwind-protect
112-
,@body
112+
(progn ,@body)
113113
(ffi-free ,(car binding)))))
114114

115115
(defmacro with-ffi-temporaries (bindings &rest body)
@@ -126,7 +126,7 @@ SLOT-NAME is a symbol and TYPE is an FFI type descriptor."
126126
(declare (indent defun))
127127
`(let ((,(car binding) (ffi-make-c-string ,@(cdr binding))))
128128
(unwind-protect
129-
,@body
129+
(progn ,@body)
130130
(ffi-free ,(car binding)))))
131131

132132
(defmacro with-ffi-strings (bindings &rest body)

test.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,16 @@
9797
(should (eq (test-not t) nil))
9898
(should (eq (test-not 0) nil))
9999
(should (eq (test-not "hi") nil)))
100+
101+
(defconst test-user-defined-char :char)
102+
103+
(ert-deftest ffi-array ()
104+
(should (eq (define-ffi-array arr1 :char 1024) 'arr1))
105+
(should (eq (define-ffi-array arr2 test-user-defined-char 1024) 'arr2)))
106+
107+
(ert-deftest ffi-with-ffi-multi-stat ()
108+
(should (eq (with-ffi-temporary (a :int) 1 2 3) 3))
109+
(should (eq (with-ffi-temporaries ((a :int) (b :int)) 1 2 3) 3))
110+
(should (eq (with-ffi-string (a "test") 1 2 3) 3))
111+
(should (eq (with-ffi-strings ((a "s1") (b "s2")) 1 2 3) 3)))
112+

0 commit comments

Comments
 (0)