Skip to content

Commit 16c681a

Browse files
committed
Add a test for str in C interoperation
1 parent 1c9c909 commit 16c681a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

integration_tests/test_c_interop_02.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def f_i16_i16(x: i16) -> i16:
2424
def f_i8_i8(x: i8) -> i8:
2525
pass
2626

27+
@ccall
28+
def f_str_i32(x: str) -> i32:
29+
pass
30+
2731
def test_c_callbacks():
2832
xf64: f64
2933
xf64 = 3.3
@@ -49,4 +53,13 @@ def test_c_callbacks():
4953
xi8 = 3
5054
assert f_i8_i8(xi8) == 4
5155

56+
assert f_str_i32("Hello World!") == 12
57+
assert f_str_i32("abc") == 3
58+
assert f_str_i32("a") == 1
59+
assert f_str_i32("") == 0
60+
x: str = "Hello World!"
61+
assert f_str_i32(x) == 12
62+
x = "abc"
63+
assert f_str_i32(x) == 3
64+
5265
test_c_callbacks()

integration_tests/test_c_interop_02b.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <string.h>
2+
13
#include "test_c_interop_02b.h"
24

35
double f_f64_f64(double x) {
@@ -23,3 +25,7 @@ int16_t f_i16_i16(int16_t x) {
2325
int8_t f_i8_i8(int8_t x) {
2426
return x+1;
2527
}
28+
29+
int32_t f_str_i32(char *x) {
30+
return strlen(x);
31+
}

integration_tests/test_c_interop_02b.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ int64_t f_i64_i64(int64_t x);
1010
int32_t f_i32_i32(int32_t x);
1111
int16_t f_i16_i16(int16_t x);
1212
int8_t f_i8_i8 (int8_t x);
13+
int32_t f_str_i32(char *x);
1314

1415

1516
#endif // TEST_C_INTEROP_02B

0 commit comments

Comments
 (0)