diff options
author | guyroz <none@none> | 2011-09-20 00:30:09 +0300 |
---|---|---|
committer | guyroz <none@none> | 2011-09-20 00:30:09 +0300 |
commit | 7b263a6234594d272da9c664a62115963a44edfd (patch) | |
tree | 6c5b7bc67656b701c17fb622d2db69a728ee6ad9 | |
parent | 3b8de2876b38e5b2afc4210e6d37c5b90fecb8a4 (diff) | |
parent | a34c88660ad2ee5ef9c58cec0bb1deffbb8202d3 (diff) | |
download | external_python_setuptools-7b263a6234594d272da9c664a62115963a44edfd.tar.gz external_python_setuptools-7b263a6234594d272da9c664a62115963a44edfd.tar.bz2 external_python_setuptools-7b263a6234594d272da9c664a62115963a44edfd.zip |
merging issues_207_238 to master
--HG--
branch : distribute
extra : rebase_source : ffa072934d0623e442744b70426ac3c06326e2b8
-rwxr-xr-x | launcher.c | 102 | ||||
-rw-r--r-- | setuptools/cli-32.exe | bin | 0 -> 69632 bytes | |||
-rw-r--r-- | setuptools/cli-64.exe | bin | 0 -> 75264 bytes | |||
-rw-r--r-- | setuptools/cli.exe | bin | 7168 -> 69632 bytes | |||
-rwxr-xr-x | setuptools/command/easy_install.py | 9 | ||||
-rw-r--r-- | setuptools/gui-32.exe | bin | 0 -> 65536 bytes | |||
-rw-r--r-- | setuptools/gui-64.exe | bin | 0 -> 75264 bytes | |||
-rw-r--r-- | setuptools/gui.exe | bin | 7168 -> 7168 bytes |
8 files changed, 99 insertions, 12 deletions
@@ -25,9 +25,12 @@ #include <stdlib.h> #include <stdio.h> -#include <unistd.h> +#include <string.h> +#include <windows.h> +#include <tchar.h> #include <fcntl.h> -#include "windows.h" + +int child_pid=0; int fail(char *format, char *data) { /* Print error message to stderr and return 2 */ @@ -35,10 +38,6 @@ int fail(char *format, char *data) { return 2; } - - - - char *quoted(char *data) { int i, ln = strlen(data), nb; @@ -90,7 +89,7 @@ char *loadable_exe(char *exename) { /* Return the absolute filename for spawnv */ result = calloc(MAX_PATH, sizeof(char)); strncpy(result, exename, MAX_PATH); - /*if (result) GetModuleFileName(hPython, result, MAX_PATH); + /*if (result) GetModuleFileNameA(hPython, result, MAX_PATH); FreeLibrary(hPython); */ return result; @@ -160,8 +159,82 @@ char **parse_argv(char *cmdline, int *argc) } while (1); } +void pass_control_to_child(DWORD control_type) { + /* + * distribute-issue207 + * passes the control event to child process (Python) + */ + if (!child_pid) { + return; + } + GenerateConsoleCtrlEvent(child_pid,0); +} + +BOOL control_handler(DWORD control_type) { + /* + * distribute-issue207 + * control event handler callback function + */ + switch (control_type) { + case CTRL_C_EVENT: + pass_control_to_child(0); + break; + } + return TRUE; +} + +int create_and_wait_for_subprocess(char* command) { + /* + * distribute-issue207 + * launches child process (Python) + */ + DWORD return_value = 0; + LPSTR commandline = command; + STARTUPINFOA s_info; + PROCESS_INFORMATION p_info; + ZeroMemory(&p_info, sizeof(p_info)); + ZeroMemory(&s_info, sizeof(s_info)); + s_info.cb = sizeof(STARTUPINFO); + // set-up control handler callback funciotn + SetConsoleCtrlHandler((PHANDLER_ROUTINE) control_handler, TRUE); + if (!CreateProcessA(NULL, commandline, NULL, NULL, TRUE, 0, NULL, NULL, &s_info, &p_info)) { + fprintf(stderr, "failed to create process.\n"); + return 0; + } + child_pid = p_info.dwProcessId; + // wait for Python to exit + WaitForSingleObject(p_info.hProcess, INFINITE); + if (!GetExitCodeProcess(p_info.hProcess, &return_value)) { + fprintf(stderr, "failed to get exit code from process.\n"); + return 0; + } + return return_value; +} +char* join_executable_and_args(char *executable, char **args, int argc) +{ + /* + * distribute-issue207 + * CreateProcess needs a long string of the executable and command-line arguments, + * so we need to convert it from the args that was built + */ + int len,counter; + char* cmdline; + + len=strlen(executable)+2; + for (counter=1; counter<argc; counter++) { + len+=strlen(args[counter])+1; + } + cmdline = (char*)calloc(len, sizeof(char)); + sprintf(cmdline, "%s", executable); + len=strlen(executable); + for (counter=1; counter<argc; counter++) { + sprintf(cmdline+len, " %s", args[counter]); + len+=strlen(args[counter])+1; + } + return cmdline; +} int run(int argc, char **argv, int is_gui) { @@ -173,10 +246,11 @@ int run(int argc, char **argv, int is_gui) { char **newargs, **newargsp, **parsedargs; /* argument array for exec */ char *ptr, *end; /* working pointers for string manipulation */ + char *cmdline; int i, parsedargc; /* loop counter */ /* compute script name from our .exe name*/ - GetModuleFileName(NULL, script, sizeof(script)); + GetModuleFileNameA(NULL, script, sizeof(script)); end = script + strlen(script); while( end>script && *end != '.') *end-- = '\0'; @@ -236,12 +310,18 @@ int run(int argc, char **argv, int is_gui) { return fail("Could not exec %s", ptr); /* shouldn't get here! */ } - /* We *do* need to wait for a CLI to finish, so use spawn */ - return spawnv(P_WAIT, ptr, (const char * const *)(newargs)); + /* + * distribute-issue207: using CreateProcessA instead of spawnv + */ + cmdline = join_executable_and_args(ptr, newargs, parsedargc + argc); + return create_and_wait_for_subprocess(cmdline); } - int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR lpCmd, int nShow) { return run(__argc, __argv, GUI); } +int main(int argc, char** argv) { + return run(argc, argv, GUI); +} + diff --git a/setuptools/cli-32.exe b/setuptools/cli-32.exe Binary files differnew file mode 100644 index 00000000..9b7717b7 --- /dev/null +++ b/setuptools/cli-32.exe diff --git a/setuptools/cli-64.exe b/setuptools/cli-64.exe Binary files differnew file mode 100644 index 00000000..265585af --- /dev/null +++ b/setuptools/cli-64.exe diff --git a/setuptools/cli.exe b/setuptools/cli.exe Binary files differindex 8906ff77..9b7717b7 100644 --- a/setuptools/cli.exe +++ b/setuptools/cli.exe diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 853753c1..4700fe0e 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -42,6 +42,10 @@ __all__ = [ import site HAS_USER_SITE = not sys.version < "2.6" and site.ENABLE_USER_SITE +import struct +def is_64bit(): + return struct.calcsize("P") == 8 + def samefile(p1,p2): if hasattr(os.path,'samefile') and ( os.path.exists(p1) and os.path.exists(p2) @@ -1781,7 +1785,10 @@ def get_script_args(dist, executable=sys_executable, wininst=False): ext, launcher = '-script.py', 'cli.exe' old = ['.py','.pyc','.pyo'] new_header = re.sub('(?i)pythonw.exe','python.exe',header) - + if is_64bit(): + launcher = launcher.replace(".", "-64.") + else: + launcher = launcher.replace(".", "-32.") if os.path.exists(new_header[2:-1]) or sys.platform!='win32': hdr = new_header else: diff --git a/setuptools/gui-32.exe b/setuptools/gui-32.exe Binary files differnew file mode 100644 index 00000000..3f64af7d --- /dev/null +++ b/setuptools/gui-32.exe diff --git a/setuptools/gui-64.exe b/setuptools/gui-64.exe Binary files differnew file mode 100644 index 00000000..3ab4378e --- /dev/null +++ b/setuptools/gui-64.exe diff --git a/setuptools/gui.exe b/setuptools/gui.exe Binary files differindex 474838d5..8906ff77 100644 --- a/setuptools/gui.exe +++ b/setuptools/gui.exe |