annotate Python/memmove.c @ 24155:9456a2ccda61 legacy-trunk

The Py_REF_DEBUG/COUNT_ALLOCS/Py_TRACE_REFS macro minefield: added more trivial lexical helper macros so that uses of these guys expand to nothing at all when they're not enabled. This should help sub- standard compilers that can't do a good job of optimizing away the previous "(void)0" expressions. Py_DECREF: There's only one definition of this now. Yay! That was that last one in the family defined multiple times in an #ifdef maze. Py_FatalError(): Changed the char* signature to const char*. _Py_NegativeRefcount(): New helper function for the Py_REF_DEBUG expansion of Py_DECREF. Calling an external function cuts down on the volume of generated code. The previous inline expansion of abort() didn't work as intended on Windows (the program often kept going, and the error msg scrolled off the screen unseen). _Py_NegativeRefcount calls Py_FatalError instead, which captures our best knowledge of how to abort effectively across platforms.
author Tim Peters <tim.peters@gmail.com>
date Tue, 09 Jul 2002 02:57:01 +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 }