Opened 7 years ago

Closed 5 years ago

#1346 closed defect (fixed)

define-external variables can't be exported

Reported by: sjamaan Owned by: felix winkelmann
Priority: major Milestone: 5.2
Component: compiler Version: 4.12.0
Keywords: ffi Cc:
Estimated difficulty: medium

Description

This program fails to compile:

(module test (x)
  (import foreign scheme chicken)
  (define-external x int 123))

If you don't wrap it in a module, x doesn't exist if you load the shared object you get from csc -s.

Change History (9)

comment:1 Changed 7 years ago by LemonBoy

Here's a patch patch addressing this problem.

comment:2 Changed 5 years ago by sjamaan

Milestone: someday5.1

Let's try to fix this in 5.1. It's still relevant.

comment:3 Changed 5 years ago by sjamaan

Milestone: 5.15.2

Getting ready for 5.1, moving tickets which won't make it in to 5.2.

comment:4 Changed 5 years ago by felix winkelmann

You cannot export a foreign variable - it is not a variable that doesn't have normal Scheme semantics, it may be a volatile memory location and any Scheme variable bound to this will be completely detached. Note that the situation for callback-functions is different, the Scheme part can be called externally and refers only internally to the foreign entity (a function in this case).

I recommend to signal an error when a foreign-variable is appearing in an export list.

comment:5 Changed 5 years ago by felix winkelmann

A patch has been posted for this, but it is probably not complete. We could also check for names defined by define-constant and define-type as well...

comment:6 Changed 5 years ago by felix winkelmann

Owner: set to felix winkelmann
Status: newassigned

comment:7 Changed 5 years ago by sjamaan

Patch has been applied. Should we keep this ticket here or move to 5.3 for the remaining things?

comment:8 Changed 5 years ago by felix winkelmann

A patch for detecting all other entities has been submitted to chicken-hackers.

comment:9 Changed 5 years ago by felix winkelmann

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.