]> granicus.if.org Git - python/commitdiff
Include mymath.h instead of declaring prototypes for math functions.
authorGuido van Rossum <guido@python.org>
Thu, 8 Aug 1996 18:49:41 +0000 (18:49 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 8 Aug 1996 18:49:41 +0000 (18:49 +0000)
Fix leak and unchecked error in complex().

Python/bltinmodule.c

index 04b2b7d3511e872ad20095120e140b45b26c5012..ea3d30ddee313f1a3a54467b9eae1ed442b8eaaf 100644 (file)
@@ -33,6 +33,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "compile.h"
 #include "eval.h"
 
+#include "mymath.h"
+
 /* Forward */
 static object *filterstring PROTO((object *, object *));
 static object *filtertuple  PROTO((object *, object *));
@@ -284,7 +286,7 @@ builtin_complex(self, args)
        object *self;
        object *args;
 {
-       object *r, *i;
+       object *r, *i, *tmp;
        number_methods *nbr, *nbi;
        Py_complex cr, ci;
 
@@ -302,7 +304,11 @@ builtin_complex(self, args)
        if (is_complexobject(r))
                cr = ((complexobject*)r)->cval;
        else {
-               cr.real = getfloatvalue((*nbr->nb_float)(r));
+               tmp = (*nbr->nb_float)(r);
+               if (tmp == NULL)
+                       return NULL;
+               cr.real = getfloatvalue(tmp);
+               DECREF(tmp);
                cr.imag = 0.;
        }
        if (i == NULL) {
@@ -312,7 +318,11 @@ builtin_complex(self, args)
        else if (is_complexobject(i))
                ci = ((complexobject*)i)->cval;
        else {
-               ci.real = getfloatvalue((*nbi->nb_float)(i));
+               tmp = (*nbr->nb_float)(r);
+               if (tmp == NULL)
+                       return NULL;
+               ci.real = getfloatvalue(tmp);
+               DECREF(tmp);
                ci.imag = 0.;
        }
        cr.real -= ci.imag;
@@ -1354,8 +1364,6 @@ builtin_round(self, args)
        object *self;
        object *args;
 {
-       extern double floor PROTO((double));
-       extern double ceil PROTO((double));
        double x;
        double f;
        int ndigits = 0;