88 |
/* |
/* |
89 |
* Forward declarations. |
* Forward declarations. |
90 |
*/ |
*/ |
91 |
static ffi_type *TypeToFFI(ILType *type, int isInternal); |
static ffi_type *TypeToFFI(ILExecProcess *process, ILType *type, int isInternal); |
92 |
|
|
93 |
#ifdef IL_CONFIG_PINVOKE |
#ifdef IL_CONFIG_PINVOKE |
94 |
|
|
95 |
static ffi_type *StructToFFI(ILClass *classInfo); |
static ffi_type *StructToFFI(ILExecProcess *process, ILClass *classInfo); |
96 |
|
|
97 |
#if !FFI_NO_STRUCTS |
#if !FFI_NO_STRUCTS |
98 |
|
|
101 |
* about the non-static fields of a class. Returns zero if |
* about the non-static fields of a class. Returns zero if |
102 |
* out of memory. |
* out of memory. |
103 |
*/ |
*/ |
104 |
static int PopulateStructFFI(ILClass *classInfo, ffi_type **fieldTypes, |
static int PopulateStructFFI(ILExecProcess *process, ILClass *classInfo, |
105 |
unsigned *posn) |
ffi_type **fieldTypes, unsigned *posn) |
106 |
{ |
{ |
107 |
ILClass *parent; |
ILClass *parent; |
108 |
ILField *field; |
ILField *field; |
113 |
parent = ILClassGetParent(classInfo); |
parent = ILClassGetParent(classInfo); |
114 |
if(parent) |
if(parent) |
115 |
{ |
{ |
116 |
if(!PopulateStructFFI(parent, fieldTypes, posn)) |
if(!PopulateStructFFI(process, parent, fieldTypes, posn)) |
117 |
{ |
{ |
118 |
return 0; |
return 0; |
119 |
} |
} |
130 |
if(ILType_IsValueType(type)) |
if(ILType_IsValueType(type)) |
131 |
{ |
{ |
132 |
/* Process an embedded structure type */ |
/* Process an embedded structure type */ |
133 |
ffi = StructToFFI(ILType_ToValueType(type)); |
ffi = StructToFFI(process, ILType_ToValueType(type)); |
134 |
if(!ffi) |
if(!ffi) |
135 |
{ |
{ |
136 |
return 0; |
return 0; |
139 |
else |
else |
140 |
{ |
{ |
141 |
/* Process a non-structure type */ |
/* Process a non-structure type */ |
142 |
ffi = TypeToFFI(type, 0); |
ffi = TypeToFFI(process, type, 0); |
143 |
} |
} |
144 |
fieldTypes[(*posn)++] = ffi; |
fieldTypes[(*posn)++] = ffi; |
145 |
} |
} |
155 |
* Convert a "struct" class into a "ffi" type descriptor. |
* Convert a "struct" class into a "ffi" type descriptor. |
156 |
* Returns zero if out of memory. |
* Returns zero if out of memory. |
157 |
*/ |
*/ |
158 |
static ffi_type *StructToFFI(ILClass *classInfo) |
static ffi_type *StructToFFI(ILExecProcess *process, ILClass *classInfo) |
159 |
{ |
{ |
160 |
#if !FFI_NO_STRUCTS |
#if !FFI_NO_STRUCTS |
161 |
ILClass *current; |
ILClass *current; |
190 |
else |
else |
191 |
{ |
{ |
192 |
/* Use the explicit layout information from "layout.c" */ |
/* Use the explicit layout information from "layout.c" */ |
193 |
explicitSize = _ILLayoutClassReturn(classInfo, &explicitAlignment); |
explicitSize = _ILLayoutClassReturn(process, classInfo, &explicitAlignment); |
194 |
} |
} |
195 |
|
|
196 |
/* Allocate space for the struct's type descriptor */ |
/* Allocate space for the struct's type descriptor */ |
213 |
if(!ILClass_IsExplicitLayout(classInfo)) |
if(!ILClass_IsExplicitLayout(classInfo)) |
214 |
{ |
{ |
215 |
numFields = 0; |
numFields = 0; |
216 |
if(!PopulateStructFFI(classInfo, fieldTypes, &numFields)) |
if(!PopulateStructFFI(process, classInfo, fieldTypes, &numFields)) |
217 |
{ |
{ |
218 |
ILFree(descr); |
ILFree(descr); |
219 |
return 0; |
return 0; |
239 |
/* |
/* |
240 |
* Convert an IL type into an "ffi" type descriptor. |
* Convert an IL type into an "ffi" type descriptor. |
241 |
*/ |
*/ |
242 |
static ffi_type *TypeToFFI(ILType *type, int isInternal) |
static ffi_type *TypeToFFI(ILExecProcess *process, ILType *type, int isInternal) |
243 |
{ |
{ |
244 |
if(ILType_IsPrimitive(type)) |
if(ILType_IsPrimitive(type)) |
245 |
{ |
{ |
279 |
else if(!isInternal && ILType_IsValueType(type)) |
else if(!isInternal && ILType_IsValueType(type)) |
280 |
{ |
{ |
281 |
/* Structure that is passed by value to a PInvoke method */ |
/* Structure that is passed by value to a PInvoke method */ |
282 |
ffi_type *ffi = StructToFFI(ILClassResolve(ILType_ToValueType(type))); |
ffi_type *ffi = StructToFFI(process, ILClassResolve(ILType_ToValueType(type))); |
283 |
return (ffi ? ffi : &ffi_type_pointer); |
return (ffi ? ffi : &ffi_type_pointer); |
284 |
} |
} |
285 |
#endif |
#endif |
290 |
} |
} |
291 |
} |
} |
292 |
|
|
293 |
void *_ILMakeCifForMethod(ILMethod *method, int isInternal) |
void *_ILMakeCifForMethod(ILExecProcess *process, ILMethod *method, int isInternal) |
294 |
{ |
{ |
295 |
ILType *signature = ILMethod_Signature(method); |
ILType *signature = ILMethod_Signature(method); |
296 |
ILType *returnType = ILTypeGetEnumType(ILTypeGetReturn(signature)); |
ILType *returnType = ILTypeGetEnumType(ILTypeGetReturn(signature)); |
333 |
args = ((ffi_type **)(cif + 1)); |
args = ((ffi_type **)(cif + 1)); |
334 |
|
|
335 |
/* Convert the return type */ |
/* Convert the return type */ |
336 |
rtype = TypeToFFI(modReturnType, isInternal); |
rtype = TypeToFFI(process, modReturnType, isInternal); |
337 |
|
|
338 |
/* Convert the argument types */ |
/* Convert the argument types */ |
339 |
arg = 0; |
arg = 0; |
354 |
} |
} |
355 |
for(param = 1; param <= numParams; ++param) |
for(param = 1; param <= numParams; ++param) |
356 |
{ |
{ |
357 |
args[arg++] = TypeToFFI(ILTypeGetEnumType |
args[arg++] = TypeToFFI(process, ILTypeGetEnumType |
358 |
(ILTypeGetParam(signature, param)), |
(ILTypeGetParam(signature, param)), |
359 |
isInternal); |
isInternal); |
360 |
} |
} |
378 |
return (void *)cif; |
return (void *)cif; |
379 |
} |
} |
380 |
|
|
381 |
void *_ILMakeCifForConstructor(ILMethod *method, int isInternal) |
void *_ILMakeCifForConstructor(ILExecProcess *process, ILMethod *method, int isInternal) |
382 |
{ |
{ |
383 |
ILType *signature = ILMethod_Signature(method); |
ILType *signature = ILMethod_Signature(method); |
384 |
ILUInt32 numArgs; |
ILUInt32 numArgs; |
420 |
} |
} |
421 |
for(param = 1; param <= numParams; ++param) |
for(param = 1; param <= numParams; ++param) |
422 |
{ |
{ |
423 |
args[arg++] = TypeToFFI(ILTypeGetEnumType |
args[arg++] = TypeToFFI(process, ILTypeGetEnumType |
424 |
(ILTypeGetParam(signature, param)), |
(ILTypeGetParam(signature, param)), |
425 |
isInternal); |
isInternal); |
426 |
} |
} |
1032 |
|
|
1033 |
#endif /* FFI_CLOSURES */ |
#endif /* FFI_CLOSURES */ |
1034 |
|
|
1035 |
void *_ILMakeClosureForDelegate(ILObject *delegate, ILMethod *method) |
void *_ILMakeClosureForDelegate(ILExecProcess *process, ILObject *delegate, ILMethod *method) |
1036 |
{ |
{ |
1037 |
#if FFI_CLOSURES |
#if FFI_CLOSURES |
1038 |
ILType *signature = ILMethod_Signature(method); |
ILType *signature = ILMethod_Signature(method); |
1058 |
args = ((ffi_type **)(cif + 1)); |
args = ((ffi_type **)(cif + 1)); |
1059 |
|
|
1060 |
/* Convert the return type */ |
/* Convert the return type */ |
1061 |
rtype = TypeToFFI(returnType, 0); |
rtype = TypeToFFI(process, returnType, 0); |
1062 |
|
|
1063 |
/* Convert the argument types */ |
/* Convert the argument types */ |
1064 |
arg = 0; |
arg = 0; |
1069 |
} |
} |
1070 |
for(param = 1; param <= numArgs; ++param) |
for(param = 1; param <= numArgs; ++param) |
1071 |
{ |
{ |
1072 |
args[arg++] = TypeToFFI(ILTypeGetEnumType |
args[arg++] = TypeToFFI(process, ILTypeGetEnumType |
1073 |
(ILTypeGetParam(signature, param)), 0); |
(ILTypeGetParam(signature, param)), 0); |
1074 |
} |
} |
1075 |
|
|