Debian Codegraph @

ffi/record_meta.c

raw
1 #include <ffi_platypus.h>
2
3 #ifdef _MSC_VER
4 #define EXPORT __declspec(dllexport)
5 #else
6 #define EXPORT
7 #endif
8
9 /*
10 * Question: this is the documented way of creating a struct type.
11 * we already compute the size and alignment for the Perl interface
12 * to the members, can we use that instead?
13 */
14
15 EXPORT
16 ffi_pl_record_meta_t *
17 ffi_platypus_record_meta__new(ffi_type *list[], int safe_to_return_from_closure)
18 {
19 int size, i;
20 ffi_pl_record_meta_t *t;
21
22 for(size=0; list[size] != NULL; size++)
23 ;
24
25 t = malloc(sizeof(ffi_pl_record_meta_t) + sizeof(ffi_type*)*(size+1) );
26 if(t == NULL)
27 return NULL;
28
29 t->ffi_type.size = 0;
30 t->ffi_type.alignment = 0;
31 t->ffi_type.type = FFI_TYPE_STRUCT;
32 t->ffi_type.elements = (ffi_type**) &t->elements;
33
34 t->can_return_from_closure = safe_to_return_from_closure;
35
36
37 for(i=0; i<size+1; i++)
38 {
39 t->elements[i] = list[i];
40 }
41
42 return t;
43 }
44
45 EXPORT
46 ffi_type *
47 ffi_platypus_record_meta__ffi_type(ffi_pl_record_meta_t *t)
48 {
49 return &t->ffi_type;
50 }
51
52 EXPORT
53 size_t
54 ffi_platypus_record_meta__size(ffi_pl_record_meta_t *t)
55 {
56 return t->ffi_type.size;
57 }
58
59 EXPORT
60 unsigned short
61 ffi_platypus_record_meta__alignment(ffi_pl_record_meta_t *t)
62 {
63 return t->ffi_type.alignment;
64 }
65
66 EXPORT
67 ffi_type **
68 ffi_platypus_record_meta__element_pointers(ffi_pl_record_meta_t *t)
69 {
70 return t->ffi_type.elements;
71 }
72
73 EXPORT
74 void
75 ffi_platypus_record_meta__DESTROY(ffi_pl_record_meta_t *t)
76 {
77 free(t);
78 }
79
80 EXPORT
81 ffi_type *
82 ffi_platypus_record_meta___find_symbol(const char *name)
83 {
84 if(!strcmp(name, "sint8"))
85 return &ffi_type_sint8;
86 else if(!strcmp(name, "sint16"))
87 return &ffi_type_sint16;
88 else if(!strcmp(name, "sint32"))
89 return &ffi_type_sint32;
90 else if(!strcmp(name, "sint64"))
91 return &ffi_type_sint64;
92 else if(!strcmp(name, "uint8"))
93 return &ffi_type_uint8;
94 else if(!strcmp(name, "uint16"))
95 return &ffi_type_uint16;
96 else if(!strcmp(name, "uint32"))
97 return &ffi_type_uint32;
98 else if(!strcmp(name, "uint64"))
99 return &ffi_type_uint64;
100 else if(!strcmp(name, "pointer"))
101 return &ffi_type_pointer;
102 else if(!strcmp(name, "float"))
103 return &ffi_type_float;
104 else if(!strcmp(name, "double"))
105 return &ffi_type_double;
106 /* TODO: longdouble, complex_float, complex_duble, complex_longdouble */
107 else
108 return NULL;
109 }