Skip to content

Commit ff2ea9a

Browse files
committed
fix test: incorrect printf format specifier discovered by this feature; simplify test now that nim-lang#13489 was merged
1 parent 0a691f3 commit ff2ea9a

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

tests/trunner.nim

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ proc testCTFFI() =
2929
let expected = """
3030
hello world stderr
3131
hi stderr
32-
foo
33-
foo:100
34-
foo:101
35-
foo:102:103
36-
foo:102:103:104
37-
foo:0.03:asdf:103:105
38-
ret={s1:foobar s2:foobar age:25 pi:3.14}
32+
foo0
33+
foo1:101
34+
foo2:102:103
35+
foo3:102:103:104
36+
foo4:0.03:asdf:103:105
37+
foo5:{s1:foobar s2:foobar age:25 pi:3.14}
3938
"""
4039
doAssert output == expected, output
4140
doAssert exitCode == 0

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:

0 commit comments

Comments
 (0)