31.2. Saving an Image

31.2.1. Image Portability

The function (EXT:SAVEINITMEM &OPTIONAL (filename "lispinit.mem") &KEY :KEEP-GLOBAL-HANDLERS :QUIET :INIT-FUNCTION :LOCKED-PACKAGES :START-PACKAGE :EXECUTABLE :NORC :SCRIPT :DOCUMENTATION :VERBOSE) saves the running CLISP's memory to the file filename; extension #P".mem" is recommended (when filename does not have an extension, #P".mem" extension is automatically added unless the file being created is an executable).

:QUIET

If this argument is not NIL, the startup banner and the good-bye message will be suppressed, as if by -q.

This is not recommended for interactive application delivery, please append your banner to ours (using init function) instead of replacing it.

:VERBOSE
Print a message after writing the file. This argument defaults to CUSTOM:*SAVEINITMEM-VERBOSE*; initial value is T.
:NORC
If this argument is not NIL, the RC file loading will be suppressed, as if by -norc.
:INIT-FUNCTION

This argument specifies a function that will be executed at startup of the saved image, before entering the standard read-eval-print loop (but after all other initialization, see Section 31.1.1, “Cradle to Grave”); thus, if you want to avoid the read-eval-print loop, you have to call EXT:EXIT at the end of the init function yourself (this does not prevent CUSTOM:*FINI-HOOKS* from being run).

See the manual for passing command line arguments to this function.

See also CUSTOM:*INIT-HOOKS* and CUSTOM:*FINI-HOOKS*.

:SCRIPT

This options determines the handling of positional arguments when the image is invoked.

This option defaults to T when init function is NIL and to NIL when init function is non-NIL.

:DOCUMENTATION

The description of what this image does, printed by the -help-image olption.

Defaults to (DOCUMENTATION init function 'FUNCTION)

:LOCKED-PACKAGES
This argument specifies the packages to lock before saving the image; this is convenient for application delivery, when you do not want your users to mess up your product. This argument defaults to CUSTOM:*SYSTEM-PACKAGE-LIST*.
:START-PACKAGE
This argument specifies the starting value of *PACKAGE* in the image being saved, and defaults to the current value of *PACKAGE*.
:KEEP-GLOBAL-HANDLERS

When non-NIL, the currently established global handlers (either with EXT:SET-GLOBAL-HANDLER or with -on-error) are inherited by the image. Defaults to NIL, so that

$ clisp -i myfile -x '(EXT:SAVEINITMEM)'

will produce an image without any global handlers inherited from the batch mode of the above command.

:EXECUTABLE

When non-NIL, the saved file will be a standalone executable. In this case, the #P".mem" extension is not added. On Win32 and Cygwin the extension #P".exe" is added instead.

Additionally, if this argument is 0, the standard CLISP command line options will not be processed by the executable but will be placed into EXT:*ARGS* instead. This is convenient for application delivery, so that your CLISP-based application can accept, e.g., -x. To override this feature of the image, you have to prefix the options with "--clisp", e.g., use --clisp-x instead of -x. This, given such a CLISP-based application, you can get to an ordinary CLISP read-eval-print loop by doing

$ application --clisp-x '(EXT:SAVEINITMEM "myclisp" :executable t :init-function nil)'
$ ./myclisp
[1]> (! 20)
2432902008176640000

These instructions are also printed by --clisp--help.

Of course, this feature opens a security hole if the application is running setuid root, therefore CLISP resets the effective group and user IDs to the real ones if it sees a "--clisp-*" option.

You can use this memory image with the -M option. On UNIX systems, you may compress it with GNU gzip to save disk space.

31.2.1. Image Portability

Memory images are not portable across different platforms (in contrast with platform-independent #P".fas" files). They are not even portable across linking sets: image saved using the full linking set cannot be used with the base runtime:

$ clisp -K full -x '(EXT:SAVEINITMEM)'
$ clisp -K base -M lispinit.mem
base/lisp.run: initialization file `lispinit.mem' was not created by this version of CLISP runtime

See also SFmail/BF6EFF38DF3FA647BBD932720D8BED650BAA11%40parmbx02.ilog.biz/Gmane/devel/17757.


These notes document CLISP version 2.49Last modified: 2010-07-07