Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fc64f28
[WIP] Start implementation of entrypoint support
zooba Nov 20, 2025
8b83213
[WIP] Updated, implemented, and existing tests pass
zooba Nov 24, 2025
7ff8626
Add test
zooba Nov 25, 2025
1263c28
Improved script and fixed names
zooba Nov 25, 2025
fc4793f
Fix tests
zooba Nov 25, 2025
bd20de5
Fix tests
zooba Nov 25, 2025
36118d8
Add tests to improve coverage
zooba Nov 26, 2025
81808f3
More test coverage
zooba Nov 26, 2025
2a3839b
Minor refactor, improved test coverage
zooba Nov 27, 2025
16a60c1
Remove unused import
zooba Nov 27, 2025
52d27a7
Add comment and update scratch key
zooba Nov 27, 2025
e05fbad
Add some missing log messages
zooba Nov 27, 2025
e621dd4
Minor bug fixes
zooba Nov 27, 2025
5916e76
Properly handle launching script executable (not DLL)
zooba Nov 27, 2025
5be8d04
Ensure pip.exe exists
zooba Dec 2, 2025
0a3924e
Merge main
zooba Dec 3, 2025
2069514
Add welcome message
zooba Dec 3, 2025
fddc8cc
Add refresh step to entrypoint test
zooba Dec 3, 2025
c67f0e5
Fix paths
zooba Dec 3, 2025
7f24d36
Minor refactoring on alias creation
zooba Dec 3, 2025
ea6d7c7
Fix calls
zooba Dec 3, 2025
935ab05
Merge main
zooba Dec 8, 2025
198a73f
Refactor and simplify code for aliases
zooba Dec 9, 2025
2eec6d2
Improved edge case handling and test
zooba Dec 9, 2025
a36f76a
Update args
zooba Dec 9, 2025
fb9b7c0
Remove some dead code
zooba Dec 9, 2025
13c57b7
Naming conventions
zooba Dec 9, 2025
42b51bb
Fixes and improvements suggested by reviewer
zooba Dec 9, 2025
753b295
Split names before testing
zooba Dec 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Properly handle launching script executable (not DLL)
  • Loading branch information
zooba committed Nov 27, 2025
commit 5916e76bf3374d6df6ca4a26f8d8063f374a797e
41 changes: 20 additions & 21 deletions src/pymanager/_launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,48 @@ dup_handle(HANDLE input, HANDLE *output)


