Cross-Platform build scripts for audio plugins
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
12KB

  1. diff -Naur Python-3.8.0-orig/Include/pylifecycle.h Python-3.8.0/Include/pylifecycle.h
  2. --- Python-3.8.0-orig/Include/pylifecycle.h 2019-10-22 10:02:41.276120000 +0300
  3. +++ Python-3.8.0/Include/pylifecycle.h 2019-10-22 10:02:44.427325500 +0300
  4. @@ -53,7 +53,7 @@
  5. PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
  6. PyAPI_FUNC(wchar_t *) Py_GetPath(void);
  7. PyAPI_FUNC(void) Py_SetPath(const wchar_t *);
  8. -#ifdef MS_WINDOWS
  9. +#ifdef _MSC_VER
  10. int _Py_CheckPython3(void);
  11. #endif
  12. diff -Naur Python-3.8.0-orig/Modules/getpath.c Python-3.8.0/Modules/getpath.c
  13. --- Python-3.8.0-orig/Modules/getpath.c 2019-10-14 16:34:47.000000000 +0300
  14. +++ Python-3.8.0/Modules/getpath.c 2019-10-22 10:02:44.848526300 +0300
  15. @@ -14,6 +14,11 @@
  16. # include <mach-o/dyld.h>
  17. #endif
  18. +#ifdef MS_WINDOWS
  19. +#include <windows.h>
  20. +#include <shlwapi.h>
  21. +#endif
  22. +
  23. /* Search in some common locations for the associated Python libraries.
  24. *
  25. * Two directories must be found, the platform independent directory
  26. @@ -132,13 +137,39 @@
  27. int prefix_found; /* found platform independent libraries? */
  28. int exec_prefix_found; /* found the platform dependent libraries? */
  29. + wchar_t *dll_path;
  30. int warnings;
  31. const wchar_t *pythonpath_env;
  32. } PyCalculatePath;
  33. static const wchar_t delimiter[2] = {DELIM, '\0'};
  34. -static const wchar_t separator[2] = {SEP, '\0'};
  35. +static wchar_t separator[2] = {SEP, '\0'};
  36. +static int
  37. +is_sep(wchar_t ch)
  38. +{
  39. +#ifdef _WIN32
  40. + return ch == SEP || ch == ALTSEP;
  41. +#else
  42. + return ch == SEP;
  43. +#endif
  44. +}
  45. +
  46. +static int
  47. +is_absolute(const wchar_t *path)
  48. +{
  49. +#ifdef _WIN32
  50. + size_t i = wcslen(path);
  51. + if (i >= 3) {
  52. + if (iswalpha(path[0]) && path[1] == L':' && is_sep(path[2])) {
  53. + return 1;
  54. + }
  55. + }
  56. + return 0;
  57. +#else
  58. + return path[0] == SEP;
  59. +#endif
  60. +}
  61. /* Get file status. Encode the path to the locale encoding. */
  62. static int
  63. @@ -161,7 +192,7 @@
  64. reduce(wchar_t *dir)
  65. {
  66. size_t i = wcslen(dir);
  67. - while (i > 0 && dir[i] != SEP) {
  68. + while (i > 0 && !is_sep(dir[i])) {
  69. --i;
  70. }
  71. dir[i] = '\0';
  72. @@ -241,14 +272,14 @@
  73. joinpath(wchar_t *buffer, const wchar_t *stuff, size_t buflen)
  74. {
  75. size_t n, k;
  76. - if (stuff[0] != SEP) {
  77. + if (!is_sep(stuff[0])) {
  78. n = wcslen(buffer);
  79. if (n >= buflen) {
  80. return PATHLEN_ERR();
  81. }
  82. - if (n > 0 && buffer[n-1] != SEP) {
  83. - buffer[n++] = SEP;
  84. + if (n > 0 && !is_sep(buffer[n-1]) != SEP) {
  85. + buffer[n++] = Py_GetSepW(buffer);
  86. }
  87. }
  88. else {
  89. @@ -284,7 +315,7 @@
  90. static PyStatus
  91. copy_absolute(wchar_t *path, const wchar_t *p, size_t pathlen)
  92. {
  93. - if (p[0] == SEP) {
  94. + if (is_absolute(p)) {
  95. if (safe_wcscpy(path, p, pathlen) < 0) {
  96. return PATHLEN_ERR();
  97. }
  98. @@ -297,7 +328,7 @@
  99. }
  100. return _PyStatus_OK();
  101. }
  102. - if (p[0] == '.' && p[1] == SEP) {
  103. + if (p[0] == '.' && is_sep(p[1])) {
  104. p += 2;
  105. }
  106. PyStatus status = joinpath(path, p, pathlen);
  107. @@ -313,7 +344,7 @@
  108. static PyStatus
  109. absolutize(wchar_t *path, size_t path_len)
  110. {
  111. - if (path[0] == SEP) {
  112. + if (is_absolute(path)) {
  113. return _PyStatus_OK();
  114. }
  115. @@ -403,6 +434,7 @@
  116. return status;
  117. }
  118. + Py_NormalizeSepsW(path);
  119. if (isfile(path)) {
  120. /* Check VPATH to see if argv0_path is in the build directory.
  121. VPATH can be empty. */
  122. @@ -427,6 +459,7 @@
  123. return status;
  124. }
  125. + Py_NormalizeSepsW(prefix);
  126. if (ismodule(prefix, prefix_len)) {
  127. *found = -1;
  128. reduce(prefix);
  129. @@ -529,12 +562,21 @@
  130. * return the compiled-in defaults instead.
  131. */
  132. if (calculate->prefix_found > 0) {
  133. +#ifdef _WIN32
  134. + wchar_t drive_root[3];
  135. + memset(drive_root, 0, sizeof(drive_root));
  136. + wcsncpy(drive_root, prefix, 3);
  137. +#endif
  138. reduce(prefix);
  139. reduce(prefix);
  140. /* The prefix is the root directory, but reduce() chopped
  141. * off the "/". */
  142. if (!prefix[0]) {
  143. +#ifdef _WIN32
  144. + wcsncpy(prefix, drive_root, 3);
  145. +#else
  146. wcscpy(prefix, separator);
  147. +#endif
  148. }
  149. pathconfig->prefix = _PyMem_RawWcsdup(prefix);
  150. }
  151. @@ -649,6 +691,7 @@
  152. /* Check for pybuilddir.txt */
  153. assert(*found == 0);
  154. + Py_NormalizeSepsW(exec_prefix);
  155. status = calculate_pybuilddir(argv0_path, exec_prefix, exec_prefix_len,
  156. found);
  157. if (_PyStatus_EXCEPTION(status)) {
  158. @@ -734,6 +777,7 @@
  159. if (_PyStatus_EXCEPTION(status)) {
  160. return status;
  161. }
  162. + Py_NormalizeSepsW(exec_prefix);
  163. }
  164. /* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */
  165. return _PyStatus_OK();
  166. @@ -746,11 +790,20 @@
  167. wchar_t *exec_prefix)
  168. {
  169. if (calculate->exec_prefix_found > 0) {
  170. +#ifdef _WIN32
  171. + wchar_t drive_root[3];
  172. + memset(drive_root, 0, sizeof(drive_root));
  173. + wcsncpy(drive_root, exec_prefix, 3);
  174. +#endif
  175. reduce(exec_prefix);
  176. reduce(exec_prefix);
  177. reduce(exec_prefix);
  178. if (!exec_prefix[0]) {
  179. +#ifdef _WIN32
  180. + wcsncpy(exec_prefix, drive_root, 3);
  181. +#else
  182. wcscpy(exec_prefix, separator);
  183. +#endif
  184. }
  185. pathconfig->exec_prefix = _PyMem_RawWcsdup(exec_prefix);
  186. @@ -767,6 +820,48 @@
  187. }
  188. +#ifdef MS_WINDOWS
  189. +static int
  190. +GetWindowsModulePaths(wchar_t *progpath)
  191. +{
  192. + int result = 0;
  193. + wchar_t program_full_path[MAXPATHLEN+1];
  194. + memset(program_full_path, 0, sizeof(program_full_path));
  195. +
  196. + if (GetModuleFileNameW(NULL, program_full_path, MAXPATHLEN)) {
  197. + result = 1;
  198. + Py_NormalizeSepsW(program_full_path);
  199. + }
  200. +
  201. + wcscpy(progpath, program_full_path);
  202. + return result;
  203. +}
  204. +
  205. +
  206. +wchar_t*
  207. +_Py_GetDLLPath(void)
  208. +{
  209. + wchar_t dll_path[MAXPATHLEN+1];
  210. + memset(dll_path, 0, sizeof(dll_path));
  211. +
  212. +#ifdef Py_ENABLE_SHARED
  213. + extern HANDLE PyWin_DLLhModule;
  214. + if (PyWin_DLLhModule) {
  215. + if (GetModuleFileNameW(PyWin_DLLhModule, dll_path, MAXPATHLEN)) {
  216. + Py_NormalizeSepsW(dll_path);
  217. + } else {
  218. + dll_path[0] = 0;
  219. + }
  220. + }
  221. +#else
  222. + dll_path[0] = 0;
  223. +#endif
  224. +
  225. + return _PyMem_RawWcsdup(dll_path);
  226. +}
  227. +#endif /* MS_WINDOWS */
  228. +
  229. +
  230. static PyStatus
  231. calculate_program_full_path(PyCalculatePath *calculate, _PyPathConfig *pathconfig)
  232. {
  233. @@ -789,7 +884,7 @@
  234. * other way to find a directory to start the search from. If
  235. * $PATH isn't exported, you lose.
  236. */
  237. - if (wcschr(pathconfig->program_name, SEP)) {
  238. + if (wcschr(pathconfig->program_name, Py_GetSepW(pathconfig->program_name))) {
  239. if (safe_wcscpy(program_full_path, pathconfig->program_name,
  240. program_full_path_len) < 0) {
  241. return PATHLEN_ERR();
  242. @@ -821,6 +916,10 @@
  243. PyMem_RawFree(path);
  244. }
  245. #endif /* __APPLE__ */
  246. +#ifdef MS_WINDOWS
  247. + else if(GetWindowsModulePaths(program_full_path)) {
  248. + }
  249. +#endif /* MS_WINDOWS */
  250. else if (calculate->path_env) {
  251. wchar_t *path = calculate->path_env;
  252. while (1) {
  253. @@ -861,7 +960,7 @@
  254. else {
  255. program_full_path[0] = '\0';
  256. }
  257. - if (program_full_path[0] != SEP && program_full_path[0] != '\0') {
  258. + if (!is_absolute(program_full_path)) {
  259. status = absolutize(program_full_path, program_full_path_len);
  260. if (_PyStatus_EXCEPTION(status)) {
  261. return status;
  262. @@ -1071,6 +1170,7 @@
  263. if (_PyStatus_EXCEPTION(status)) {
  264. return status;
  265. }
  266. + Py_NormalizeSepsW(zip_path);
  267. /* Replace "00" with version */
  268. size_t bufsz = wcslen(zip_path);
  269. @@ -1098,7 +1198,7 @@
  270. while (1) {
  271. wchar_t *delim = wcschr(defpath, DELIM);
  272. - if (defpath[0] != SEP) {
  273. + if (!is_absolute(defpath)) {
  274. /* Paths are relative to prefix */
  275. bufsz += prefixsz;
  276. }
  277. @@ -1115,6 +1215,11 @@
  278. bufsz += wcslen(zip_path) + 1;
  279. bufsz += wcslen(exec_prefix) + 1;
  280. +#ifdef MS_WINDOWS
  281. + if (is_absolute(prefix)) {
  282. + bufsz += wcslen(prefix) + 1;
  283. + }
  284. +#endif
  285. /* Allocate the buffer */
  286. wchar_t *buf = PyMem_RawMalloc(bufsz * sizeof(wchar_t));
  287. @@ -1140,9 +1245,9 @@
  288. while (1) {
  289. wchar_t *delim = wcschr(defpath, DELIM);
  290. - if (defpath[0] != SEP) {
  291. + if (!is_absolute(defpath)) {
  292. wcscat(buf, prefix);
  293. - if (prefixsz >= 2 && prefix[prefixsz - 2] != SEP &&
  294. + if (prefixsz >= 2 && !is_sep(prefix[prefixsz - 2]) &&
  295. defpath[0] != (delim ? DELIM : L'\0'))
  296. {
  297. /* not empty */
  298. @@ -1163,6 +1268,12 @@
  299. defpath = delim + 1;
  300. }
  301. wcscat(buf, delimiter);
  302. +#ifdef MS_WINDOWS
  303. + if (is_absolute(prefix)) {
  304. + wcscat(buf, prefix);
  305. + wcscat(buf, delimiter);
  306. + }
  307. +#endif
  308. /* Finally, on goes the directory for dynamic-load modules */
  309. wcscat(buf, exec_prefix);
  310. @@ -1188,16 +1299,20 @@
  311. if (!calculate->pythonpath) {
  312. return DECODE_LOCALE_ERR("PYTHONPATH define", len);
  313. }
  314. + Py_NormalizeSepsW(calculate->pythonpath);
  315. calculate->prefix = Py_DecodeLocale(PREFIX, &len);
  316. if (!calculate->prefix) {
  317. return DECODE_LOCALE_ERR("PREFIX define", len);
  318. }
  319. + Py_NormalizeSepsW(calculate->prefix);
  320. calculate->exec_prefix = Py_DecodeLocale(EXEC_PREFIX, &len);
  321. if (!calculate->exec_prefix) {
  322. return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
  323. }
  324. - calculate->lib_python = Py_DecodeLocale("lib/python" VERSION, &len);
  325. + Py_NormalizeSepsW(calculate->exec_prefix);
  326. + const char *lib_python_VERSION = (Py_GetSepW(NULL) == L'/') ? "lib/python" VERSION : "lib\\python" VERSION;
  327. + calculate->lib_python = Py_DecodeLocale(lib_python_VERSION, &len);
  328. if (!calculate->lib_python) {
  329. return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
  330. }
  331. @@ -1215,6 +1330,7 @@
  332. PyMem_RawFree(calculate->pythonpath);
  333. PyMem_RawFree(calculate->prefix);
  334. PyMem_RawFree(calculate->exec_prefix);
  335. + PyMem_RawFree(calculate->dll_path);
  336. PyMem_RawFree(calculate->lib_python);
  337. PyMem_RawFree(calculate->path_env);
  338. }
  339. @@ -1225,6 +1341,8 @@
  340. {
  341. PyStatus status;
  342. + calculate->dll_path = _Py_GetDLLPath();
  343. +
  344. if (pathconfig->program_full_path == NULL) {
  345. status = calculate_program_full_path(calculate, pathconfig);
  346. if (_PyStatus_EXCEPTION(status)) {
  347. @@ -1343,6 +1461,7 @@
  348. {
  349. PyStatus status;
  350. PyCalculatePath calculate;
  351. + separator[0] = Py_GetSepW(NULL);
  352. memset(&calculate, 0, sizeof(calculate));
  353. status = calculate_init(&calculate, config);
  354. diff -Naur Python-3.8.0-orig/Modules/posixmodule.c Python-3.8.0/Modules/posixmodule.c
  355. --- Python-3.8.0-orig/Modules/posixmodule.c 2019-10-22 10:02:42.087321400 +0300
  356. +++ Python-3.8.0/Modules/posixmodule.c 2019-10-22 10:02:45.238527000 +0300
  357. @@ -3691,7 +3691,7 @@
  358. Py_END_ALLOW_THREADS
  359. /* FindNextFile sets error to ERROR_NO_MORE_FILES if
  360. it got to the end of the directory. */
  361. - if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
  362. + if (!result && GetLastError() != 0 && GetLastError() != ERROR_NO_MORE_FILES) {
  363. Py_DECREF(list);
  364. list = path_error(path);
  365. goto exit;
  366. diff -Naur Python-3.8.4-orig/Python/dynload_win.c Python-3.8.4/Python/dynload_win.c
  367. --- Python-3.8.4-orig/Python/dynload_win.c 2019-10-22 10:01:24.710185500 +0300
  368. +++ Python-3.8.4/Python/dynload_win.c 2019-10-22 10:02:45.644127700 +0300
  369. @@ -180,7 +180,9 @@
  370. char funcname[258], *import_python;
  371. const wchar_t *wpathname;
  372. +#if defined(_MSC_VER)
  373. _Py_CheckPython3();
  374. +#endif
  375. wpathname = _PyUnicode_AsUnicode(pathname);
  376. if (wpathname == NULL)