Opened 9 years ago

Closed 4 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:


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)

get-rid-of-global-ref.patch (1.3 KB) - added by Moritz Heidkamp 9 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 9 years ago by felix winkelmann

Milestone: 4.7.0

comment:2 Changed 9 years ago by Moritz Heidkamp

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.

Changed 9 years ago by Moritz Heidkamp

Attachment: get-rid-of-global-ref.patch added

comment:3 Changed 9 years ago by Moritz Heidkamp

OK, that approach does not work when autoload is used in modules unfortunately.

comment:4 Changed 7 years ago by Moritz Heidkamp

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 Changed 7 years ago by Alaric Snell-Pym

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))
           `(module ,(gensym) ()
                      (only scheme vector require-extension quote) ; quote shouldn't need to be here
                      (vector ,vektor) (require-extension ,rekuire-extension)))
                    (,rekuire-extension ,module)
                    (,vektor ,@bindings))))
      exn (if ((condition-predicate 'syntax) exn)
              (signal (make-composite-condition
                       (make-property-condition 'exn
                                                (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
     (apply lzma:compress args)))

 (define lzma:decompress
   (lambda args
     (apply lzma:decompress args)))

comment:6 Changed 7 years ago by Alaric Snell-Pym

Gah, I failed to format my code correctly. Let's just use the pastebin:

comment:7 Changed 4 years ago by sjamaan

Resolution: fixed
Status: newclosed

I fixed this with autoload 3.0 in [33550] / [33551]

Note: See TracTickets for help on using tickets.