-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffi_extra.c
31 lines (26 loc) · 1.06 KB
/
ffi_extra.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
extern unsigned char* even_numbers_upto(const unsigned char *a, size_t * alen);
extern void free_char_array(char * ref, size_t len);
void ffieven_numbers_upto (unsigned char *c, long clen, unsigned char *a, long alen) {
printf("c fficreate_array: available CakeML buffer length %d\n", alen);
size_t len = alen;
unsigned char * res = even_numbers_upto(a, &len);
printf("c fficreate_array: used buffer length %d\n", len);
assert(len <= alen);
memcpy(a, res, len);
free_char_array(res, len);
}
extern unsigned char* even_numbers_upto_malloc_buf(const unsigned char *a, size_t * alen);
void ffieven_numbers_upto_malloc_buf (unsigned char *c, long clen, unsigned char *a, long alen) {
printf("c ffieven_numbers_upto: available CakeML buffer length %d\n", alen);
size_t len = alen;
unsigned char * res = even_numbers_upto_malloc_buf(a, &len);
printf("c ffieven_numbers_upto: used buffer length %d\n", len);
assert(len <= alen);
memcpy(a, res, len);
free(res);
}