int
launch(const wchar_t *executable, const wchar_t *insert_args, int skip_argc, DWORD *exitCode)
{
launch(
const wchar_t *executable,
const wchar_t *origCmdLine,
const wchar_t *insert_args,
int skip_argc,
DWORD *exitCode
) {
HANDLE job;
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info;
DWORD info_len;
STARTUPINFOW si;
PROCESS_INFORMATION pi;
int lastError = 0;
const wchar_t *arg_space = L" ";
LPCWSTR origCmdLine = GetCommandLineW();
const wchar_t *cmdLine = NULL;

if (insert_args == NULL) {
insert_args = L"";
if (origCmdLine[0] == L'"') {
cmdLine = wcschr(origCmdLine + 1, L'"');
} else {
cmdLine = wcschr(origCmdLine, L' ');
}

size_t n = wcslen(executable) + wcslen(origCmdLine) + wcslen(insert_args) + 5;
size_t n = wcslen(executable) + wcslen(origCmdLine) + wcslen(insert_args) + 6;
wchar_t *newCmdLine = (wchar_t *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, n * sizeof(wchar_t));
if (!newCmdLine) {
lastError = GetLastError();
goto exit;
}

if (origCmdLine[0] == L'"') {
cmdLine = wcschr(origCmdLine + 1, L'"');
} else {
cmdLine = wcschr(origCmdLine, L' ');
}

// Skip any requested args, deliberately leaving any trailing spaces
// (we'll skip one later one and add our own space, and preserve multiple)
while (skip_argc-- > 0) {
wchar_t c;
while (*++cmdLine && *cmdLine == L' ') { }
while (*++cmdLine && *cmdLine != L' ') { }
}

if (!insert_args || !*insert_args) {
arg_space = L"";
}
if (cmdLine && *cmdLine) {
swprintf_s(newCmdLine, n + 1, L"\"%s\"%s%s %s", executable, arg_space, insert_args, cmdLine + 1);
} else {
swprintf_s(newCmdLine, n + 1, L"\"%s\"%s%s", executable, arg_space, insert_args);
}
swprintf_s(newCmdLine, n, L"\"%s\"%s%s%s%s",
executable,
(insert_args && *insert_args) ? L" ": L"",
(insert_args && *insert_args) ? insert_args : L"",
(cmdLine && *cmdLine) ? L" " : L"",
(cmdLine && *cmdLine) ? cmdLine + 1 : L"");

#if defined(_WINDOWS)
/*
Expand Down
8 changes: 7 additions & 1 deletion src/pymanager/_launch.h
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
int launch(const wchar_t *executable, const wchar_t *insert_args, int skip_argc, DWORD *exitCode);
int launch(
const wchar_t *executable,
const wchar_t *origCmdLine,
const wchar_t *insert_args,
int skip_argc,
DWORD *exitCode
);
39 changes: 21 additions & 18 deletions src/pymanager/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ get_executable(wchar_t *executable, unsigned int bufferSize)


int
insert_script(int *argc, wchar_t ***argv)
get_script(wchar_t **result_path)
{
HANDLE ph = GetProcessHeap();
wchar_t *path = NULL;
Expand Down Expand Up @@ -194,22 +194,9 @@ insert_script(int *argc, wchar_t ***argv)
}
FindClose(fh);

// Create a new argv that will be used to launch the script.
wchar_t **argv2 = (wchar_t **)HeapAlloc(ph, HEAP_ZERO_MEMORY, sizeof(wchar_t *) * (*argc + 1));
if (!argv2) {
HeapFree(ph, 0, path);
return HRESULT_FROM_WIN32(GetLastError());
}

// Deliberately letting our memory leak - it'll be cleaned up when the
// process ends, and this is not a loop.
argv2[0] = (*argv)[0];
argv2[1] = path;
for (int i = 1; i < (*argc); ++i) {
argv2[i + 1] = (*argv)[i];
}
*argv = argv2;
*argc += 1;
*result_path = path;
return 0;
}

Expand Down Expand Up @@ -280,21 +267,36 @@ wmain(int argc, wchar_t **argv)
{
int exit_code;
wchar_t executable[MAXLEN];
wchar_t *script;

int err = get_executable(executable, MAXLEN);
if (err) {
return print_error(err, L"Failed to get target path");
}

err = insert_script(&argc, &argv);
err = get_script(&script);
if (err) {
return print_error(err, L"Failed to insert script path");
return print_error(err, L"Failed to get script path");
}

void *main_func = NULL;
err = try_load_python3_dll(executable, MAXLEN, (void **)&main_func);
switch (err) {
case 0:
if (script) {
wchar_t **argv2 = (wchar_t **)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
(argc + 1) * sizeof(wchar_t *));
if (!argv2) {
return HRESULT_FROM_WIN32(GetLastError());
}
argv2[0] = argv[0];
argv2[1] = script;
for (int i = 1; i < argc; ++i) {
argv2[i + 1] = argv[i];
}
argv = argv2;
argc += 1;
}
err = launch_by_dll(main_func, executable, argc, argv, &exit_code);
if (!err) {
return exit_code;
Expand Down Expand Up @@ -324,7 +326,8 @@ wmain(int argc, wchar_t **argv)
break;
}

err = launch(executable, NULL, 0, (DWORD *)&exit_code);
err = launch(executable, GetCommandLineW(), script, 0, (DWORD *)&exit_code);

if (!err) {
return exit_code;
}
Expand Down
2 changes: 1 addition & 1 deletion src/pymanager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ wmain(int argc, wchar_t **argv)
}
#endif

err = launch(executable.c_str(), args.c_str(), skip_argc, &exitCode);
err = launch(executable.c_str(), GetCommandLineW(), args.c_str(), skip_argc, &exitCode);

// TODO: Consider sharing print_error() with launcher.cpp
// This will ensure error messages are aligned whether we're launching
Expand Down