VM FFI: write(stderr, msg) and fprintf(cstderr, msg) now work at CT (#13083)
This commit is contained in:
parent
1c001fe583
commit
ee1563ef33
3 changed files with 29 additions and 5 deletions
|
|
@ -116,9 +116,15 @@ type
|
||||||
incompleteStruct.} = object
|
incompleteStruct.} = object
|
||||||
CFilePtr* = ptr CFile ## The type representing a file handle.
|
CFilePtr* = ptr CFile ## The type representing a file handle.
|
||||||
|
|
||||||
|
# duplicated between io and ansi_c
|
||||||
|
const stderrName = when defined(osx): "__stderrp" else: "stderr"
|
||||||
|
const stdoutName = when defined(osx): "__stdoutp" else: "stdout"
|
||||||
|
const stdinName = when defined(osx): "__stdinp" else: "stdin"
|
||||||
|
|
||||||
var
|
var
|
||||||
cstderr* {.importc: "stderr", header: "<stdio.h>".}: CFilePtr
|
cstderr* {.importc: stderrName, header: "<stdio.h>".}: CFilePtr
|
||||||
cstdout* {.importc: "stdout", header: "<stdio.h>".}: CFilePtr
|
cstdout* {.importc: stdoutName, header: "<stdio.h>".}: CFilePtr
|
||||||
|
cstdin* {.importc: stdinName, header: "<stdio.h>".}: CFilePtr
|
||||||
|
|
||||||
proc c_fprintf*(f: CFilePtr, frmt: cstring): cint {.
|
proc c_fprintf*(f: CFilePtr, frmt: cstring): cint {.
|
||||||
importc: "fprintf", header: "<stdio.h>", varargs, discardable.}
|
importc: "fprintf", header: "<stdio.h>", varargs, discardable.}
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,17 @@ type
|
||||||
|
|
||||||
# text file handling:
|
# text file handling:
|
||||||
when not defined(nimscript) and not defined(js):
|
when not defined(nimscript) and not defined(js):
|
||||||
|
# duplicated between io and ansi_c
|
||||||
|
const stderrName = when defined(osx): "__stderrp" else: "stderr"
|
||||||
|
const stdoutName = when defined(osx): "__stdoutp" else: "stdout"
|
||||||
|
const stdinName = when defined(osx): "__stdinp" else: "stdin"
|
||||||
|
|
||||||
var
|
var
|
||||||
stdin* {.importc: "stdin", header: "<stdio.h>".}: File
|
stdin* {.importc: stdinName, header: "<stdio.h>".}: File
|
||||||
## The standard input stream.
|
## The standard input stream.
|
||||||
stdout* {.importc: "stdout", header: "<stdio.h>".}: File
|
stdout* {.importc: stdoutName, header: "<stdio.h>".}: File
|
||||||
## The standard output stream.
|
## The standard output stream.
|
||||||
stderr* {.importc: "stderr", header: "<stdio.h>".}: File
|
stderr* {.importc: stderrName, header: "<stdio.h>".}: File
|
||||||
## The standard error stream.
|
## The standard error stream.
|
||||||
|
|
||||||
when defined(useStdoutAsStdmsg):
|
when defined(useStdoutAsStdmsg):
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ foo:102:103
|
||||||
foo:102:103:104
|
foo:102:103:104
|
||||||
foo:0.03:asdf:103:105
|
foo:0.03:asdf:103:105
|
||||||
ret={s1:foobar s2:foobar age:25 pi:3.14}
|
ret={s1:foobar s2:foobar age:25 pi:3.14}
|
||||||
|
hello world stderr
|
||||||
|
hi stderr
|
||||||
'''
|
'''
|
||||||
output: '''
|
output: '''
|
||||||
foo
|
foo
|
||||||
|
|
@ -17,6 +19,8 @@ foo:102:103
|
||||||
foo:102:103:104
|
foo:102:103:104
|
||||||
foo:0.03:asdf:103:105
|
foo:0.03:asdf:103:105
|
||||||
ret={s1:foobar s2:foobar age:25 pi:3.14}
|
ret={s1:foobar s2:foobar age:25 pi:3.14}
|
||||||
|
hello world stderr
|
||||||
|
hi stderr
|
||||||
'''
|
'''
|
||||||
disabled: "true"
|
disabled: "true"
|
||||||
"""
|
"""
|
||||||
|
|
@ -76,6 +80,15 @@ proc fun() =
|
||||||
if false:
|
if false:
|
||||||
c_printf("foo2:a=%d\n", a2)
|
c_printf("foo2:a=%d\n", a2)
|
||||||
|
|
||||||
|
|
||||||
static:
|
static:
|
||||||
fun()
|
fun()
|
||||||
fun()
|
fun()
|
||||||
|
|
||||||
|
when true:
|
||||||
|
import system/ansi_c
|
||||||
|
proc fun2()=
|
||||||
|
c_fprintf(cstderr, "hello world stderr\n")
|
||||||
|
write(stderr, "hi stderr\n")
|
||||||
|
static: fun2()
|
||||||
|
fun2()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue