Opened 15 years ago
Closed 9 years ago
#548 closed defect (fixed)
autoload egg broken with newer chicken
| Reported by: | Moritz Heidkamp | Owned by: | foof |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | extensions | Version: | 4.6.x |
| Keywords: | autoload global-ref | Cc: | |
| Estimated difficulty: |
Description
At least with Chicken 4.6.5 (and probably some versions before that) the autoload egg is broken because it uses global-ref. A work-around is unknown--can such functionality be implemented without global-ref at all?
Attachments (1)
Change History (8)
comment:1 by , 15 years ago
| Milestone: | 4.7.0 |
|---|
comment:2 by , 14 years ago
by , 14 years ago
| Attachment: | get-rid-of-global-ref.patch added |
|---|
comment:3 by , 14 years ago
OK, that approach does not work when autoload is used in modules unfortunately.
comment:4 by , 12 years ago
Although the use of global-ref was removed, the autoload form now only works when the referenced module is actually available, i.e. it is not possible to autoload modules from eggs which aren't installed. Is this intended behavior? If so we can close this ticket.
comment:5 by , 12 years ago
I don't know about the egg author's intended behaviour, but for me, it's certainly not helpful behaviour :-) I originally used the autoload egg in Ugarit to support optional dependencies; eg, if the user (at run time) selected AES encryption, then it would attempt to use the aes functions, causing run-time auto-loading of the aes egg. But the code could compile and run fine if AES wasn't installed, as long as you didn't ask to use aes. This is a convenient and simple way to support optional dependencies.
Due to autoload no longer functioning in that way, I was forced to hack together my own autoload-esque mechanism for Ugarit. However, it doesn't support all the features of autoload, and doesn't have a nice wrapper macro, it's just the bits I need:
(define (get-bindings-from-module egg module bindings)
(let* ((vektor (gensym))
(rekuire-extension (gensym))
(expression
`(module ,(gensym) ()
(import
(rename
(only scheme vector require-extension quote) ; quote shouldn't need to be here
(vector ,vektor) (require-extension ,rekuire-extension)))
(,rekuire-extension ,module)
(,vektor ,@bindings))))
(handle-exceptions
exn (if ((condition-predicate 'syntax) exn)
(signal (make-composite-condition
(make-property-condition 'exn
'message
(sprintf "This feature depends upon the optional module ~a being installed. Please install it with 'chicken-install -s ~a'." module egg))
(make-property-condition 'unsupported-feature
'egg egg
'module module
'bindings bindings)))
(signal exn))
(eval expression))))
;; FIXME: Write a macro to generate these for us.
(define (autoload-lzma!)
(let ((real-bindings
(get-bindings-from-module 'lzma 'lzma '(compress decompress))))
(set! lzma:compress (vector-ref real-bindings 0))
(set! lzma:decompress (vector-ref real-bindings 1))))
(define lzma:compress
(lambda args
(autoload-lzma!)
(apply lzma:compress args)))
(define lzma:decompress
(lambda args
(autoload-lzma!)
(apply lzma:decompress args)))
comment:6 by , 12 years ago
Gah, I failed to format my code correctly. Let's just use the pastebin:
http://paste.call-cc.org/paste?id=752dd0e1667a1d7ffbda53d05df847c89a6e2e75
comment:7 by , 9 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |

The attached patch makes autoload work with newer Chickens again and should also be downwards compatible. However, it will emit notes about unbound toplevel variables when used interactively in csi. I guess that's not a big issue though.