Coverage report: /development/source/library/com/dydra/gitlab/dydra-cgi/ffi/lisp/rdfcache/library.lisp

KindCoveredAll%
expression3085 35.3
branch210 20.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 (in-package :rdfcache)
2
 
3
 ;; Variables
4
 
5
 (defvar *encoding* :utf-8
6
   "Triple term encoding.")
7
 
8
 (defvar *wildcard-term-pointer* (null-pointer)
9
   "A wildcard term.")
10
 
11
 (defvar *wildcard-term-number* 0
12
   "The term number designating a wildcard term.")
13
 
14
 #+(or)
15
 (progn
16
   (defvar *default-context-pointer* t
17
     "The default context.")
18
   (defvar *default-context-id* nil
19
     "The default context identifier.")
20
 )
21
 
22
 #+(or)
23
 (progn
24
   (setf *default-context-pointer* %default-context-pointer)
25
   (setf *default-context-id* %default-context-id)
26
 )
27
 
28
 (defvar *all-context-number* 0
29
   "The term number designating the context which comprises all graphs,
30
  default and named.")
31
 
32
 (defvar *default-context-number* -1
33
   "The term number designating the default context.")
34
 
35
 (defvar *named-context-number* -2
36
   "The term number designating the context which comprises all named graphs.")
37
 
38
 (defvar *default-timeout* -1 ;; milliseconds, or -1 for blocking
39
   "The default operation timeout.")
40
 
41
 (defun pointer (ptr)
42
   (if (pointerp ptr)
43
       (with-checked-pointer (ptr) ptr)
44
       (cl:error "~A is not a pointer." ptr)))
45
 
46
 ;; Initialization
47
 
48
 (defun getenv (variable-name &optional default-value)
49
   (or #+sbcl (sb-unix::posix-getenv variable-name)
50
       #+lispworks (lispworks:environment-variable variable-name)
51
       #+ecl (si:getenv variable-name)
52
       default-value))
53
 
54
 (defun getenvp (variable-name &optional (default-value ""))
55
   (not (zerop (length (getenv variable-name default-value)))))
56
 
57
 (defun load-library (&key path version debug features)
58
   "Loads the libspocq native library. Must be called before invoking any
59
    foreign functions in the library."
60
   (declare (type boolean debug)
61
            (type list features))
62
   ;; Load the SPOCQ FFI shared library:
63
   (spocq-ffi:load-library :path path)
64
   ;; Load the Dydra NDK shared library:
65
   (dydra-ndk:load-library :path path)
66
   ;; Ensure all structure sizes match in the libspocq ABI:
67
   (dolist (type '(term triple quad transaction cursor))
68
     (let ((ffi-size (foreign-type-size (list :struct type)))
69
           (lib-size (%%sizeof (intern (string type) :keyword))))
70
       (unless (eql ffi-size lib-size)
71
         (incompatible-abi-structure type ffi-size lib-size))))
72
   ;; Optionally, ensure that the libspocq version string matches:
73
   ;(when version
74
   ;  (let ((ffi-version (string version))
75
   ;        (lib-version (version)))
76
   ;    (when (not (equal lib-version ffi-version))
77
   ;      (mismatched-version ffi-version lib-version))))
78
   ;; Optionally, ensure that the libspocq feature set matches:
79
   (when features
80
     (dolist (feature features)
81
       (unless (%%has-feature (if (keywordp feature)
82
                                  (keyword->string feature)
83
                                  (string feature)))
84
         (missing-feature feature))))
85
   (values)) ;; no meaningful return value
86
 
87
 (defun unload-library ()
88
   "Unloads the libspocq native library."
89
   ;; Unload the Dydra NDK shared library:
90
   (dydra-ndk:unload-library)
91
   ;; Unload the SPOCQ FFI shared library:
92
   (spocq-ffi:unload-library)
93
   (values)) ;; no meaningful return value
94
 
95
 ;; Miscellaneous
96
 
97
 (defun features ()
98
   "Returns the list of available RDFcache features."
99
   (let* ((features (list))
100
          (*current-callback* (lambda (s) (push (string->keyword s) features) t)))
101
     (declare (special *current-callback*))
102
     (%%each-feature (callback string-callback))
103
     (reverse features)))
104
 
105
 (defun modules ()
106
   "Returns the list of available RDFcache modules. See RDFCACHE:TRACE-MODULE."
107
   (let* ((modules (list))
108
          (*current-callback* (lambda (s) (push (string->keyword s) modules) t)))
109
     (declare (special *current-callback*))
110
     (%%each-module (callback string-callback))
111
     (reverse modules)))