This file is indexed.

/usr/share/common-lisp/source/contextl/cx-layer.lisp is in cl-contextl 1:0.61-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
(in-package :contextl)

(defclass root-specializer () ()
  (:metaclass standard-layer-class)
  (original-name . t))
(ensure-finalized (find-class 'root-specializer))

#-allegro
(declaim (type layer-context *root-context* *active-context*))
#+allegro
(eval-when (:load-toplevel :execute)
  (proclaim '(type layer-context *root-context* *active-context*)))

(defvar *root-context*
  (make-layer-context
   :prototype (class-prototype (find-class 'root-specializer))
   :specializer (find-class 'root-specializer)))

(defvar *active-context* *root-context*)

(declaim (inline current-layer-context))
(defun current-layer-context () *active-context*)

(declaim (inline (setf current-layer-context)))
(defun (setf current-layer-context) (new-layer-context)
  (setf *active-context* new-layer-context))

(defun layer-active-p (layer &optional (context *active-context*))
  (subtypep (layer-context-specializer context)
            (find-layer-class layer)))

(defun active-layers (&optional (context *active-context*))
  (loop with result = '()
        for context-specializer = (layer-context-specializer context)
        then (second (class-direct-superclasses context-specializer))
        until (eq context-specializer (load-time-value (find-class 'root-specializer)))
        do (push (find-layer (first (class-direct-superclasses context-specializer))) result)
        finally (return (nreverse (cons 't result)))))

(define-layered-function adjoin-layer-using-class (layer-class active-context)
  (:method ((layer-class (eql (find-class 't))) active-context)
   (values active-context t))
  (:method ((layer-class standard-layer-class) active-context)
   (let ((active-context-specializer (layer-context-specializer active-context)))
     (values
      (if (subtypep active-context-specializer layer-class)
        active-context
        (let ((new-specializer
               (as-atomic-operation
                 (ensure-finalized
                  (make-instance 'standard-layer-class
                                 :direct-superclasses
                                 (list layer-class active-context-specializer))))))
          (make-layer-context
           :prototype (class-prototype new-specializer)
           :specializer new-specializer)))
      t))))

(defun safe-adjoin-layer (layer active-context)
  (with-lock ((layer-context-lock active-context))
    (or #-cx-threads (getf (layer-context-children/ensure-active active-context) layer)
        #-cx-threads (getf (layer-context-children/ensure-active active-context) (layer-name layer))
        (multiple-value-bind
            (new-layer-context cacheablep)
            (adjoin-layer-using-class (find-layer-class layer) active-context)
          (when cacheablep
            (setf (layer-context-children/ensure-active active-context)
                  (list* (or (layer-name layer) layer) new-layer-context
                         (layer-context-children/ensure-active active-context))))
          new-layer-context))))

(declaim (inline adjoin-layer))

(defun adjoin-layer (layer active-context)
  (declare (optimize (speed 3) (debug 0) (safety 0)
                     (compilation-speed 0)))
  (or (getf (layer-context-children/ensure-active active-context) layer)
      (getf (layer-context-children/ensure-active active-context) (layer-name layer))
      (safe-adjoin-layer layer active-context)))

(defun ensure-active-layer (layer-name)
  (setf *active-context*
        (locally
          (declare (optimize (speed 3) (debug 0) (safety 0)
                             (compilation-speed 0)))
          (adjoin-layer layer-name *active-context*)))
  (values))

(define-layered-function remove-layer-using-class (layer-class active-context)
  (:method ((layer-class (eql (find-class 't))) active-context)
   (declare (ignore active-context))
   (error "The layer T may never be removed."))
  (:method ((layer-class standard-layer-class) active-context)
   (values
    (loop for context-specializer = (layer-context-specializer active-context)
          then (second (class-direct-superclasses context-specializer))
          for active-layers = (list (first (class-direct-superclasses context-specializer)))
          then (cons (first (class-direct-superclasses context-specializer)) active-layers)
          until (eq context-specializer (load-time-value (find-class 'root-specializer)))
          finally
          (return (loop for new-layer-context = *root-context*
                        then (if (subtypep active-layer layer-class)
                               new-layer-context
                               (adjoin-layer active-layer new-layer-context))
                        for active-layer in (cdr active-layers)
                        finally (return new-layer-context))))
    t)))

(defun safe-remove-layer (layer active-context)
  (with-lock ((layer-context-lock active-context))
    (or #-cx-threads (getf (layer-context-children/ensure-inactive active-context) layer)
        #-cx-threads (getf (layer-context-children/ensure-inactive active-context) (layer-name layer))
        (multiple-value-bind
            (new-layer-context cacheablep)
            (remove-layer-using-class (find-layer-class layer) active-context)
          (when cacheablep
            (setf (layer-context-children/ensure-inactive active-context)
                  (list* (or (layer-name layer) layer) new-layer-context
                         (layer-context-children/ensure-inactive active-context))))
          new-layer-context))))

(declaim (inline remove-layer))

(defun remove-layer (layer active-context)
  (declare (optimize (speed 3) (debug 0) (safety 0)
                     (compilation-speed 0)))
  (or (getf (layer-context-children/ensure-inactive active-context) layer)
      (getf (layer-context-children/ensure-inactive active-context) (layer-name layer))
      (safe-remove-layer layer active-context)))

(defun ensure-inactive-layer (layer-name)
  (setf *active-context*
        (locally
          (declare (optimize (speed 3) (debug 0) (safety 0)
                             (compilation-speed 0)))
          (remove-layer layer-name *active-context*)))
  (values))

(defmacro %with-active-layers ((&rest layer-names) &body body)
  `(let ((*active-context*
          (locally
            (declare (optimize (speed 3) (debug 0) (safety 0)
                               (compilation-speed 0)))
            ,(loop for form = '*active-context*
                   then `(adjoin-layer ',layer-name ,form)
                   for layer-name in layer-names
                   finally (return form)))))
     ,@body))

(defmacro with-active-layers ((&rest layer-names) &body body)
  (cond ((null layer-names) `(progn ,@body))
        ((every #'atom layer-names)
         (with-unique-names (proceed)
           `(dynamic-wind :proceed ,proceed
              (%with-active-layers ,layer-names (,proceed ,@body)))))
        (t `(with-active-layers ,(loop for layer-spec in layer-names
                                       if (atom layer-spec)
                                       collect layer-spec
                                       else collect (car layer-spec))
              (with-special-initargs
                  ,(loop for layer-spec in layer-names
                         when (consp layer-spec)
                         collect `((find-layer ',(car layer-spec)) ,@(cdr layer-spec)))
                ,@body)))))

(defmacro with-active-layers* ((&rest layer-names) &body body)
  (cond ((null layer-names) `(progn ,@body))
        ((every #'atom layer-names)
         (with-unique-names (proceed)
           `(dynamic-wind :proceed ,proceed
              (%with-active-layers ,layer-names (,proceed ,@body)))))
        (t `(with-active-layers ,(loop for layer-spec in layer-names
                                       if (atom layer-spec)
                                       collect layer-spec
                                       else collect (car layer-spec))
              (with-special-initargs*
                  ,(loop for layer-spec in layer-names
                         when (consp layer-spec)
                         collect `((find-layer ',(car layer-spec)) ,@(cdr layer-spec)))
                ,@body)))))

(defmacro %with-inactive-layers ((&rest layer-names) &body body)
  `(let ((*active-context*
          (locally
            (declare (optimize (speed 3) (debug 0) (safety 0)
                               (compilation-speed 0)))
            ,(loop for form = '*active-context*
                   then `(remove-layer ',layer-name ,form)
                   for layer-name in layer-names
                   finally (return form)))))
     ,@body))

(defmacro with-inactive-layers ((&rest layer-names) &body body)
  (if layer-names
    (with-unique-names (proceed)
      `(dynamic-wind :proceed ,proceed
         (%with-inactive-layers ,layer-names (,proceed ,@body))))
    `(progn ,@body)))

(defun funcall-with-layer-context (layer-context function &rest args)
  (declare (dynamic-extent args))
  (dynamic-wind
    (let ((*active-context* layer-context))
      (proceed (apply function args)))))

(defun apply-with-layer-context (layer-context function &rest args)
  (declare (dynamic-extent args))
  (dynamic-wind
    (let ((*active-context* layer-context))
      (proceed (apply #'apply function args)))))