Last active
October 7, 2018 15:30
-
-
Save dpwright/4615860 to your computer and use it in GitHub Desktop.
Demonstrates filling in a u32vector from an FFI function returning a pointer in Chicken Scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(4 9 15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const int TEST_SIZE = 3; | |
static unsigned int testArray[TEST_SIZE] = {4, 9, 15}; | |
static unsigned int* testFunc() | |
{ | |
return testArray; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use srfi-4) | |
(foreign-declare "#include \\"test.h\\"") | |
(define test-size 3) | |
(define c-test-func | |
(foreign-lambda* int ((nonnull-u32vector vector_out)) | |
"unsigned int* array_from_func = testFunc(); | |
memcpy(vector_out, array_from_func, TEST_SIZE * sizeof(unsigned int)); | |
C_return(TEST_SIZE);")) | |
(define (test-func) | |
(let* ((buffer (make-u32vector test-size))) | |
(c-test-func buffer) | |
(u32vector->list buffer))) | |
(write (test-func)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment