@@ -106,8 +106,27 @@ static void __exec_closure(ffi_cif *cif, void *ret, void **args, void *user_data
106106 MCTypeInfoRef t_signature;
107107 t_signature = t_handler -> typeinfo;
108108
109+ // Check the arity of the handler - at the moment we can only handle 16
110+ // arguments.
109111 uindex_t t_arity;
110112 t_arity = MCHandlerTypeInfoGetParameterCount (t_signature);
113+ if (t_arity > 16 )
114+ {
115+ MCErrorThrowUnimplemented (MCSTR (" closures only supported for handlers with at most 16 parameters" ));
116+ return ;
117+ }
118+
119+
120+ // Check that we can resolve the return type.
121+ MCTypeInfoRef t_return_type;
122+ t_return_type = MCHandlerTypeInfoGetReturnType (t_signature);
123+
124+ MCResolvedTypeInfo t_resolved_return_type;
125+ if (!MCTypeInfoResolve (t_return_type, t_resolved_return_type))
126+ {
127+ MCErrorThrowUnboundType (t_return_type);
128+ return ;
129+ }
111130
112131 MCValueRef t_value_result;
113132 MCValueRef t_value_args[16 ];
@@ -123,12 +142,15 @@ static void __exec_closure(ffi_cif *cif, void *ret, void **args, void *user_data
123142 t_type = MCHandlerTypeInfoGetParameterType (t_signature, t_arg_index);
124143
125144 if (t_mode != kMCHandlerTypeFieldModeIn )
126- abort ();
145+ {
146+ MCErrorThrowUnimplemented (MCSTR (" closures only support in arguments" ));
147+ goto error_exit;
148+ }
127149
128150 MCResolvedTypeInfo t_resolved_type;
129151 if (!MCTypeInfoResolve (t_type, t_resolved_type))
130152 {
131- MCErrorThrowGeneric (nil );
153+ MCErrorThrowUnboundType (t_type );
132154 goto error_exit;
133155 }
134156
@@ -162,17 +184,6 @@ static void __exec_closure(ffi_cif *cif, void *ret, void **args, void *user_data
162184 if (!MCHandlerInvoke (t_handler, t_value_args, t_arity, t_value_result))
163185 goto error_exit;
164186
165- MCTypeInfoRef t_return_type;
166- t_return_type = MCHandlerTypeInfoGetReturnType (t_signature);
167-
168- MCResolvedTypeInfo t_resolved_return_type;
169- t_return_type = MCHandlerTypeInfoGetReturnType (t_signature);
170- if (!MCTypeInfoResolve (t_return_type, t_resolved_return_type))
171- {
172- MCErrorThrowGeneric (nil);
173- goto error_exit;
174- }
175-
176187 if (t_resolved_return_type . named_type != kMCNullTypeInfo )
177188 {
178189 if (MCTypeInfoIsForeign (t_resolved_return_type . type))
@@ -189,8 +200,6 @@ static void __exec_closure(ffi_cif *cif, void *ret, void **args, void *user_data
189200 }
190201 }
191202
192- return ;
193-
194203error_exit:
195204 if (t_value_result != nil)
196205 MCValueRelease (t_value_result);
@@ -218,7 +227,7 @@ bool MCHandlerGetFunctionPtr(MCHandlerRef self, void*& r_function_ptr)
218227 {
219228 ffi_closure_free (self -> closure);
220229 self -> closure = nil;
221- return MCErrorThrowGeneric (nil );
230+ return MCErrorThrowGeneric (MCSTR ( " unexpected libffi failure " ) );
222231 }
223232
224233 r_function_ptr = self -> function_ptr;
0 commit comments