annotate Python/hypot.c @ 43840:73c8e27eb9ce

Correction for issue1265 (pdb bug with "with" statement). When an unfinished generator-iterator is garbage collected, PyEval_EvalFrameEx is called with a GeneratorExit exception set. This leads to funny results if the sys.settrace function itself makes use of generators. A visible effect is that the settrace function is reset to None. Another is that the eventual "finally" block of the generator is not called. It is necessary to save/restore the exception around the call to the trace function. This happens a lot with py3k: isinstance() of an ABCMeta instance runs def __instancecheck__(cls, instance): """Override for isinstance(instance, cls).""" return any(cls.__subclasscheck__(c) for c in {instance.__class__, type(instance)}) which lets an opened generator expression each time it returns True. Seems a backport candidate, even if the case is less frequent in 2.5.
author Amaury Forgeot d'Arc <amauryfa@gmail.com>
date Tue, 13 Nov 2007 01:05:30 +0000
parents 7bc4cc972b0b
children ef859cd754a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4176
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* hypot() replacement */
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
43829
7bc4cc972b0b Merged revisions 58939-58946 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 18835
diff changeset
3 #include "Python.h"
4176
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 4176
diff changeset
5 double hypot(double x, double y)
4176
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 {
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 double yx;
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 x = fabs(x);
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 y = fabs(y);
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 if (x < y) {
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 double temp = x;
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 x = y;
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 y = temp;
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 }
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 if (x == 0.)
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 return 0.;
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 else {
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 yx = y/x;
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 return x*sqrt(1.+yx*yx);
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 }
37d009b1bf45 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 }