Skip to content

Commit 153a31c

Browse files
committed
basic == unknown object return false now
1 parent b2af1e1 commit 153a31c

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

ext/symengine/ruby_basic.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ VALUE cbasic_diff(VALUE self, VALUE operand2) {
9090
}
9191

9292
VALUE cbasic_eq(VALUE self, VALUE operand2) {
93+
9394
basic_struct *this;
9495

9596
basic cbasic_operand2;
9697
basic_new_stack(cbasic_operand2);
9798
Data_Get_Struct(self, basic_struct, this);
98-
sympify(operand2, cbasic_operand2);
99+
100+
VALUE ret = check_sympify(operand2, cbasic_operand2);
101+
if (ret == Qfalse) return Qfalse;
99102

100103
VALUE ret_val = basic_eq(this, cbasic_operand2) ? Qtrue : Qfalse;
101104
basic_free_stack(cbasic_operand2);
@@ -109,7 +112,9 @@ VALUE cbasic_neq(VALUE self, VALUE operand2) {
109112
basic cbasic_operand2;
110113
basic_new_stack(cbasic_operand2);
111114
Data_Get_Struct(self, basic_struct, this);
112-
sympify(operand2, cbasic_operand2);
115+
116+
VALUE ret = check_sympify(operand2, cbasic_operand2);
117+
if (ret == Qfalse) return Qtrue;
113118

114119
VALUE ret_val = basic_neq(this, cbasic_operand2) ? Qtrue : Qfalse;
115120
basic_free_stack(cbasic_operand2);

ext/symengine/symengine_utils.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "symengine_utils.h"
22
#include "symengine.h"
33

4-
void sympify(VALUE operand2, basic_struct *cbasic_operand2) {
4+
VALUE check_sympify(VALUE operand2, basic_struct *cbasic_operand2) {
55

66
basic_struct *temp;
77
VALUE new_operand2;
88
VALUE a, b;
99
double f;
10-
char *c;
10+
const char *c;
1111

1212
switch(TYPE(operand2)) {
1313
case T_FIXNUM:
@@ -73,7 +73,15 @@ void sympify(VALUE operand2, basic_struct *cbasic_operand2) {
7373
}
7474
#endif //HAVE_SYMENGINE_MPFR
7575
default:
76-
rb_raise(rb_eTypeError, "%s can't be coerced into SymEngine::Basic", rb_obj_classname(operand2));
76+
return Qfalse;
77+
}
78+
return Qtrue;
79+
}
80+
81+
void sympify(VALUE operand2, basic_struct *cbasic_operand2) {
82+
VALUE ret = check_sympify(operand2, cbasic_operand2);
83+
if (ret == Qfalse) {
84+
rb_raise(rb_eTypeError, "%s can't be coerced into SymEngine::Basic", rb_obj_classname(operand2));
7785
}
7886
}
7987

ext/symengine/symengine_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
VALUE rb_cBigDecimal;
99

10-
//Returns the pointer wrapped inside the Ruby VALUE
10+
//Coerces operand2 into a SymEngine object
1111
void sympify(VALUE operand2, basic_struct *cbasic_operand2);
12+
//Coerces operand2 into a SymEngine object and returns whether successful
13+
VALUE check_sympify(VALUE operand2, basic_struct *cbasic_operand2);
1214
//Returns the pointer wrapped inside the Ruby Fixnum or Bignum
1315
void get_symintfromval(VALUE operand2, basic_struct *cbasic_operand2);
1416
//Returns the Ruby class of the corresponding basic_struct pointer

0 commit comments

Comments
 (0)