diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-05-06 08:16:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 17:16:54 +0200 |
commit | 330b3c4453bbff572987ad7fe2f435b353529964 (patch) | |
tree | 1df721a817b23bd32f556c219480f69dbec38350 /tests/vm/mevalffi.nim | |
parent | b8e6ea7547344389b5e45c3af249fee9642f028e (diff) | |
download | Nim-330b3c4453bbff572987ad7fe2f435b353529964.tar.gz |
fix regression: -d:nimHasLibFFI was not being tested anymore (#14234)
* * fix regression: -d:nimHasLibFFI was not being tested anymore, in part because testament was silently treating some errors as easy to overlook messages * turned that message into an error * -d:nimHasLibFFI is now being tested with nim cpp * use correct signatures for importc procs * workaround for openbsd to unblock ctffi testing
Diffstat (limited to 'tests/vm/mevalffi.nim')
-rw-r--r-- | tests/vm/mevalffi.nim | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/tests/vm/mevalffi.nim b/tests/vm/mevalffi.nim index e15ed8f74..ad8f8b62b 100644 --- a/tests/vm/mevalffi.nim +++ b/tests/vm/mevalffi.nim @@ -8,9 +8,9 @@ proc c_exp(a: float64): float64 {.importc: "exp", header: "<math.h>".} proc c_printf(frmt: cstring): cint {.importc: "printf", header: "<stdio.h>", varargs, discardable.} const snprintfName = when defined(windows): "_snprintf" else: "snprintf" -proc c_snprintf*(buffer: pointer, buf_size: uint, format: cstring): cint {.importc: snprintfName, header: "<stdio.h>", varargs .} +proc c_snprintf*(str: cstring, size: csize_t, format: cstring): cint {.importc: snprintfName, header: "<stdio.h>", varargs .} -proc c_malloc(size:uint):pointer {.importc:"malloc", header: "<stdlib.h>".} +proc c_malloc(size: csize_t): pointer {.importc:"malloc", header: "<stdlib.h>".} proc c_free(p: pointer) {.importc:"free", header: "<stdlib.h>".} proc fun() = @@ -35,12 +35,15 @@ proc fun() = block: # c_snprintf, c_malloc, c_free let n: uint = 50 - var buffer2: pointer = c_malloc(n) + var buffer2 = cstring(cast[ptr char](c_malloc(n))) + var s: cstring = "foobar" var age: cint = 25 - discard c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14) - c_printf("ret={%s}\n", buffer2) - c_free(buffer2) # not sure it has an effect + let num = c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14) + let numExp = 34 + doAssert num == numExp + c_printf("ret=[%s]\n", buffer2) + c_free(buffer2) block: # c_printf bug var a = 123 @@ -58,10 +61,11 @@ static: fun() fun() -import system/ansi_c -block: - proc fun2()= - c_fprintf(cstderr, "hello world stderr\n") - write(stderr, "hi stderr\n") - static: fun2() - fun2() +when not defined nimEvalffiStderrWorkaround: + import system/ansi_c + block: + proc fun2()= + c_fprintf(cstderr, "hello world stderr\n") + write(stderr, "hi stderr\n") + static: fun2() + fun2() |