annotate Python/memmove.c @ 33940:dfd07b7be407 legacy-trunk

SF bug 1061968: threads: segfault or Py_FatalError at exit PyGILState_Ensure(): The fix in 2.4a3 for bug 1010677 reintroduced thread shutdown race bug 225673. Repaired by (once again) ensuring the GIL is held whenever deleting a thread state. Alas, there's no useful test case for this shy bug. Four years ago, only Guido could provoke it, on his box, and today only Armin can provoke it on his box. I've never been able to provoke it (but not for lack of trying!). This is a critical fix for 2.3.5 too, since the fix for 1010677 got backported there already and so also reintroduced 225673. I don't intend to backport this fix. For whoever (if anyone) does, there are other thread fixes in 2.4 that need backporting too, and I bet they need to happen first for this patch to apply cleanly.
author Tim Peters <tim.peters@gmail.com>
date Mon, 08 Nov 2004 04:30:21 +0000
parents 6f6f965c5e2d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1449
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* A perhaps slow but I hope correct implementation of memmove */
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
4 extern char *memcpy(char *, char *, int);
1449
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 char *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
7 memmove(char *dst, char *src, int n)
1449
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 {
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 char *realdst = dst;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 if (n <= 0)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 return dst;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 if (src >= dst+n || dst >= src+n)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 return memcpy(dst, src, n);
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 if (src > dst) {
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 while (--n >= 0)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 *dst++ = *src++;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 }
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 else if (src < dst) {
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 src += n;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 dst += n;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 while (--n >= 0)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 *--dst = *--src;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 }
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 return realdst;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 }