Summary

Unused arguments in callback wrappers are incorrectly optimized away

Metadata

Attachments

Description

 (module bla (foo)
 
 (import chicken scheme foreign)
 
 (define-external
   (blabla (int a) (c-string b) (int c) (int d) (c-string e) (int f))
   void
   (print "HELLO"))
 
 (define (foo) ((foreign-safe-lambda* void () "blabla(1, \"2\", 3, 4, \"5\", 6);")))
 )
 
 (import bla)
 (foo)

This gives an error:

 Error: bad argument count - received 6 but expected 2: #<procedure>
 
         Call history:
 
         test.scm:14: bla#foo      
         ##sys#gc          
         g2728           <--

This is caused by the fact that callback-names contains the unqualified procedure name (not prefixed with a module name).

Attached is a patch that seems to fix this (but I'm not 100% sure if it's the Right Way(TM) of fixing this).

I think there may be other bugs like this where the raw symbol is inserted into some database while it should be using the qualified name, so it's probably a good idea to review other parts of the optimizer.

PS: The milestone 4.7.0 was reached, it should be closed in Trac and the Version dropdown should be changed to include 4.7.0

Changes and comments

[2011-05-29 16:28:05 UTC] sjamaan attached define-external-no-optimization.patch (description=Insert module-qualified names into callback-names db)

[2011-06-06 13:13:24 UTC] felix wrote:

The patch is basically correct, but will break `(location <callbackname>)`. I will figure something out. Thanks, Peter.

[2011-06-06 15:14:51 UTC] sjamaan wrote:

Oh, that's unfortunate.

If anyone else is having this problem, just sticking a (list a b c d ...) call somewhere (including all (unused) arguments to the procedure) in the procedure is a good workaround.

[2011-06-14 11:06:42 UTC] felix changed status from new to closed

[2011-06-14 11:06:42 UTC] felix set resolution to fixed

[2011-06-14 11:06:42 UTC] felix wrote:

Fixed in "experimental". The raw symbol and the aliased name are now saved in `callback-names`, to make `location` work.

[2012-09-24 21:47:48 UTC] felix changed milestone from 4.8.0 to 4.9.0

[2012-09-24 21:47:48 UTC] felix wrote:

Milestone 4.8.0 deleted