Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysterious return value in a script #1

Open
mathias-brandewinder opened this issue Mar 7, 2015 · 1 comment
Open

Mysterious return value in a script #1

mathias-brandewinder opened this issue Mar 7, 2015 · 1 comment
Assignees

Comments

@mathias-brandewinder
Copy link

namespace Planets

open Ferop

[<Ferop>]
module App = 

    [<Import; MI(MIO.NoInlining)>]
    let helloWorld () : int =

//        C"""printf ("Hello World\n"); """
        C"""return 42; """

Call from a script:

#r @"..\Planets\bin\Debug\Planets.dll"
open Planets

Planets.App.helloWorld () |> printfn "%A"

... returns mysterious values that are NOT necessarily 42.

@TIHan
Copy link
Owner

TIHan commented Mar 11, 2015

The mysterious value is most likely from "printf ("Hello World\n");" from the last time the C code was compiled but the new F# code was expecting a return value of type "int". So the value you got was a random number it decided to access in memory.

Exactly how this could happen, is that when you tried to compile your F# code, it passed, but when it tried to compile your C it failed; but, you had an old compiled C code with the same function names as the new one. Then, you tried to run your passed .NET DLL in FSI.

What should happen is that the .NET DLL shouldn't exist until the C code is compiled successfully; which doesn't happen currently. This can easily switched to do that. Or, we use a "tmp" place to do all the weaving and if it fails, it wont impact the previous build that was successful; that actually might be better.

@TIHan TIHan self-assigned this Mar 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants