Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Strange bug when linking foreign functions ( Bad file descriptor )

Open SrMordred opened this issue 3 years ago • 4 comments

Odin Report:

        Odin: dev-2021-11-nightly:bb7703fc
        OS:   Windows 10 Professional (version: 20H2), build 19042.1348
        CPU:  AMD Ryzen 5 1600 Six-Core Processor
        RAM:  16314 MiB

Error example

package main

import "core:fmt"

foreign import "system:libucrt.lib"
@(default_calling_convention = "stdcall")
foreign libucrt {
    _execlp :: proc( file: cstring, arg: cstring, #c_vararg args: ..any ) -> uintptr ---;
}

main :: proc () {
    err := _execlp( "dir", "dir", nil ); //comment here
    fmt.print("oi?"); 
}

Output:

dir: write error: Bad file descriptor

Commenting the cited line 'unbug' the output.

SrMordred avatar Nov 29 '21 01:11 SrMordred

Does this work if you change the signature to this?

_execlp :: proc( file: cstring, arg: cstring, #c_vararg args: ..cstring) -> uintptr ---

gingerBill avatar Nov 29 '21 01:11 gingerBill

My hunch is that the passed nil is actually getting passed as a nil any e.g. any{}.

gingerBill avatar Nov 29 '21 01:11 gingerBill

Changing the signature didn´t change the error. Also, calling like this _execlp( "dir", "dir") crashes the program. (exit code -1073741819)

SrMordred avatar Nov 29 '21 01:11 SrMordred

Hello!

I am marking this issue as stale as it has not received any engagement from the community or maintainers 120 days. That does not imply that the issue has no merit! If you feel strongly about this issue

  • open a PR referencing and resolving the issue;
  • leave a comment on it and discuss ideas how you could contribute towards resolving it;
  • leave a comment and describe in detail why this issue is critical for your use case;
  • open a new issue with updated details and a plan on resolving the issue.

The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone..

github-actions[bot] avatar Jul 24 '22 22:07 github-actions[bot]