Coverage report: /development/source/library/com/dydra/gitlab/dydra-cgi/ffi/lisp/dydra-ndk/package.lisp
| Kind | Covered | All | % |
| expression | 20 | 51 | 39.2 |
| branch | 0 | 2 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
(in-package :common-lisp)
4
(:use :cl :cffi :cffi-sys)
6
(:export ;; package.lisp:
15
:foreign-function-error
31
:quad-cursor-subject-id
32
:quad-cursor-predicate-id
33
:quad-cursor-object-id
46
:record-query-accounting
49
:repository-creation-time
50
:repository-mutation-time
54
:revision-creation-time
59
:statement-predicate-id
69
:term-value-as-boolean
80
:term-value-as-integer
81
:term-value-as-decimal
82
:term-value-as-decoded-time
83
:term-value-as-universal-time
84
:term-value-as-unix-time
87
:term-matrix-construct
95
:term-matrix-data-pointer
96
:term-matrix-row-count
98
:term-matrix-column-count
99
:term-matrix-element-count
103
:term-matrix-clear-row
104
:term-matrix-clear-column
106
:term-matrix-fill-row
107
:term-matrix-fill-column
108
:term-matrix-drop-column
109
:term-matrix-drop-columns
111
:term-matrix-append-row
112
:term-matrix-append-rows
113
:term-matrix-append-column
114
:term-matrix-append-columns
133
(in-package :dydra-ndk)
135
(eval-when (:compile-toplevel :load-toplevel :execute)
136
(pushnew #P"/opt/dydra/lib/" *foreign-library-directories* :test #'equal)
137
(define-foreign-library libdydra
138
(:unix (:or "libdydra.so.0" "libdydra.so"))
139
(:darwin (:or "libdydra.0.dylib" "libdydra.dylib"))
140
(t (:default "libdydra"))))
142
(defcvar ("dydra_error_callback" *error-callback*) :pointer)
144
(defcallback error-callback (:boolean :int8) ((errno :int) (message :string) (function :string))
145
(restart-case (foreign-function-error errno function message)
146
(retry () :report "Retry calling the foreign function." t)
147
(continue () :report "Continue regardless, returning from the foreign function." nil)))
149
(defun load-library (&key path version debug features)
150
"Loads the libdydra native library.
151
Must be called before invoking any foreign functions in the library."
152
(declare (type boolean debug)
154
(ignorable path version debug features))
155
(load-foreign-library 'libdydra)
156
(setf *error-callback* (callback error-callback))
157
(values)) ;;; no meaningful return value
159
(defun unload-library ()
160
"Unloads the libdydra native library."
161
(close-foreign-library 'libdydra)
162
(values)) ;;; no meaningful return value
164
(defmacro with-checked-pointer ((ptr) &rest body)
165
(let* ((ptr-var (gensym))
166
(body (or body (list ptr-var))))
167
`(let ((,ptr-var ,ptr))
168
(declare (type foreign-pointer ,ptr-var))
169
(if (null-pointer-p ,ptr-var)
170
(cl:error "~A is a null pointer." ,ptr-var)
173
(defmacro with-checked-pointers ((&rest ptrs) &rest body)
174
(let ((result `(progn ,@body)))
175
(dolist (ptr (reverse ptrs))
176
(setf result `(with-checked-pointer (,ptr) ,result)))
179
;;; cffi extension as c++ unwind workaround
180
(defparameter *called-ffi-operators* ())
181
(defparameter *last-ffi-operator* ())
183
(defmacro dydra-ndk:defcfun ((foreign-name lisp-name &rest name-options) ffi-return &rest ffi-args)
184
(let ((wrapped-name (intern (concatenate 'string "%." (symbol-name lisp-name)) (symbol-package lisp-name)))
185
(args (mapcar #'first ffi-args)))
186
`(progn (cffi:defcfun (,foreign-name ,wrapped-name ,@name-options) ,ffi-return ,@ffi-args)
187
(declaim (inline ,lisp-name))
188
(defun ,lisp-name ,args
189
(sb-sys:without-interrupts
190
;; track the last called - not thread-safe, but close enough
191
;; 2020-12-22: removed tracking
192
;; (setf (getf *called-ffi-operators* ',lisp-name) (incf *count-ffi-operations*))
193
;; an unblocked thread was still free to modify this
194
;;(setq *last-ffi-operator* (cons ',lisp-name (bt:thread-name (bt:current-thread))))
195
(,wrapped-name ,@args)
198
(defmacro dydra-ndk:defcfunwi (&rest args)
199
`(dydra-ndk:defcfun ,@args))