Skip to content

Commit 94614ce

Browse files
committed
Restructuring macros->utils
1 parent d57e5f5 commit 94614ce

File tree

9 files changed

+54
-69
lines changed

9 files changed

+54
-69
lines changed

ext/symengine/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(RUBY_WRAPPER_SRC
66
ruby_constant.c
77
ruby_function.c
88
ruby_ntheory.c
9-
symengine_macros.c
9+
symengine_utils.c
1010
symengine.c
1111
)
1212

ext/symengine/ruby_basic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <ruby.h>
55
#include <symengine/cwrapper.h>
66

7-
#include "symengine_macros.h"
7+
#include "symengine_utils.h"
88

99
void cbasic_free(void *ptr);
1010

ext/symengine/ruby_constant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#include <ruby.h>
55
#include <symengine/cwrapper.h>
66

7-
#include "ruby_basic.h"
87
#include "symengine.h"
9-
#include "symengine_macros.h"
8+
#include "symengine_utils.h"
109

1110
VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct*));
1211

ext/symengine/ruby_function.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
#include "ruby_function.h"
22

3-
4-
VALUE cfunction_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1) {
5-
basic_struct *cresult;
6-
VALUE result;
7-
8-
basic cbasic_operand1;
9-
basic_new_stack(cbasic_operand1);
10-
sympify(operand1, cbasic_operand1);
11-
12-
cresult = basic_new_heap();
13-
cwfunc_ptr(cresult, cbasic_operand1);
14-
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
15-
basic_free_stack(cbasic_operand1);
16-
17-
return result;
18-
}
19-
203
#define IMPLEMENT_ONE_ARG_FUNC(func) \
214
VALUE cfunction_ ## func(VALUE self, VALUE operand1) { \
22-
return cfunction_onearg(basic_ ## func, operand1); \
5+
return function_onearg(basic_ ## func, operand1); \
236
}
247

258
IMPLEMENT_ONE_ARG_FUNC(abs);

ext/symengine/ruby_function.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#include <ruby.h>
55
#include <symengine/cwrapper.h>
66

7-
#include "ruby_basic.h"
87
#include "symengine.h"
9-
#include "symengine_macros.h"
8+
#include "symengine_utils.h"
109

1110
VALUE cfunction_func(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1);
1211

ext/symengine/ruby_ntheory.c

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,23 @@
11
#include "ruby_ntheory.h"
22

3-
VALUE cntheory_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1) {
4-
basic_struct *cresult;
5-
VALUE result;
6-
7-
basic cbasic_operand1;
8-
basic_new_stack(cbasic_operand1);
9-
sympify(operand1, cbasic_operand1);
10-
11-
cresult = basic_new_heap();
12-
cwfunc_ptr(cresult, cbasic_operand1);
13-
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
14-
basic_free_stack(cbasic_operand1);
15-
16-
return result;
17-
}
18-
19-
VALUE cntheory_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), VALUE operand1, VALUE operand2) {
20-
basic_struct *cresult;
21-
VALUE result;
22-
23-
basic cbasic_operand1;
24-
basic_new_stack(cbasic_operand1);
25-
sympify(operand1, cbasic_operand1);
26-
27-
basic cbasic_operand2;
28-
basic_new_stack(cbasic_operand2);
29-
sympify(operand2, cbasic_operand2);
30-
31-
cresult = basic_new_heap();
32-
cwfunc_ptr(cresult, cbasic_operand1, cbasic_operand2);
33-
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
34-
basic_free_stack(cbasic_operand1);
35-
basic_free_stack(cbasic_operand2);
36-
37-
return result;
38-
}
39-
403
VALUE cntheory_nextprime(VALUE self, VALUE operand1) {
41-
return cntheory_onearg(ntheory_nextprime, operand1);
4+
return function_onearg(ntheory_nextprime, operand1);
425
}
436

447
VALUE cntheory_gcd(VALUE self, VALUE operand1, VALUE operand2) {
45-
return cntheory_twoarg(ntheory_gcd, operand1, operand2);
8+
return function_twoarg(ntheory_gcd, operand1, operand2);
469
}
4710

