mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-20 20:39:06 +00:00
cgo: do a basic test that math functions work
They should, but we weren't testing this. I discovered this while working on https://github.com/tinygo-org/macos-minimal-sdk/pull/4 which will likely make math.h not work anymore. So I wanted to make sure we have a test in place before we update that dependency.
This commit is contained in:
committed by
Ron Evans
parent
7b7601d77c
commit
c383a407e3
Vendored
+5
@@ -1,3 +1,4 @@
|
|||||||
|
#include <math.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
int global = 3;
|
int global = 3;
|
||||||
@@ -67,3 +68,7 @@ void unionSetData(short f0, short f1, short f2) {
|
|||||||
void arraydecay(int buf1[5], int buf2[3][8], int buf3[4][7][2]) {
|
void arraydecay(int buf1[5], int buf2[3][8], int buf3[4][7][2]) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double doSqrt(double x) {
|
||||||
|
return sqrt(x);
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+5
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
int fortytwo(void);
|
int fortytwo(void);
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
@@ -171,6 +172,10 @@ func main() {
|
|||||||
C.strcpy((*C.char)(unsafe.Pointer(&buf2[0])), (*C.char)(unsafe.Pointer(&buf1[0])))
|
C.strcpy((*C.char)(unsafe.Pointer(&buf2[0])), (*C.char)(unsafe.Pointer(&buf1[0])))
|
||||||
println("copied string:", string(buf2[:C.strlen((*C.char)(unsafe.Pointer(&buf2[0])))]))
|
println("copied string:", string(buf2[:C.strlen((*C.char)(unsafe.Pointer(&buf2[0])))]))
|
||||||
|
|
||||||
|
// libc: test libm functions (normally bundled in libc)
|
||||||
|
println("CGo sqrt(3):", C.sqrt(3))
|
||||||
|
println("C sqrt(3):", C.doSqrt(3))
|
||||||
|
|
||||||
// libc: test basic stdio functionality
|
// libc: test basic stdio functionality
|
||||||
putsBuf := []byte("line written using C puts\x00")
|
putsBuf := []byte("line written using C puts\x00")
|
||||||
C.puts((*C.char)(unsafe.Pointer(&putsBuf[0])))
|
C.puts((*C.char)(unsafe.Pointer(&putsBuf[0])))
|
||||||
|
|||||||
Vendored
+2
@@ -150,3 +150,5 @@ extern int global;
|
|||||||
// Test array decaying into a pointer.
|
// Test array decaying into a pointer.
|
||||||
typedef int arraydecay_buf3[4][7][2];
|
typedef int arraydecay_buf3[4][7][2];
|
||||||
void arraydecay(int buf1[5], int buf2[3][8], arraydecay_buf3 buf3);
|
void arraydecay(int buf1[5], int buf2[3][8], arraydecay_buf3 buf3);
|
||||||
|
|
||||||
|
double doSqrt(double);
|
||||||
|
|||||||
Vendored
+2
@@ -74,4 +74,6 @@ C.GoString(nil):
|
|||||||
len(C.GoStringN(nil, 0)): 0
|
len(C.GoStringN(nil, 0)): 0
|
||||||
len(C.GoBytes(nil, 0)): 0
|
len(C.GoBytes(nil, 0)): 0
|
||||||
copied string: foobar
|
copied string: foobar
|
||||||
|
CGo sqrt(3): +1.732051e+000
|
||||||
|
C sqrt(3): +1.732051e+000
|
||||||
line written using C puts
|
line written using C puts
|
||||||
|
|||||||
Reference in New Issue
Block a user