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

cstring fix when using typedef #64

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/opir.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ proc toNimType(ct: CXType): JsonNode =
CXType_LongAccum, CXType_UShortAccum, CXType_UAccum, CXType_ULongAccum, CXType_Complex: %*{"kind": "invalid", "value": "???"}
of CXType_Pointer:
let info = ct.getPointerInfo
if info.depth == 1 and info.baseType.kind == CXType_CharS:
var kind = info.baseType.kind
if kind == CXType_Typedef:
kind = info.baseType.getTypeDeclaration.getTypedefDeclUnderlyingType.kind
if info.depth == 1 and kind in {CXType_Char_S, CXType_SChar}:
%*{"kind": "base", "value": "cstring"}
else:
let baseType = info.baseType.toNimType
Expand Down
5 changes: 5 additions & 0 deletions tests/tcstring.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "tcstring.h"

int my_func(const TCHAR* string) {
return strlen(string);
}
6 changes: 6 additions & 0 deletions tests/tcstring.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <string.h>
typedef char TCHAR;
typedef signed char TSCHAR;
typedef unsigned char TUCHAR;

int my_func(const TCHAR* string);
9 changes: 9 additions & 0 deletions tests/tcstring.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "../src/futhark"

{.compile: "tcstring.c".}

importc:
path "."
"tcstring.h"

doAssert my_func("Hello".cstring) == 5