Mercurial > cpython-lru_cache-weakref
annotate Python/getopt.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 | a826a46bae54 |
| children | 2f3f2e32dfd9 |
| rev | line source |
|---|---|
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
1 /*---------------------------------------------------------------------------* |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
2 * <RCS keywords> |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
3 * |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
4 * C++ Library |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
5 * |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
6 * Copyright 1992-1994, David Gottner |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
7 * |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
8 * All Rights Reserved |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
9 * |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
10 * Permission to use, copy, modify, and distribute this software and its |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
11 * documentation for any purpose and without fee is hereby granted, |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
12 * provided that the above copyright notice, this permission notice and |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
13 * the following disclaimer notice appear unmodified in all copies. |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
14 * |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
15 * I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL I |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
17 * BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
18 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
19 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
20 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
21 * |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
22 * Nevertheless, I would like to know about bugs in this library or |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
23 * suggestions for improvment. Send bug reports and feedback to |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
24 * davegottner@delphi.com. |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
25 *---------------------------------------------------------------------------*/ |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 #include <stdio.h> |
|
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 #include <string.h> |
|
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
30 int _PyOS_opterr = 1; /* generate error messages */ |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
31 int _PyOS_optind = 1; /* index into argv array */ |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
32 char *_PyOS_optarg = NULL; /* optional argument */ |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
34 int _PyOS_GetOpt(int argc, char **argv, char *optstring) |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 { |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
36 static char *opt_ptr = ""; |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
37 char *ptr; |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
38 int option; |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
40 if (*opt_ptr == '\0') { |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
41 |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
42 if (_PyOS_optind >= argc || argv[_PyOS_optind][0] != '-' || |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
43 argv[_PyOS_optind][1] == '\0' /* lone dash */ ) |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
44 return -1; |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
46 else if (strcmp(argv[_PyOS_optind], "--") == 0) { |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
47 ++_PyOS_optind; |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
48 return -1; |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
49 } |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
51 opt_ptr = &argv[_PyOS_optind++][1]; |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
52 } |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 |
|
6364
f39bee3ff22b
Fix a bug in this code that made it do the wrong thing when an option
Guido van Rossum <guido@python.org>
parents:
5313
diff
changeset
|
54 if ( (option = *opt_ptr++) == '\0') |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
55 return -1; |
|
6364
f39bee3ff22b
Fix a bug in this code that made it do the wrong thing when an option
Guido van Rossum <guido@python.org>
parents:
5313
diff
changeset
|
56 |
|
f39bee3ff22b
Fix a bug in this code that made it do the wrong thing when an option
Guido van Rossum <guido@python.org>
parents:
5313
diff
changeset
|
57 if ((ptr = strchr(optstring, option)) == NULL) { |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
58 if (_PyOS_opterr) |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
59 fprintf(stderr, "Unknown option: -%c\n", option); |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
61 return '?'; |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
62 } |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
64 if (*(ptr + 1) == ':') { |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
65 if (*opt_ptr != '\0') { |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
66 _PyOS_optarg = opt_ptr; |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
67 opt_ptr = ""; |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
68 } |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
70 else { |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
71 if (_PyOS_optind >= argc) { |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
72 if (_PyOS_opterr) |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
73 fprintf(stderr, |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
74 "Argument expected for the -%c option\n", option); |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
75 return '?'; |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
76 } |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
78 _PyOS_optarg = argv[_PyOS_optind++]; |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
79 } |
|
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
80 } |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 |
|
1598
ecbadb818847
New version handles -o<string> same as -o <string>
Guido van Rossum <guido@python.org>
parents:
1585
diff
changeset
|
82 return option; |
|
1585
7c75f60468f8
A getopt.c for your amusement
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 } |
