Skip to content

Commit 88b302f

Browse files
committed
Exposed sympify to Ruby
1 parent 316a9c1 commit 88b302f

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

ext/symengine/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(RUBY_WRAPPER_SRC
77
ruby_constant.c
88
ruby_function.c
99
ruby_ntheory.c
10+
ruby_utils.c
1011
symengine_utils.c
1112
symengine.c
1213
)

ext/symengine/ruby_complex.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
VALUE ccomplex_init(VALUE self, VALUE comp_value) {
44
basic_struct *this;
5-
basic real_basic, imag_basic;
6-
7-
basic_new_stack(real_basic);
8-
basic_new_stack(imag_basic);
5+
basic_struct *real_basic = basic_new_heap();
6+
basic_struct *imag_basic = basic_new_heap();
97

108
Data_Get_Struct(self, basic_struct, this);
119

@@ -17,7 +15,9 @@ VALUE ccomplex_init(VALUE self, VALUE comp_value) {
1715
crational_init(imag_basic, imag);
1816

1917
complex_set(this, real_basic, imag_basic);
20-
basic_free_stack(real_basic);
21-
basic_free_stack(imag_basic);
18+
19+
basic_free_heap(real_basic);
20+
basic_free_heap(imag_basic);
21+
2222
return self;
2323
}

ext/symengine/ruby_utils.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "ruby_utils.h"
2+
3+
VALUE cutils_sympify(VALUE self, VALUE operand) {
4+
5+
VALUE result;
6+
basic cbasic_operand;
7+
basic_new_stack(cbasic_operand);
8+
9+
sympify(operand, cbasic_operand);
10+
result = Data_Wrap_Struct(Klass_of_Basic(cbasic_operand), NULL , cbasic_free_heap, cbasic_operand);
11+
12+
return operand;
13+
14+
}
15+

ext/symengine/ruby_utils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef RUBY_UTILS_H_
2+
#define RUBY_UTILS_H_
3+
4+
#include "symengine_utils.h"
5+
6+
//Returns the Ruby Value after going through sympify
7+
VALUE cutils_sympify(VALUE self, VALUE operand);
8+
9+
#endif //RUBY_UTILS_H_

ext/symengine/symengine.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "ruby_constant.h"
88
#include "ruby_function.h"
99
#include "ruby_ntheory.h"
10+
#include "ruby_utils.h"
11+
#include "symengine_utils.h"
1012
#include "symengine.h"
1113

1214
///////////////////
@@ -45,6 +47,9 @@ void Init_symengine() {
4547
rb_define_method(c_basic, "subs", cbasic_subs, -1);
4648
rb_define_method(c_basic, "coerce", cbasic_coerce, 1);
4749

50+
//Sympify as a Module Level Function
51+
rb_define_module_function(m_symengine, "sympify", cutils_sympify, 1);
52+
4853
//Symbol class
4954
c_symbol = rb_define_class_under(m_symengine, "Symbol", c_basic);
5055
rb_define_alloc_func(c_symbol, cbasic_alloc);

ext/symengine/symengine_utils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "symengine.h"
33

44
void sympify(VALUE operand2, basic_struct *cbasic_operand2) {
5+
56
basic_struct *temp;
67
VALUE new_operand2, num, den;
78

0 commit comments

Comments
 (0)