Skip to content

Commit

Permalink
Making TCC work again on Windows --cpu:amd64 - fix #16326 (#19221)
Browse files Browse the repository at this point in the history
* fix #16326

* removing comments
  • Loading branch information
rockcavera authored Dec 8, 2021
1 parent cd592ed commit 7806ec5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/system/io.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,22 @@ when defined(windows):
else:
proc c_fseek(f: File, offset: int64, whence: cint): cint {.
importc: "_fseeki64", header: "<stdio.h>", tags: [].}
proc c_ftell(f: File): int64 {.
importc: "_ftelli64", header: "<stdio.h>", tags: [].}
when defined(tcc):
proc c_fsetpos(f: File, pos: var int64): int32 {.
importc: "fsetpos", header: "<stdio.h>", tags: [].}
proc c_fgetpos(f: File, pos: var int64): int32 {.
importc: "fgetpos", header: "<stdio.h>", tags: [].}
proc c_telli64(f: cint): int64 {.
importc: "_telli64", header: "<io.h>", tags: [].}
proc c_ftell(f: File): int64 =
# Taken from https://pt.osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.4-trunk/mingwrt/mingwex/stdio/ftelli64.c
result = -1'i64
var pos: int64
if c_fgetpos(f, pos) == 0 and c_fsetpos(f, pos) == 0:
result = c_telli64(c_fileno(f))
else:
proc c_ftell(f: File): int64 {.
importc: "_ftelli64", header: "<stdio.h>", tags: [].}
else:
proc c_fseek(f: File, offset: int64, whence: cint): cint {.
importc: "fseeko", header: "<stdio.h>", tags: [].}
Expand Down

2 comments on commit 7806ec5

@rockcavera
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Araq , I was testing to build Nim from TCC using this: koch boot -d:release --cc:tcc

But I get this error message: D:\Nim\lib\system\io.nim(119, 12) Error: 'c_ftell' should be: 'cFtell'

The error also happens if you try to compile the Nim compiler directly with D:\Nim\compiler>nim.exe c -d:release --cc:tcc nim.nim

After researching, I noticed that this error happens with TCC, GCC, CLANG, VCC... but the error does not happen outside of the Nim compiler compilation.

It's like the compiler doesn't find the procedure since it has an underscore (_), but if you remove the underscore, it works normally. The name prefixed with c_ doesn't matter, as it can be prefixed with anything else but the underscore that won't work. Another way that works normally is when the procedure is imported from a c function, in the case of the pragma {.importc.}.

@Araq
Copy link
Member

@Araq Araq commented on 7806ec5 Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just

@if nimHasStyleChecks:
  styleCheck:error
@end

at work. Can be mitigated by

when defined(nimHasStyleChecks):
  {.push styleChecks: off.}

... <io code here>

when defined(nimHasStyleChecks):
  {.pop.}

Please sign in to comment.