annotate Python/fmod.c @ 22621:830c829a7eb2 legacy-trunk

Fix an issue that was reported in but unrelated to the main problem of SF bug 535905 (Evil Trashcan and GC interaction). The SETLOCAL() macro should not DECREF the local variable in-place and then store the new value; it should copy the old value to a temporary value, then store the new value, and then DECREF the temporary value. This is because it is possible that during the DECREF the frame is accessed by other code (e.g. a __del__ method or gc.collect()) and the variable would be pointing to already-freed memory. BUGFIX CANDIDATE!
author Guido van Rossum <guido@python.org>
date Thu, 28 Mar 2002 20:17:52 +0000
parents 2dea40e40d9d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Portable fmod(x, y) implementation for systems that don't have it */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
18835
2dea40e40d9d Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774.
Martin v. Löwis <martin@v.loewis.de>
parents: 14375
diff changeset
4 #include "pyconfig.h"
2434
5bc341c4071c for MPW __SC__
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
5
13761
59f8cedcf049 merge Include/my*.h into Include/pyport.h
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
6 #include "pyport.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #include <errno.h>
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 double
2434
5bc341c4071c for MPW __SC__
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
10 fmod(double x, double y)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 double i, f;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 if (y == 0.0) {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 errno = EDOM;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 return 0.0;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 /* return f such that x = i*y + f for some integer i
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 such that |f| < |y| and f has the same sign as x */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 i = floor(x/y);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 f = x - i*y;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 if ((x < 0.0) != (y < 0.0))
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 f = f-y;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 return f;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 }