4811
VALUE cntheory_lcm(VALUE self, VALUE operand1, VALUE operand2) {
49-
return cntheory_twoarg(ntheory_lcm, operand1, operand2);
12+
return function_twoarg(ntheory_lcm, operand1, operand2);
5013
}
5114

5215
VALUE cntheory_mod(VALUE self, VALUE operand1, VALUE operand2) {
53-
return cntheory_twoarg(ntheory_mod, operand1, operand2);
16+
return function_twoarg(ntheory_mod, operand1, operand2);
5417
}
5518

5619
VALUE cntheory_quotient(VALUE self, VALUE operand1, VALUE operand2) {
57-
return cntheory_twoarg(ntheory_quotient, operand1, operand2);
20+
return function_twoarg(ntheory_quotient, operand1, operand2);
5821
}
5922

6023
VALUE cntheory_fibonacci(VALUE self, VALUE operand1){

ext/symengine/ruby_ntheory.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#include <ruby.h>
55
#include <symengine/cwrapper.h>
66

7-
#include "ruby_basic.h"
87
#include "symengine.h"
9-
#include "symengine_macros.h"
8+
#include "symengine_utils.h"
109

1110
VALUE cntheory_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1);
1211
VALUE cntheory_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), VALUE operand1, VALUE operand2);

ext/symengine/symengine_macros.c renamed to ext/symengine/symengine_utils.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "symengine_macros.h"
1+
#include "symengine_utils.h"
22
#include "symengine.h"
33

44
void sympify(VALUE operand2, basic_struct *cbasic_operand2) {
@@ -111,3 +111,40 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) {
111111
return c_basic;
112112
}
113113
}
114+
115+
VALUE function_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1) {
116+
basic_struct *cresult;
117+
VALUE result;
118+
119+
basic cbasic_operand1;
120+
basic_new_stack(cbasic_operand1);
121+
sympify(operand1, cbasic_operand1);
122+
123+
cresult = basic_new_heap();
124+
cwfunc_ptr(cresult, cbasic_operand1);
125+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
126+
basic_free_stack(cbasic_operand1);
127+
128+
return result;
129+
}
130+
131+
VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), VALUE operand1, VALUE operand2) {
132+
basic_struct *cresult;
133+
VALUE result;
134+
135+
basic cbasic_operand1;
136+
basic_new_stack(cbasic_operand1);
137+
sympify(operand1, cbasic_operand1);
138+
139+
basic cbasic_operand2;
140+
basic_new_stack(cbasic_operand2);
141+
sympify(operand2, cbasic_operand2);
142+
143+
cresult = basic_new_heap();
144+
cwfunc_ptr(cresult, cbasic_operand1, cbasic_operand2);
145+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
146+
basic_free_stack(cbasic_operand1);
147+
basic_free_stack(cbasic_operand2);
148+
149+
return result;
150+
}

ext/symengine/symengine_macros.h renamed to ext/symengine/symengine_utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
#define SYMENGINE_MACROS_H_
33

44
#include "ruby.h"
5+
#include "ruby_basic.h"
56
#include "symengine/cwrapper.h"
67

78
//Returns the pointer wrapped inside the Ruby VALUE
89
void sympify(VALUE operand2, basic_struct *cbasic_operand2);
910
//Returns the Ruby class of the corresponding basic_struct pointer
1011
VALUE Klass_of_Basic(const basic_struct *basic_ptr);
12+
//Returns the result from the function pointed by cwfunc_ptr: for one argument functions
13+
VALUE function_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1);
14+
//Returns the result from the function pointed by cwfunc_ptr: for two argument functions
15+
VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), VALUE operand1, VALUE operand2);
1116

1217
//Obtains the value from Ruby Fixnum or Bignum to an already allocated basic_struct
1318
#define GET_SYMINTFROMVAL(num_value, this) { \

0 commit comments

Comments
 (0)