Changeset 15908 in project


Ignore:
Timestamp:
09/15/09 21:24:07 (10 years ago)
Author:
Kon Lovett
Message:

Made raising an error optional for dynamic load routines. Updated manual for new routines.

Location:
chicken/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • chicken/trunk/eval.scm

    r15907 r15908  
    10911091          (loop (cdr ils) (if (member nam (dynamic-load-libraries)) ols (cons nam ols))) ) ) ) )
    10921092
    1093 (define (dynamic-library-load name)
     1093(define (dynamic-library-load name #!optional (err? #t))
    10941094  (##sys#check-string name 'dynamic-library-load)
    10951095  (or (##sys#dynamic-library-load name)
    1096       (##sys#error 'dynamic-library-load "cannot load dynamic library" name _dlerror) ) )
    1097 
    1098 ;; (dynamic-library-procedure mname sname handler) => procedure/n
    1099 ;; (dynamic-library-variable mname sname handler) => procedure/n
     1096      (and err?
     1097           (##sys#error 'dynamic-library-load "cannot load dynamic library" name _dlerror) ) ) )
     1098
     1099;; (dynamic-library-procedure mname sname handler [error?]) => procedure/n
     1100;; (dynamic-library-variable mname sname handler [error?]) => procedure/n
    11001101;;
    11011102;; The 'procedure/n' invokes the handler on (mname sname mname+sname-ptr n-args).
     
    11101111(let ()
    11111112
    1112   (define (checked-pointer loc ptrfnc mname sname)
     1113  (define (checked-pointer loc ptrfnc mname sname err?)
    11131114    (or (ptrfnc mname sname)
    1114         (and (parameterize ((dynamic-load-mode '(lazy global))) (dynamic-library-load mname))
     1115        (and (parameterize ((dynamic-load-mode '(lazy global)))
     1116               (dynamic-library-load mname err?))
    11151117             (ptrfnc mname sname) )
    1116         (##sys#error loc "cannot resolve dynamic library symbol" mname sname _dlerror) ) )
    1117 
    1118   (define (dynlibsym loc ptrfnc mname sname handler)
     1118        (and err?
     1119             (##sys#error loc "cannot resolve dynamic library symbol" mname sname _dlerror) ) ) )
     1120
     1121  (define (dynlibsym loc ptrfnc mname sname handler err?)
    11191122    (##sys#check-string mname loc)
    11201123    (##sys#check-closure handler loc)
    11211124    (let ((sname (if (symbol? sname) (symbol->string sname) sname)))
    11221125      (##sys#check-string sname loc)
    1123       (let ((ptr (checked-pointer loc ptrfnc mname sname)))
     1126      (and-let* ((ptr (checked-pointer loc ptrfnc mname sname err?)))
    11241127        (lambda args (handler mname sname ptr args)) ) ) )
    11251128
    11261129  (set! dynamic-library-procedure
    1127     (lambda (mname sname handler)
     1130    (lambda (mname sname handler #!optional (err? #t))
    11281131      (dynlibsym 'dynamic-library-procedure
    1129                  ##sys#dynamic-library-procedure-pointer mname sname handler) ) )
     1132                 ##sys#dynamic-library-procedure-pointer mname sname handler err?) ) )
    11301133
    11311134  (set! dynamic-library-variable
    1132     (lambda (mname sname handler)
     1135    (lambda (mname sname handler #!optional (err? #t))
    11331136      (dynlibsym 'dynamic-library-variable
    1134                  ##sys#dynamic-library-variable-pointer mname sname handler) ) ) )
     1137                 ##sys#dynamic-library-variable-pointer mname sname handler err?) ) ) )
    11351138
    11361139
  • chicken/trunk/manual/Parameters

    r15896 r15908  
    5858the program and any runtime options (all options starting with {{-:}})
    5959removed.
    60 
    6160
    6261
     
    131130abort the current computation and to restart the read-eval-print loop.
    132131
     132
     133=== dynamic-load-mode
     134On systems that support dynamic loading of compiled code via the {{dlopen(3)}}
     135interface (for example Linux and Solaris), some options can be specified to
     136fine-tune the behaviour of the dynamic linker. {{MODE}} should be a list of
     137symbols (or a single symbol) taken from the following set:
     138
     139; {{local}} : If {{local}} is given, then any C/C++ symbols defined in the dynamically loaded file are not available for subsequently loaded files and libraries. Use this if you have linked foreign code into your dynamically loadable file and if you don't want to export them (for example because you want to load another file that defines the same symbols).
     140; {{global}} : The default is {{global}}, which means all C/C++ symbols are available to code loaded at a later stage.
     141; {{now}} : If {{now}} is specified, all symbols are resolved immediately.
     142; {{lazy}} : Unresolved symbols are resolved as code from the file is executed. This is the default.
     143
     144Note that this procedure does not control the way Scheme variables are handled -
     145this facility is mainly of interest when accessing foreign code.
     146
    133147---
    134148Previous: [[Declarations]]
  • chicken/trunk/manual/Unit eval

    r13710 r15908  
    6262
    6363See also the [[http://chicken.wiki.br/Parameters#load-verbose|load-verbose]] parameter.
     64
    6465==== load-library
    6566
     
    8182the {{load-library}} does nothing.
    8283
     84==== loaded-libraries
     85
     86 [procedure] (loaded-libraries)
     87 
     88Returns a list of the dynamic library names.
     89
     90==== dynamic-library-load
     91
     92 [procedure] (dynamic-library-load LIBRARYFILE [ERROR?])
     93 
     94Performs a dynamic load of the binary file {{LIBRARYFILE}}.
     95
     96WIll raise an error upon failure to find the symbol. Unless {{ERROR?}} is
     97{{#f}}, in which case {{#f}} is returned.
     98
     99==== dynamic-library-procedure
     100
     101 [procedure] (dynamic-library-procedure LIBRARYFILE SYMBOLNAME HANDLER [ERROR?])
     102 
     103Performs a symbol to address lookup in the dynamic load library
     104{{LIBRARYFILE}}. Attempts to load the library if not already loaded.
     105
     106A {{symbol}} {{SYMBOLNAME}} will be converted to a {{string}}.
     107
     108{{HANDLER}} is a procedure of 4 arguments.
     109
     110Returns a {{procedure}} of N arguments, {{ARGS}}, with body
     111{{(HANDLER LIBRARYFILE SYMBOLNAME POINTER ARGS)}}. {{PONTER}} is a {{pointer}}
     112with an address value of the symbol in the library.
     113
     114WIll raise an error upon failure to find the symbol. Unless {{ERROR?}} is
     115{{#f}}, in which case {{#f}} is returned.
     116
     117On platforms other than Windows the literal form of the symbol is attempted
     118first, followed by a lookup with a leading underscore {{#\_}}.
     119
     120==== dynamic-library-variable
     121
     122 [procedure] (dynamic-library-variable LIBRARYFILE SYMBOLNAME HANDLER [ERROR?])
     123 
     124Performs a symbol to address lookup in the dynamic load library
     125{{LIBRARYFILE}}. Attempts to load the library if not already loaded.
     126
     127A {{symbol}} {{SYMBOLNAME}} will be converted to a {{string}}.
     128
     129{{HANDLER}} is a procedure of 4 arguments.
     130
     131Returns a {{procedure}} of N arguments, {{ARGS}}, with body
     132{{(HANDLER LIBRARYFILE SYMBOLNAME POINTER ARGS)}}. {{PONTER}} is a {{pointer}}
     133with an address value of the symbol in the library.
     134
     135WIll raise an error upon failure to find the symbol. Unless {{ERROR?}} is
     136{{#f}}, in which case {{#f}} is returned.
     137
     138On platforms other than Windows the literal form of the symbol is attempted
     139first, followed by a lookup with a leading underscore {{#\_}}.
     140
     141The distinction between a procedure and variable symbol lookup is platform
     142dependent, if even possible. On Windows {{dynamic-library-variable}} will
     143always fail. On all other supported platforms {{dynamic-library-variable}} will
     144do the right thing.
     145
    83146==== set-dynamic-load-mode!
    84147
     
    97160Note that this procedure does not control the way Scheme variables are handled -
    98161this facility is mainly of interest when accessing foreign code.
     162
     163DEPRECATED - See the [[http://chicken.wiki.br/Parameters#dynamic-load-mode|dynamic-load-mode]] parameter
    99164
    100165
Note: See TracChangeset for help on using the changeset viewer.