Skip to content

Commit b2af1e1

Browse files
committed
Fail fast if sympify fails
1 parent 313208d commit b2af1e1

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ext/symengine/symengine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#ifndef SYMENGINE_H_
22
#define SYMENGINE_H_
33

4-
#include "ruby.h"
4+
#include <ruby/ruby.h>
5+
#include <ruby/intern.h>
56

67
//variable name for a module starts with m
78
VALUE m_symengine;

ext/symengine/symengine_utils.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ void sympify(VALUE operand2, basic_struct *cbasic_operand2) {
6060
break;
6161

6262
case T_DATA:
63+
if (rb_obj_is_kind_of(operand2, c_basic)) {
64+
Data_Get_Struct(operand2, basic_struct, temp);
65+
basic_assign(cbasic_operand2, temp);
66+
break;
67+
}
6368
#ifdef HAVE_SYMENGINE_MPFR
6469
if (strcmp(rb_obj_classname(operand2), "BigDecimal") == 0) {
6570
c = RSTRING_PTR( rb_funcall(operand2, rb_intern("to_s"), 1, rb_str_new2("F")) );
6671
real_mpfr_set_str(cbasic_operand2, c, 200);
6772
break;
6873
}
6974
#endif //HAVE_SYMENGINE_MPFR
70-
71-
Data_Get_Struct(operand2, basic_struct, temp);
72-
basic_assign(cbasic_operand2, temp);
73-
break;
75+
default:
76+
rb_raise(rb_eTypeError, "%s can't be coerced into SymEngine::Basic", rb_obj_classname(operand2));
7477
}
7578
}
7679

0 commit comments

Comments
 (0)