Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 738d4dd

Browse files
committed
Take out duplication of code in initmodule().
1 parent ed97f6a commit 738d4dd

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

Modules/mathmodule.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,9 @@ void
150150
initmath()
151151
{
152152
object *m, *d, *v;
153-
struct methodlist *ml;
154-
if ((m = new_module("math")) == NULL)
155-
fatal("can't create math module");
153+
154+
m = initmodule("math", math_methods);
156155
d = getmoduledict(m);
157-
for (ml = math_methods; ml->ml_name != NULL; ml++) {
158-
v = newmethodobject(ml->ml_name, ml->ml_meth, (object *)NULL);
159-
if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
160-
fatal("can't initialize math module");
161-
}
162-
DECREF(v);
163-
}
164156
dictinsert(d, "pi", newfloatobject(atan(1.0) * 4.0));
165157
dictinsert(d, "e", newfloatobject(exp(1.0)));
166-
DECREF(m);
167158
}

0 commit comments

Comments
 (0)