Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#584 closed defect (fixed)

Unused arguments in callback wrappers are incorrectly optimized away

Reported by: sjamaan Owned by: felix winkelmann
Priority: critical Milestone: 4.9.0
Component: compiler Version: 4.6.x
Keywords: optimizations, define-external, ffi Cc:
Estimated difficulty:

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

Attachments (1)

define-external-no-optimization.patch (1.6 KB) - added by sjamaan 13 years ago.
Insert module-qualified names into callback-names db

Download all attachments as: .zip

Change History (5)

Changed 13 years ago by sjamaan

Insert module-qualified names into callback-names db

comment:1 Changed 13 years ago by felix winkelmann

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

comment:2 Changed 13 years ago by sjamaan

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.

comment:3 Changed 13 years ago by felix winkelmann

Resolution: fixed
Status: newclosed

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

comment:4 Changed 12 years ago by felix winkelmann

Milestone: 4.8.04.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.