futhark
futhark copied to clipboard
FILE* is translated incorrectly to ptr File -> ptr ptr CFile
/home/deodex/Documents/CODE/Nim/natsuhi/src/natsuhi.nim(40, 29) Error: type mismatch: got <typeof(nil), File>
but expected one of:
proc notcursescoreinit(opts: ptr notcursesoptions_1342177605;
fp: ptr File_1342177650): ptr notcurses
first type mismatch at position: 2
required type for fp: ptr File_1342177650
but expression 'stdout' is of type: File
expression: notcursescoreinit(nil, stdout)
this should work (this does in a nimterop wrapper); fp
should just be File
or ptr CFile
File_1342177650* = (when declared(File):
File
else:
File_1342177649)
offending C header file (notcurses/include/notcurses/notcurses.h
)
// The same as notcurses_init(), but without any multimedia functionality,
// allowing for a svelter binary. Link with notcurses-core if this is used.
API ALLOC struct notcurses* notcurses_core_init(const notcurses_options* opts, FILE* fp);
futhark perhaps should check if nim has the type in posix or io or so before going into the C headers and generating a new type, but i can see how that would be tricky
e: i misunderstood, but the comment before this still applies
workaround for this issue is this
import std/[typetraits, os]
const clangIncludeDir {.strdefine.} = "/usr/lib/clang/13.0.0/include"
type CFile* = typeof(File.pointerBase)
importc:
absPath clangIncludeDir
path currentSourcePath() / ".." / ".." / "notcurses/include/notcurses/"
rename FILE, CFile
"notcurses.h"
Okay, I think I fully understand the idea now, what is needed is better retyping for other types like function parameter types and so so that the workaround doesn’t need to muck around redefining an internal type and could just change ptr File into File
What do you mean by better retyping? Isn't it working well for you? The problem here is that I want to keep Futhark as automatic as absolutely possible, so adding overrides for defined things isn't a great solution. But I thought FILE
was actually working, I could've sworn I've used those with a Futhark wrapped library before..
It only "works" if I manually get what the pointer base of File is and rename FILE to that. I was thinking better utilities like being able to rename a not-named type like FILE* itself into File without needing to get the pointer base