Skip to content
Snippets Groups Projects
Commit 973ff03d authored by Matt Harbison's avatar Matt Harbison
Browse files

exewrapper: convert to _tcsxxx functions for Unicode compatability

This fixes more than 50 tests on py3 on Windows when enabled, mostly hooks and
such that invoked `hg` directly.  187 left to go.

I skipped doing the abort printing with Unicode because of apparent issues with
MinGW [1].  It may be moot though, as MinGW isn't listed as a supported compiler
after 3.4 [2].

[1] https://stackoverflow.com/questions/17700797/printf-wprintf-s-s-ls-char-and-wchar-errors-not-announced-by-a-compil
[2] https://wiki.python.org/moin/WindowsCompilers
parent aca72735
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@
*/
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include "hgpythonlib.h"
......@@ -21,5 +22,9 @@
{
return !strncpy(d, s, n);
}
#define _tcscpy_s strcpy_s
#define _tcscat_s strcat_s
#define _countof(array) (sizeof(array)/sizeof(array[0]))
#endif
......@@ -24,6 +29,6 @@
#endif
static char pyscript[MAX_PATH + 10];
static char pyhome[MAX_PATH + 10];
static char pydllfile[MAX_PATH + 10];
static TCHAR pyscript[MAX_PATH + 10];
static TCHAR pyhome[MAX_PATH + 10];
static TCHAR pydllfile[MAX_PATH + 10];
......@@ -29,3 +34,3 @@
int main(int argc, char *argv[])
int _tmain(int argc, TCHAR *argv[])
{
......@@ -31,5 +36,5 @@
{
char *p;
TCHAR *p;
int ret;
int i;
int n;
......@@ -33,8 +38,8 @@
int ret;
int i;
int n;
char **pyargv;
TCHAR **pyargv;
WIN32_FIND_DATA fdata;
HANDLE hfind;
const char *err;
HMODULE pydll;
......@@ -37,7 +42,7 @@
WIN32_FIND_DATA fdata;
HANDLE hfind;
const char *err;
HMODULE pydll;
void(__cdecl * Py_SetPythonHome)(char *home);
int(__cdecl * Py_Main)(int argc, char *argv[]);
void(__cdecl * Py_SetPythonHome)(TCHAR *home);
int(__cdecl * Py_Main)(int argc, TCHAR *argv[]);
......@@ -43,6 +48,6 @@
if (GetModuleFileName(NULL, pyscript, sizeof(pyscript)) == 0) {
if (GetModuleFileName(NULL, pyscript, _countof(pyscript)) == 0) {
err = "GetModuleFileName failed";
goto bail;
}
......@@ -45,10 +50,10 @@
err = "GetModuleFileName failed";
goto bail;
}
p = strrchr(pyscript, '.');
p = _tcsrchr(pyscript, '.');
if (p == NULL) {
err = "malformed module filename";
goto bail;
}
*p = 0; /* cut trailing ".exe" */
......@@ -50,9 +55,9 @@
if (p == NULL) {
err = "malformed module filename";
goto bail;
}
*p = 0; /* cut trailing ".exe" */
strcpy_s(pyhome, sizeof(pyhome), pyscript);
_tcscpy_s(pyhome, _countof(pyhome), pyscript);
hfind = FindFirstFile(pyscript, &fdata);
if (hfind != INVALID_HANDLE_VALUE) {
......@@ -60,8 +65,8 @@
FindClose(hfind);
} else {
/* file pyscript isn't there, take <pyscript>exe.py */
strcat_s(pyscript, sizeof(pyscript), "exe.py");
_tcscat_s(pyscript, _countof(pyscript), _T("exe.py"));
}
pydll = NULL;
......@@ -64,8 +69,8 @@
}
pydll = NULL;
p = strrchr(pyhome, '\\');
p = _tcsrchr(pyhome, _T('\\'));
if (p == NULL) {
err = "can't find backslash in module filename";
goto bail;
......@@ -73,10 +78,10 @@
*p = 0; /* cut at directory */
/* check for private Python of HackableMercurial */
strcat_s(pyhome, sizeof(pyhome), "\\hg-python");
_tcscat_s(pyhome, _countof(pyhome), _T("\\hg-python"));
hfind = FindFirstFile(pyhome, &fdata);
if (hfind != INVALID_HANDLE_VALUE) {
/* Path .\hg-python exists. We are probably in HackableMercurial
scenario, so let's load python dll from this dir. */
FindClose(hfind);
......@@ -77,10 +82,11 @@
hfind = FindFirstFile(pyhome, &fdata);
if (hfind != INVALID_HANDLE_VALUE) {
/* Path .\hg-python exists. We are probably in HackableMercurial
scenario, so let's load python dll from this dir. */
FindClose(hfind);
strcpy_s(pydllfile, sizeof(pydllfile), pyhome);
strcat_s(pydllfile, sizeof(pydllfile), "\\" HGPYTHONLIB ".dll");
_tcscpy_s(pydllfile, _countof(pydllfile), pyhome);
_tcscat_s(pydllfile, _countof(pydllfile), _T("\\") _T(HGPYTHONLIB)
_T(".dll"));
pydll = LoadLibrary(pydllfile);
if (pydll == NULL) {
......@@ -85,7 +91,6 @@
pydll = LoadLibrary(pydllfile);
if (pydll == NULL) {
err = "failed to load private Python DLL " HGPYTHONLIB
".dll";
err = "failed to load private Python DLL " HGPYTHONLIB ".dll";
goto bail;
}
Py_SetPythonHome =
......@@ -98,7 +103,7 @@
}
if (pydll == NULL) {
pydll = LoadLibrary(HGPYTHONLIB ".dll");
pydll = LoadLibrary(_T(HGPYTHONLIB) _T(".dll"));
if (pydll == NULL) {
err = "failed to load Python DLL " HGPYTHONLIB ".dll";
goto bail;
......@@ -118,7 +123,7 @@
place. So we optionally accept the pyscript as the first argument
(argv[1]), letting our exe taking the role of the python interpreter.
*/
if (argc >= 2 && strcmp(argv[1], pyscript) == 0) {
if (argc >= 2 && _tcscmp(argv[1], pyscript) == 0) {
/*
pyscript is already in the args, so there is no need to copy
the args and we can directly call the python interpreter with
......@@ -132,7 +137,7 @@
name of our exe (argv[0]) in the position where the python.exe
canonically is, and insert the pyscript next.
*/
pyargv = malloc((argc + 5) * sizeof(char *));
pyargv = malloc((argc + 5) * sizeof(TCHAR *));
if (pyargv == NULL) {
err = "not enough memory";
goto bail;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment