Skip to content

Commit fc8dc00

Browse files
committed
fix test: incorrect printf format specifier discovered by this feature; simplify test now that #13489 was merged
1 parent 002001f commit fc8dc00

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

tests/vm/mevalffi.nim

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,32 @@ proc fun() =
2424
doAssert c_exp(x2) == c_exp(x)
2525

2626
block: # c_printf
27-
c_printf("foo\n")
28-
c_printf("foo:%d\n", 100)
29-
c_printf("foo:%d\n", 101.cint)
30-
c_printf("foo:%d:%d\n", 102.cint, 103.cint)
27+
c_printf("foo0\n")
28+
c_printf("foo1:%d\n", 101.cint)
29+
c_printf("foo2:%d:%d\n", 102.cint, 103.cint)
3130
let temp = 104.cint
32-
c_printf("foo:%d:%d:%d\n", 102.cint, 103.cint, temp)
31+
c_printf("foo3:%d:%d:%d\n", 102.cint, 103.cint, temp)
3332
var temp2 = 105.cint
34-
c_printf("foo:%g:%s:%d:%d\n", 0.03, "asdf", 103.cint, temp2)
33+
c_printf("foo4:%g:%s:%d:%d\n", 0.03, "asdf", 103.cint, temp2)
3534

3635
block: # c_snprintf, c_malloc, c_free
3736
let n: uint = 50
3837
var buffer2: pointer = c_malloc(n)
3938
var s: cstring = "foobar"
4039
var age: cint = 25
4140
discard c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14)
42-
c_printf("ret={%s}\n", buffer2)
41+
c_printf("foo5:{%s}\n", buffer2)
4342
c_free(buffer2) # not sure it has an effect
4443

45-
block: # c_printf bug
46-
var a = 123
44+
block: # c_printf bug with `var` {.varargs.} params
45+
var a = 123.cint
4746
var a2 = a.addr
48-
#[
49-
bug: different behavior between CT RT in this case:
50-
at CT, shows foo2:a=123
51-
at RT, shows foo2:a=<address as int>
52-
]#
53-
if false:
54-
c_printf("foo2:a=%d\n", a2)
47+
when false:
48+
# BUG: CT FFI currently does not handle this edge case correctly,
49+
# passing `a2` as `cint` instead of as `ptr cint` for a {.varargs.} param:
50+
# at CT, shows foo6:a2=0x7b
51+
# at RT, shows foo2:a2=<address>
52+
c_printf("foo6:a2=%p\n", a2)
5553

5654

5755
static:

tests/vm/tevalffi.nim

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import std/[strformat,os,osproc]
77
proc main() =
88
const nim = getCurrentCompilerExe()
99
const file = currentSourcePath().parentDir / "mevalffi.nim"
10-
# strangely, --hint:cc:off was needed
1110
let cmd = fmt"{nim} c -f --experimental:compiletimeFFI --hints:off --hint:cc:off {file}"
1211
let (output, exitCode) = execCmdEx(cmd)
1312
let expected = """
1413
hello world stderr
1514
hi stderr
16-
foo
17-
foo:100
18-
foo:101
19-
foo:102:103
20-
foo:102:103:104
21-
foo:0.03:asdf:103:105
22-
ret={s1:foobar s2:foobar age:25 pi:3.14}
15+
foo0
16+
foo1:101
17+
foo2:102:103
18+
foo3:102:103:104
19+
foo4:0.03:asdf:103:105
20+
foo5:{s1:foobar s2:foobar age:25 pi:3.14}
2321
"""
2422
doAssert output == expected, output
2523
doAssert exitCode == 0

0 commit comments

Comments
 (0)