@@ -199,7 +199,7 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr)
199199 }
200200}
201201
202- VALUE function_onearg (void (* cwfunc_ptr )(basic_struct * , const basic_struct * ),
202+ VALUE function_onearg (int (* cwfunc_ptr )(basic_struct * , const basic_struct * ),
203203 VALUE operand1 )
204204{
205205 basic_struct * cresult ;
@@ -210,16 +210,21 @@ VALUE function_onearg(void (*cwfunc_ptr)(basic_struct *, const basic_struct *),
210210 sympify (operand1 , cbasic_operand1 );
211211
212212 cresult = basic_new_heap ();
213- cwfunc_ptr (cresult , cbasic_operand1 );
214- result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap ,
215- cresult );
216- basic_free_stack (cbasic_operand1 );
213+ int error_code = cwfunc_ptr (cresult , cbasic_operand1 );
214+ if (error_code == 0 ) {
215+ result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL ,
216+ cbasic_free_heap , cresult );
217+ basic_free_stack (cbasic_operand1 );
217218
218- return result ;
219+ return result ;
220+ } else {
221+ basic_free_stack (cbasic_operand1 );
222+ rb_raise (rb_eRuntimeError , "Runtime Error" );
223+ }
219224}
220225
221- VALUE function_twoarg (void (* cwfunc_ptr )(basic_struct * , const basic_struct * ,
222- const basic_struct * ),
226+ VALUE function_twoarg (int (* cwfunc_ptr )(basic_struct * , const basic_struct * ,
227+ const basic_struct * ),
223228 VALUE operand1 , VALUE operand2 )
224229{
225230 basic_struct * cresult ;
@@ -234,11 +239,17 @@ VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct *, const basic_struct *,
234239 sympify (operand2 , cbasic_operand2 );
235240
236241 cresult = basic_new_heap ();
237- cwfunc_ptr (cresult , cbasic_operand1 , cbasic_operand2 );
238- result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap ,
239- cresult );
240- basic_free_stack (cbasic_operand1 );
241- basic_free_stack (cbasic_operand2 );
242-
243- return result ;
242+ int error_code = cwfunc_ptr (cresult , cbasic_operand1 , cbasic_operand2 );
243+
244+ if (error_code == 0 ) {
245+ result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL ,
246+ cbasic_free_heap , cresult );
247+ basic_free_stack (cbasic_operand1 );
248+ basic_free_stack (cbasic_operand2 );
249+ return result ;
250+ } else {
251+ basic_free_stack (cbasic_operand1 );
252+ basic_free_stack (cbasic_operand2 );
253+ rb_raise (rb_eRuntimeError , "Runtime Error" );
254+ }
244255}
0 commit comments