@@ -18,12 +18,13 @@ VALUE cbasic_alloc(VALUE klass)
1818 return Data_Wrap_Struct (klass , NULL , cbasic_free_heap , struct_ptr );
1919}
2020
21- VALUE cbasic_binary_op (VALUE self , VALUE operand2 ,
22- void (* cwfunc_ptr )(basic_struct * , const basic_struct * ,
23- const basic_struct * ))
21+ VALUE cbasic_binary_op (
22+ VALUE self , VALUE operand2 ,
23+ symengine_exceptions_t (* cwfunc_ptr )(basic_struct * , const basic_struct * ,
24+ const basic_struct * ))
2425{
2526 basic_struct * this , * cresult ;
26- VALUE result ;
27+ VALUE result = Qnil ;
2728
2829 basic cbasic_operand2 ;
2930 basic_new_stack (cbasic_operand2 );
@@ -32,27 +33,37 @@ VALUE cbasic_binary_op(VALUE self, VALUE operand2,
3233 sympify (operand2 , cbasic_operand2 );
3334
3435 cresult = basic_new_heap ();
35- cwfunc_ptr (cresult , this , cbasic_operand2 );
36- result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap ,
37- cresult );
38- basic_free_stack (cbasic_operand2 );
3936
37+ symengine_exceptions_t error_code
38+ = cwfunc_ptr (cresult , this , cbasic_operand2 );
39+ if (error_code == SYMENGINE_NO_EXCEPTION ) {
40+ result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL ,
41+ cbasic_free_heap , cresult );
42+ basic_free_stack (cbasic_operand2 );
43+ } else {
44+ basic_free_stack (cbasic_operand2 );
45+ raise_exception (error_code );
46+ }
4047 return result ;
4148}
4249
43- VALUE cbasic_unary_op (VALUE self ,
44- void ( * cwfunc_ptr )( basic_struct * , const basic_struct * ))
50+ VALUE cbasic_unary_op (VALUE self , symengine_exceptions_t ( * cwfunc_ptr )(
51+ basic_struct * , const basic_struct * ))
4552{
4653 basic_struct * this , * cresult ;
47- VALUE result ;
54+ VALUE result = Qnil ;
4855
4956 Data_Get_Struct (self , basic_struct , this );
5057
5158 cresult = basic_new_heap ();
52- cwfunc_ptr (cresult , this );
53- result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL , cbasic_free_heap ,
54- cresult );
5559
60+ symengine_exceptions_t error_code = cwfunc_ptr (cresult , this );
61+ if (error_code == SYMENGINE_NO_EXCEPTION ) {
62+ result = Data_Wrap_Struct (Klass_of_Basic (cresult ), NULL ,
63+ cbasic_free_heap , cresult );
64+ } else {
65+ raise_exception (error_code );
66+ }
5667 return result ;
5768}
5869
@@ -93,8 +104,8 @@ VALUE cbasic_diff(VALUE self, VALUE operand2)
93104 sympify (operand2 , cbasic_operand2 );
94105
95106 cresult = basic_new_heap ();
96- int status = basic_diff (cresult , this , cbasic_operand2 );
97- if (status == 0 ) {
107+ symengine_exceptions_t status = basic_diff (cresult , this , cbasic_operand2 );
108+ if (status == SYMENGINE_RUNTIME_ERROR ) {
98109 basic_free_stack (cbasic_operand2 );
99110 basic_free_heap (cresult );
100111 return Qnil ;
0 commit comments