Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions winloop/handles/process.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ DEF _CALL_PIPE_CONNECTION_LOST = 1
DEF _CALL_PROCESS_EXITED = 2
DEF _CALL_CONNECTION_LOST = 3

cdef int WINDOWS_EXE_FROZEN = system.__IS_WINDOWS_EXE_FROZEN()



@cython.no_gc_clear
cdef class UVProcessTransport(UVProcess):
Expand Down Expand Up @@ -439,11 +442,14 @@ cdef class UVProcessTransport(UVProcess):
else:
self._pending_calls.append((_CALL_PIPE_DATA_RECEIVED, fd, data))

# TODO: https://github.com/Vizonex/Winloop/issues/126 bug fix for uvloop
# Might need a special implementation for subprocess.Popen._get_handles()
# but can't seem to wrap my head around how to go about doing it.


cdef _file_redirect_stdio(self, int fd):
if WINDOWS_EXE_FROZEN:
# SEE: https://github.com/Vizonex/Winloop/issues/126
# use devnull instead...
return self._file_devnull()

fd = os_dup(fd)
os_set_inheritable(fd, True)
self._close_after_spawn(fd)
Expand Down
37 changes: 37 additions & 0 deletions winloop/includes/compat.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <errno.h>
#include <stddef.h>
#include <signal.h>
#include <stdint.h> // intptr_t
#ifndef _WIN32
#include <sys/socket.h>
#include <sys/un.h>
Expand Down Expand Up @@ -179,3 +180,39 @@ void PyOS_AfterFork_Child() {
#endif


/* There is a bug with CX-Freeze on windows when compiled
* to an exe this tries to fix it by seeing if alternate
* workarounds like DEVNULL need to be provided.
* SEE: https://github.com/Vizonex/Winloop/issues/126 */

#ifdef _WIN32
/* CPython version might be slower so will use our own, audits can be a costly thing, */

static int _get_std_handle(DWORD std_handle){
/* This might be a leak, IDK... CloseHandle just seems to crash it.*/
HANDLE handle = GetStdHandle(std_handle);
if (handle == INVALID_HANDLE_VALUE){
goto error;
}
/* We don't need this handle open we just want to know
if windows wants to play nice or not. executable vs not executable. */
int windows_misbehaved = (handle == NULL) ? 1: 0;
/* if handle == 0 use DEVNULL as backup instead otherwise use the other method. */
return windows_misbehaved;
error:
/* if handle == -1 throw an error */
PyErr_SetFromWindowsErr(GetLastError());
return -1;
}

/* Because these are macros it's very easy to make a workaround for unix. */
#define __IS_WINDOWS_EXE_FROZEN() _get_std_handle(STD_INPUT_HANDLE)
#else
/* On Unix these are not needed, but we define it anyways so the
compiler doesn't wind up throwing a fit about it */

#define __IS_WINDOWS_EXE_FROZEN() 0 /* NOPE */

#endif


5 changes: 3 additions & 2 deletions winloop/includes/system.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from libc.stdint cimport int8_t, uint64_t
from libc.stdint cimport int8_t, uint64_t, uintptr_t

cdef extern from "includes/compat.h" nogil:

Expand Down Expand Up @@ -65,7 +65,8 @@ cdef extern from "includes/compat.h" nogil:
int epoll_ctl(int epfd, int op, int fd, epoll_event *event)
object MakeUnixSockPyAddr(sockaddr_un *addr)


int __IS_WINDOWS_EXE_FROZEN() except -1

cdef extern from "includes/fork_handler.h":

uint64_t MAIN_THREAD_ID
Expand Down
38 changes: 0 additions & 38 deletions winloop/shlex.pxd

This file was deleted.

Loading
Loading