Skip to content

Commit 4e64375

Browse files
committed
Changes to symengine_utils
1 parent acfd1f3 commit 4e64375

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

ext/symengine/symengine_utils.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,12 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr)
199199
}
200200
}
201201

202-
VALUE function_onearg(int (*cwfunc_ptr)(basic_struct *, const basic_struct *),
202+
VALUE function_onearg(CWRAPPER_OUTPUT_TYPE (*cwfunc_ptr)(basic_struct *,
203+
const basic_struct *),
203204
VALUE operand1)
204205
{
205206
basic_struct *cresult;
206-
VALUE result;
207+
VALUE result = Qnil;
207208

208209
basic cbasic_operand1;
209210
basic_new_stack(cbasic_operand1);
@@ -215,20 +216,20 @@ VALUE function_onearg(int (*cwfunc_ptr)(basic_struct *, const basic_struct *),
215216
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL,
216217
cbasic_free_heap, cresult);
217218
basic_free_stack(cbasic_operand1);
218-
219-
return result;
220219
} else {
221220
basic_free_stack(cbasic_operand1);
222-
rb_raise(rb_eRuntimeError, "Runtime Error");
221+
raise_exception(error_code);
223222
}
223+
return result;
224224
}
225225

226-
VALUE function_twoarg(int (*cwfunc_ptr)(basic_struct *, const basic_struct *,
227-
const basic_struct *),
226+
VALUE function_twoarg(CWRAPPER_OUTPUT_TYPE (*cwfunc_ptr)(basic_struct *,
227+
const basic_struct *,
228+
const basic_struct *),
228229
VALUE operand1, VALUE operand2)
229230
{
230231
basic_struct *cresult;
231-
VALUE result;
232+
VALUE result = Qnil;
232233

233234
basic cbasic_operand1;
234235
basic_new_stack(cbasic_operand1);
@@ -246,24 +247,35 @@ VALUE function_twoarg(int (*cwfunc_ptr)(basic_struct *, const basic_struct *,
246247
cbasic_free_heap, cresult);
247248
basic_free_stack(cbasic_operand1);
248249
basic_free_stack(cbasic_operand2);
249-
return result;
250250
} else {
251251
basic_free_stack(cbasic_operand1);
252252
basic_free_stack(cbasic_operand2);
253-
rb_raise(rb_eRuntimeError, "Runtime Error");
253+
raise_exception(error_code);
254254
}
255+
return result;
255256
}
256257

257-
void raise_exception(int error_code)
258+
void raise_exception(symengine_exceptions_t error_code)
258259
{
259260
char *str = "";
260261
switch (error_code) {
261-
case -1:
262+
case SYMENGINE_NO_EXCEPTION:
263+
return;
264+
case SYMENGINE_RUNTIME_ERROR:
262265
str = "Runtime Error";
263266
break;
264-
case 1:
267+
case SYMENGINE_DIV_BY_ZERO:
265268
str = "Division by Zero";
266269
break;
270+
case SYMENGINE_NOT_IMPLEMENTED:
271+
str = "Not Implemented";
272+
break;
273+
case SYMENGINE_UNDEFINED:
274+
str = "Undefined";
275+
break;
276+
case SYMENGINE_PARSE_ERROR:
277+
str = "Parse Error";
278+
break;
267279
}
268280
rb_raise(rb_eRuntimeError, "%s", str);
269281
}

ext/symengine/symengine_utils.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ void get_symintfromval(VALUE operand2, basic_struct *cbasic_operand2);
1717
VALUE Klass_of_Basic(const basic_struct *basic_ptr);
1818
// Returns the result from the function pointed by cwfunc_ptr: for one argument
1919
// functions
20-
VALUE function_onearg(int (*cwfunc_ptr)(basic_struct *, const basic_struct *),
20+
VALUE function_onearg(CWRAPPER_OUTPUT_TYPE (*cwfunc_ptr)(basic_struct *,
21+
const basic_struct *),
2122
VALUE operand1);
2223
// Returns the result from the function pointed by cwfunc_ptr: for two argument
2324
// functions
24-
VALUE function_twoarg(int (*cwfunc_ptr)(basic_struct *, const basic_struct *,
25-
const basic_struct *),
25+
VALUE function_twoarg(CWRAPPER_OUTPUT_TYPE (*cwfunc_ptr)(basic_struct *,
26+
const basic_struct *,
27+
const basic_struct *),
2628
VALUE operand1, VALUE operand2);
27-
void raise_exception(int error_code);
29+
void raise_exception(symengine_exceptions_t error_code);
2830

2931
#endif // SYMENGINE_UTILS_H_

0 commit comments

Comments
 (0)