Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ert-runner
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-L .
18 changes: 15 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
*~
# ffi specifics
ffi-module.o
ffi-module.so
test.o
test.so
test/ffi-test.o
test/ffi-test.so

# Compiled and temporary files
*.elc
*~

# Cask
/.cask
dist

# Ecukes
/features/project/.cask
/features/project/test/*.el
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: generic
sudo: false
before_install:
- curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > x.sh && source ./x.sh
- evm install $EVM_EMACS --use --skip
- cask
env:
- EVM_EMACS=emacs-git-snapshot-travis
script:
- emacs --version
- make test

notifications:
email: false
12 changes: 12 additions & 0 deletions Cask
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(source gnu)
(source melpa)

(package-file "ffi.el")

(development
(depends-on "f")
(depends-on "ecukes")
(depends-on "ert-runner")
(depends-on "el-mock")
(depends-on "cask-package-toolset")
(depends-on "undercover"))
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
EMACS ?= emacs
# Where your dynamic-module-enabled Emacs build lies.
EMACS_BUILDDIR = /home/tromey/Emacs/emacs
# EMACS = /home/tromey/Emacs/emacs/src/emacs
CASK ?= cask

LDFLAGS = -shared
LIBS = -lffi -lltdl
Expand All @@ -10,21 +12,22 @@ CFLAGS += -g3 -Og -finline-small-functions -shared -fPIC -I$(EMACS_BUILDDIR)/src

all: ffi-module.so

test: check

ffi-module.so: ffi-module.o
$(CC) $(LDFLAGS) -o ffi-module.so ffi-module.o $(LIBS)

ffi-module.o: ffi-module.c

check: ffi-module.so test.so
check: ffi-module.so test/ffi-test.so
LD_LIBRARY_PATH=`pwd`:$$LD_LIBRARY_PATH; \
export LD_LIBRARY_PATH; \
$(GDB) $(EMACS_BUILDDIR)/src/emacs -batch -L `pwd` -l ert -l test.el \
-f ert-run-tests-batch-and-exit
$(GDB) $(CASK) exec ert-runner

test.so: test.o
$(CC) $(LDFLAGS) -o test.so test.o
test/ffi-test.so: test/ffi-test.o
$(CC) $(LDFLAGS) -o test/ffi-test.so test/ffi-test.o

test.o: test.c
test/ffi-test.o: test/ffi-test.c

clean:
-rm -f ffi-module.o ffi-module.so test.o test.so
32 changes: 31 additions & 1 deletion ffi.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
;; -*- lexical-binding:t -*-
;;; ffi.el --- FFI(Foreign Function Interface) for Emacs -*- lexical-binding: t; -*-

;; Copyright (C) 2015 Tom Tromey

;; Version: 0.0.1
;; Author: Tom Tromey <tom@tromey.com>
;; Keywords: c, languages, extensions

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This is an FFI for Emacs. It is based on libffi and relies on the
;; dynamic modules work (available on the Emacs 25 branch) in order to
;; be loaded into Emacs. It is relatively full-featured, but for the
;; time being low-level.

;;; Code:

(require 'cl-macs)

Expand Down Expand Up @@ -140,3 +168,5 @@ SLOT-NAME is a symbol and TYPE is an FFI type descriptor."
`(with-ffi-string ,first-binding ,@body))))

(provide 'ffi)

;;; ffi.el ends here
10 changes: 10 additions & 0 deletions test/emacs-ffi-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;;; Test for `emacs-ffi'

;;; Commentary:
;; These are the tests for `emacs-ffi'

;;; Code:

(ert-deftest emacs-ffi-should-not-pass ()
(should-not nil))

File renamed without changes.
8 changes: 6 additions & 2 deletions test.el → test/ffi-test.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
;;; Test for `ffi'

(require 'ffi)
;;; Commentary:
;; These are the tests for `ffi'

;;; Code:

(define-ffi-library test.so "test")

Expand Down Expand Up @@ -40,7 +44,7 @@
(ffi--type-size :int)))
(should (eq (ffi--type-alignment struct-type)
(ffi--type-alignment :int)))))

(ert-deftest ffi-struct-layout-offsets ()
(let* ((types '(:pointer :int))
(struct-type (apply #'ffi--define-struct types)))
Expand Down
46 changes: 46 additions & 0 deletions test/test-helper.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
;;; test-helper --- Test helper for ffi

;;; Commentary:
;; test helper inspired from https://github.com/tonini/overseer.el/blob/master/test/test-helper.el

;;; Code:

(require 'f)

(defvar cpt-path
(f-parent (f-this-file)))

(defvar ffi-test-path
(f-dirname (f-this-file)))

(defvar ffi-root-path
(f-parent ffi-test-path))

(defvar ffi-sandbox-path
(f-expand "sandbox" ffi-test-path))

(when (f-exists? ffi-sandbox-path)
(error "Something is already in %s. Check and destroy it yourself" ffi-sandbox-path))

(defmacro within-sandbox (&rest body)
"Evaluate BODY in an empty sandbox directory."
`(let ((default-directory ffi-sandbox-path))
(when (f-exists? ffi-sandbox-path)
(f-delete default-directory :force))
(f-mkdir ffi-sandbox-path)
,@body
(f-delete default-directory :force)))


(require 'ert)
(require 'el-mock)
(eval-when-compile
(require 'cl))
(require 'undercover)
(undercover "*.el"
(:exclude "*-test.el")
(:report-file "/tmp/undercover-report.json"))
(require 'ffi)

(provide 'test-helper)
;;; test-helper.el ends here