ECL borrows parts of the protocol and documentation from SBCL for
compatibility. Interface is the same except that the home package for
locking is ext
and that ECL doesn’t implement Implementation
Packages and a few constructs. To load the extension you need to
require package-locks
:
(require '#:package-locks)
Package locks protect against unintentional modifications of a package:
they provide similar protection to user packages as is mandated to
common-lisp
package by the ANSI specification. They are not, and
should not be used as, a security measure.
Newly created packages are by default unlocked (see the :lock
option to defpackage
).
The package common-lisp
and ECL internal implementation packages
are locked by default, including ext
.
It may be beneficial to lock common-lisp-user
as well, to
ensure that various libraries don’t pollute it without asking,
but this is not currently done by default.
The following actions cause a package lock violation if the package
operated on is locked, and *package*
is not an implementation
package of that package, and the action would cause a change in the
state of the package (so e.g. exporting already external symbols is
never a violation). Package lock violations caused by these operations
signal errors of type package-error
.
Returns t
when package is locked, nil
otherwise. Signals an error if package doesn’t designate a valid
package.
Locks package and returns t
. Has no effect if package was
already locked. Signals an error if package is not a valid
package designator
Unlocks package and returns t
. Has no effect if
package was already unlocked. Signals an error if package
is not a valid package designator.
Ignores all runtime package lock violations during the execution of body. Body can begin with declarations.
Unlocks packages for the dynamic scope of the body. Signals an error if any of packages is not a valid package designator.
Options are extended to include
:lock boolean
If the argument to :lock
is t
, the package is initially
locked. If :lock
is not provided it defaults to nil
.
Example:
(defpackage "FOO" (:export "BAR") (:lock t)) ;;; is equivalent to (defpackage "FOO") (:export "BAR")) (lock-package "FOO")