annotate Python/formatter_string.c @ 56007:b0d03fa073ec legacy-trunk

Fix issue #1590864, multiple threads and fork() can cause deadlocks, by acquiring the import lock around fork() calls. This prevents other threads from having that lock while the fork happens, and is the recommended way of dealing with such issues. There are two other locks we care about, the GIL and the Thread Local Storage lock. The GIL is obviously held when calling Python functions like os.fork(), and the TLS lock is explicitly reallocated instead, while also deleting now-orphaned TLS data. This only fixes calls to os.fork(), not extension modules or embedding programs calling C's fork() directly. Solving that requires a new set of API functions, and possibly a rewrite of the Python/thread_*.c mess. Add a warning explaining the problem to the documentation in the mean time. This also changes behaviour a little on AIX. Before, AIX (but only AIX) was getting the import lock reallocated, seemingly to avoid this very same problem. This is not the right approach, because the import lock is a re-entrant one, and reallocating would do the wrong thing when forking while holding the import lock. Will backport to 2.6, minus the tiny AIX behaviour change.
author Thomas Wouters <thomas@python.org>
date Wed, 16 Sep 2009 19:55:54 +0000
parents 34e7c1b14495
children 2754d64180d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45381
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
1 /***********************************************************************/
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
2 /* Implements the string (as opposed to unicode) version of the
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
3 built-in formatters for string, int, float. That is, the versions
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
4 of int.__float__, etc., that take and return string objects */
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
5
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
6 #include "Python.h"
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
7 #include "../Objects/stringlib/stringdefs.h"
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
8
53629
34e7c1b14495 Issue #1588: Add complex.__format__.
Eric Smith <eric@trueblade.com>
parents: 47392
diff changeset
9 #define FORMAT_STRING _PyBytes_FormatAdvanced
34e7c1b14495 Issue #1588: Add complex.__format__.
Eric Smith <eric@trueblade.com>
parents: 47392
diff changeset
10 #define FORMAT_LONG _PyLong_FormatAdvanced
34e7c1b14495 Issue #1588: Add complex.__format__.
Eric Smith <eric@trueblade.com>
parents: 47392
diff changeset
11 #define FORMAT_INT _PyInt_FormatAdvanced
34e7c1b14495 Issue #1588: Add complex.__format__.
Eric Smith <eric@trueblade.com>
parents: 47392
diff changeset
12 #define FORMAT_FLOAT _PyFloat_FormatAdvanced
34e7c1b14495 Issue #1588: Add complex.__format__.
Eric Smith <eric@trueblade.com>
parents: 47392
diff changeset
13 #define FORMAT_COMPLEX _PyComplex_FormatAdvanced
47392
47ef9a806ce9 Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Eric Smith <eric@trueblade.com>
parents: 45381
diff changeset
14
45381
b7231bf6bfb7 Backport of PEP 3101, Advanced String Formatting, from py3k.
Eric Smith <eric@trueblade.com>
parents:
diff changeset
15 #include "../Objects/stringlib/formatter.h"