annotate Mac/Tools/pythonw.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents ee5350f1d0c2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
1 /*
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
2 * This wrapper program executes a python executable hidden inside an
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
3 * application bundle inside the Python framework. This is needed to run
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
4 * GUI code: some GUI API's don't work unless the program is inside an
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
5 * application bundle.
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
6 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
7 * This program uses posix_spawn rather than plain execv because we need
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
8 * slightly more control over how the "real" interpreter is executed.
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
9 *
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
10 * On OSX 10.4 (and earlier) this falls back to using exec because the
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
11 * posix_spawnv functions aren't available there.
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
12 */
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
13 #pragma weak_import posix_spawnattr_init
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
14 #pragma weak_import posix_spawnattr_setbinpref_np
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
15 #pragma weak_import posix_spawnattr_setflags
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
16 #pragma weak_import posix_spawn
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
17
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
18 #include <Python.h>
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
19 #include <unistd.h>
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
20 #ifdef HAVE_SPAWN_H
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
21 #include <spawn.h>
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
22 #endif
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
23 #include <stdio.h>
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
24 #include <string.h>
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
25 #include <errno.h>
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
26 #include <err.h>
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
27 #include <dlfcn.h>
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
28 #include <stdlib.h>
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
29
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
30
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
31 extern char** environ;
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
32
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
33 /*
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
34 * Locate the python framework by looking for the
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
35 * library that contains Py_Initialize.
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
36 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
37 * In a regular framework the structure is:
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
38 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
39 * Python.framework/Versions/2.7
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
40 * /Python
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
41 * /Resources/Python.app/Contents/MacOS/Python
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
42 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
43 * In a virtualenv style structure the expected
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
44 * structure is:
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
45 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
46 * ROOT
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
47 * /bin/pythonw
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
48 * /.Python <- the dylib
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
49 * /.Resources/Python.app/Contents/MacOS/Python
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
50 *
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
51 * NOTE: virtualenv's are not an officially supported
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
52 * feature, support for that structure is provided as
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
53 * a convenience.
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
54 */
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
55 static char* get_python_path(void)
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
56 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
57 size_t len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
58 Dl_info info;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
59 char* end;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
60 char* g_path;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
61
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
62 if (dladdr(Py_Initialize, &info) == 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
63 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
64 }
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
65
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
66 len = strlen(info.dli_fname);
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
67
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
68 g_path = malloc(len+60);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
69 if (g_path == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
70 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
71 }
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
72
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
73 strcpy(g_path, info.dli_fname);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
74 end = g_path + len - 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
75 while (end != g_path && *end != '/') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
76 end --;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
77 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
78 end++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
79 if (*end == '.') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
80 end++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
81 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
82 strcpy(end, "Resources/Python.app/Contents/MacOS/" PYTHONFRAMEWORK);
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
83
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
84 return g_path;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
85 }
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
86
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
87 #ifdef HAVE_SPAWN_H
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
88 static void
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
89 setup_spawnattr(posix_spawnattr_t* spawnattr)
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
90 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
91 size_t ocount;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
92 size_t count;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
93 cpu_type_t cpu_types[1];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
94 short flags = 0;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
95 #ifdef __LP64__
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
96 int ch;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
97 #endif
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
98
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
99 if ((errno = posix_spawnattr_init(spawnattr)) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
100 err(2, "posix_spawnattr_int");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
101 /* NOTREACHTED */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
102 }
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
103
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
104 count = 1;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
105
68503
ee5350f1d0c2 #11515: fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62026
diff changeset
106 /* Run the real python executable using the same architecture as this
ee5350f1d0c2 #11515: fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62026
diff changeset
107 * executable, this allows users to control the architecture using
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
108 * "arch -ppc python"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
109 */
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
110
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
111 #if defined(__ppc64__)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
112 cpu_types[0] = CPU_TYPE_POWERPC64;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
113
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
114 #elif defined(__x86_64__)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
115 cpu_types[0] = CPU_TYPE_X86_64;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
116
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
117 #elif defined(__ppc__)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
118 cpu_types[0] = CPU_TYPE_POWERPC;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
119 #elif defined(__i386__)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
120 cpu_types[0] = CPU_TYPE_X86;
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
121 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
122 # error "Unknown CPU"
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
123 #endif
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
124
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
125 if (posix_spawnattr_setbinpref_np(spawnattr, count,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
126 cpu_types, &ocount) == -1) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
127 err(1, "posix_spawnattr_setbinpref");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
128 /* NOTREACHTED */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
129 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
130 if (count != ocount) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
131 fprintf(stderr, "posix_spawnattr_setbinpref failed to copy\n");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
132 exit(1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
133 /* NOTREACHTED */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
134 }
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
135
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
136
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
137 /*
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
138 * Set flag that causes posix_spawn to behave like execv
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
139 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
140 flags |= POSIX_SPAWN_SETEXEC;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
141 if ((errno = posix_spawnattr_setflags(spawnattr, flags)) != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
142 err(1, "posix_spawnattr_setflags");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
143 /* NOTREACHTED */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
144 }
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
145 }
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
146 #endif
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
147
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
148 int
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
149 main(int argc, char **argv) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
150 char* exec_path = get_python_path();
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
151
62026
bd47cd1f9bc2 Fix for issue8868: without this patch 'MacOS.WMAvailable()' will return
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 61463
diff changeset
152 /*
bd47cd1f9bc2 Fix for issue8868: without this patch 'MacOS.WMAvailable()' will return
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 61463
diff changeset
153 * Let argv[0] refer to the new interpreter. This is needed to
bd47cd1f9bc2 Fix for issue8868: without this patch 'MacOS.WMAvailable()' will return
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 61463
diff changeset
154 * get the effect we want on OSX 10.5 or earlier. That is, without
bd47cd1f9bc2 Fix for issue8868: without this patch 'MacOS.WMAvailable()' will return
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 61463
diff changeset
155 * changing argv[0] the real interpreter won't have access to
bd47cd1f9bc2 Fix for issue8868: without this patch 'MacOS.WMAvailable()' will return
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 61463
diff changeset
156 * the Window Server.
bd47cd1f9bc2 Fix for issue8868: without this patch 'MacOS.WMAvailable()' will return
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 61463
diff changeset
157 */
bd47cd1f9bc2 Fix for issue8868: without this patch 'MacOS.WMAvailable()' will return
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 61463
diff changeset
158 argv[0] = exec_path;
bd47cd1f9bc2 Fix for issue8868: without this patch 'MacOS.WMAvailable()' will return
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 61463
diff changeset
159
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
160 #ifdef HAVE_SPAWN_H
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
161
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
162 /* We're weak-linking to posix-spawnv to ensure that
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
163 * an executable build on 10.5 can work on 10.4.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
164 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
165 if (posix_spawn != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
166 posix_spawnattr_t spawnattr = NULL;
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
167
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
168
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
169 setup_spawnattr(&spawnattr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
170 posix_spawn(NULL, exec_path, NULL,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
171 &spawnattr, argv, environ);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
172 err(1, "posix_spawn: %s", exec_path);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
173 }
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
174 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
175 execve(exec_path, argv, environ);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
176 err(1, "execve: %s", argv[0]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60456
diff changeset
177 /* NOTREACHED */
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
178 }