forked from rdicosmo/parmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytearray_stubs.c
73 lines (62 loc) · 2.09 KB
/
bytearray_stubs.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* bytearray_stubs.c : C routines for bytearray.ml */
/* Copyright Jérôme Vouillon 1999-2010 (see LICENCE for distribution conditions) */
#include <string.h>
#include "caml/intext.h"
#include "caml/bigarray.h"
#define Array_data(a, i) (((char *) a->data) + Long_val(i))
#define Floatarray_data(a, i) (((char *) a->data) + 8 * Long_val(i))
CAMLprim value ml_marshal_to_bigarray(value v, value flags)
{
char *buf;
long len;
output_value_to_malloc(v, flags, &buf, &len);
return alloc_bigarray(BIGARRAY_UINT8 | BIGARRAY_C_LAYOUT | BIGARRAY_MANAGED,
1, buf, &len);
}
CAMLprim value ml_marshal_to_bigarray_buffer(value b, value ofs,
value v, value flags)
{
struct caml_bigarray *b_arr = Bigarray_val(b);
return Val_long(caml_output_value_to_block(v, flags, Array_data (b_arr, ofs),
b_arr->dim[0] - Long_val(ofs)));
}
CAMLprim value ml_unmarshal_from_bigarray(value b, value ofs)
{
struct caml_bigarray *b_arr = Bigarray_val(b);
return input_value_from_block (Array_data (b_arr, ofs),
b_arr->dim[0] - Long_val(ofs));
}
CAMLprim value ml_blit_string_to_bigarray
(value s, value i, value a, value j, value l)
{
char *src = String_val(s) + Int_val(i);
char *dest = Array_data(Bigarray_val(a), j);
memcpy(dest, src, Long_val(l));
return Val_unit;
}
CAMLprim value ml_blit_bigarray_to_string
(value a, value i, value s, value j, value l)
{
char *src = Array_data(Bigarray_val(a), i);
char *dest = String_val(s) + Long_val(j);
memcpy(dest, src, Long_val(l));
return Val_unit;
}
CAMLprim value ml_blit_floatarray_to_bigarray
(value fa, value i, value a, value j, value l)
{
int w = 8;
char *src = Bp_val(fa) + Long_val(i)*w;
char *dest = Floatarray_data(Bigarray_val(a), j);
memcpy(dest, src, Long_val(l)*w);
return Val_unit;
}
CAMLprim value ml_blit_bigarray_to_floatarray
(value a, value i, value fa, value j, value l)
{
int w = 8;
char *src = Floatarray_data(Bigarray_val(a), i);
char *dest = Bp_val(fa) + Long_val(j)*w;
memcpy(dest, src, Long_val(l)*w);
return Val_unit;
}