Skip to content

Commit

Permalink
Miscellaneous fixes for later versions of Visual Studio that fixes so…
Browse files Browse the repository at this point in the history
…me missing symbols in timemodule.c, and re-implements _PyVerify_fd in posixmodule.c so that it validates the handle/fd.
  • Loading branch information
arizvisa committed Sep 1, 2019
1 parent bb43cf4 commit 14f4193
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
58 changes: 56 additions & 2 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

#include "Python.h"
#include "structseq.h"
#ifndef MS_WINDOWS
#ifdef MS_WINDOWS
#include <Windows.h>
#else
#include "posixmodule.h"
#endif

Expand Down Expand Up @@ -282,6 +284,14 @@ extern int lstat(const char *, struct stat *);
#define pclose _pclose
#endif /* _MSC_VER */

#if !defined(SEP)
#ifdef MS_WINDOWS
#define SEP "\\"
#else
#define SEP "/"
#endif
#endif

#if defined(PYCC_VACPP) && defined(PYOS_OS2)
#include <io.h>
#endif /* OS2 */
Expand Down Expand Up @@ -533,8 +543,48 @@ _PyInt_FromDev(PY_LONG_LONG v)
# define _PyInt_FromDev PyInt_FromLong
#endif

#if defined _MSC_VER && _MSC_VER >= 1700
void
_PyInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved)
{
}

int
_PyVerify_fd(int fd)
{
HANDLE hFd;
_invalid_parameter_handler oldHandler;

oldHandler = _set_invalid_parameter_handler(_PyInvalidParameterHandler);

#if defined _MSC_VER && _MSC_VER >= 1400
hFd = _get_osfhandle(fd);
if (hFd == INVALID_HANDLE_VALUE)
goto fail;
if ((fd < 0) || _isatty(fd))
goto fail;

// FIXME: ensure that file descriptor is open too
_set_invalid_parameter_handler(oldHandler);
return 1;

fail:
_set_invalid_parameter_handler(oldHandler);
return 0;
}

static int
_PyVerify_fd_dup2(int fd1, int fd2)
{
_invalid_parameter_handler oldHandler;

if (!_PyVerify_fd(fd1))
return 0;
if (fd2 < 0)
return 0;
return 1;
}

#elif defined _MSC_VER && _MSC_VER >= 1400
/* Microsoft CRT in VS2005 and higher will verify that a filehandle is
* valid and raise an assertion if it isn't.
* Normally, an invalid fd is likely to be a C program error and therefore
Expand Down Expand Up @@ -5377,6 +5427,10 @@ win32_popen4(PyObject *self, PyObject *args)
return f;
}

#if !defined(SEP)
#define SEP "\\"
#endif

static BOOL
_PyPopenCreateProcess(char *cmdstring,
HANDLE hStdin,
Expand Down
4 changes: 4 additions & 0 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ time_clock(PyObject *self, PyObject *unused)
#endif /* HAVE_CLOCK */

#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
#include <time.h>
#define timezone _timezone
#define daylight _daylight
#define tzname _tzname
/* Due to Mark Hammond and Tim Peters */
static PyObject *
time_clock(PyObject *self, PyObject *unused)
Expand Down

0 comments on commit 14f4193

Please sign in to comment.