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.

77 lines
1.9 KiB

  1. /* Minimal main program -- everything is loaded from the library */
  2. #include "Python.h"
  3. #include <locale.h>
  4. #ifdef __FreeBSD__
  5. #include <floatingpoint.h>
  6. #endif
  7. #ifdef MS_WINDOWS
  8. int
  9. wmain(int argc, wchar_t **argv)
  10. {
  11. return Py_Main(argc, argv);
  12. }
  13. #else
  14. int
  15. main(int argc, char **argv)
  16. {
  17. wchar_t **argv_copy;
  18. /* We need a second copy, as Python might modify the first one. */
  19. wchar_t **argv_copy2;
  20. int i, res;
  21. char *oldloc;
  22. #ifdef __FreeBSD__
  23. fp_except_t m;
  24. #endif
  25. argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
  26. argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
  27. if (!argv_copy || !argv_copy2) {
  28. fprintf(stderr, "out of memory\n");
  29. return 1;
  30. }
  31. /* 754 requires that FP exceptions run in "no stop" mode by default,
  32. * and until C vendors implement C99's ways to control FP exceptions,
  33. * Python requires non-stop mode. Alas, some platforms enable FP
  34. * exceptions by default. Here we disable them.
  35. */
  36. #ifdef __FreeBSD__
  37. m = fpgetmask();
  38. fpsetmask(m & ~FP_X_OFL);
  39. #endif
  40. oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
  41. if (!oldloc) {
  42. fprintf(stderr, "out of memory\n");
  43. return 1;
  44. }
  45. setlocale(LC_ALL, "");
  46. for (i = 0; i < argc; i++) {
  47. argv_copy[i] = _Py_char2wchar(argv[i], NULL);
  48. if (!argv_copy[i]) {
  49. PyMem_RawFree(oldloc);
  50. fprintf(stderr, "Fatal Python error: "
  51. "unable to decode the command line argument #%i\n",
  52. i + 1);
  53. return 1;
  54. }
  55. argv_copy2[i] = argv_copy[i];
  56. }
  57. argv_copy2[argc] = argv_copy[argc] = NULL;
  58. setlocale(LC_ALL, oldloc);
  59. PyMem_RawFree(oldloc);
  60. res = Py_Main(argc, argv_copy);
  61. for (i = 0; i < argc; i++) {
  62. PyMem_RawFree(argv_copy2[i]);
  63. }
  64. PyMem_RawFree(argv_copy);
  65. PyMem_RawFree(argv_copy2);
  66. return res;
  67. }
  68. #endif