annotate Python/strdup.c @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents e7f6cef7a4cc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4174
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* strdup() replacement (from stdwin, if you must know) */
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 4175
diff changeset
3 #include "pgenheaders.h"
4174
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 char *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 9970
diff changeset
6 strdup(const char *str)
4174
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 {
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 if (str != NULL) {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 13658
diff changeset
9 char *copy = malloc(strlen(str) + 1);
4174
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 if (copy != NULL)
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 return strcpy(copy, str);
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 }
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 return NULL;
d241bfda7b74 *** empty log message ***
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 }