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.

66 lines
1.7 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 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
  18. /* We need a second copies, as Python might modify the first one. */
  19. wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
  20. int i, res;
  21. char *oldloc;
  22. /* 754 requires that FP exceptions run in "no stop" mode by default,
  23. * and until C vendors implement C99's ways to control FP exceptions,
  24. * Python requires non-stop mode. Alas, some platforms enable FP
  25. * exceptions by default. Here we disable them.
  26. */
  27. #ifdef __FreeBSD__
  28. fp_except_t m;
  29. m = fpgetmask();
  30. fpsetmask(m & ~FP_X_OFL);
  31. #endif
  32. if (!argv_copy || !argv_copy2) {
  33. fprintf(stderr, "out of memory\n");
  34. return 1;
  35. }
  36. oldloc = strdup(setlocale(LC_ALL, NULL));
  37. setlocale(LC_ALL, "");
  38. for (i = 0; i < argc; i++) {
  39. argv_copy[i] = _Py_char2wchar(argv[i], NULL);
  40. if (!argv_copy[i]) {
  41. free(oldloc);
  42. fprintf(stderr, "Fatal Python error: "
  43. "unable to decode the command line argument #%i\n",
  44. i + 1);
  45. return 1;
  46. }
  47. argv_copy2[i] = argv_copy[i];
  48. }
  49. argv_copy2[argc] = argv_copy[argc] = NULL;
  50. setlocale(LC_ALL, oldloc);
  51. free(oldloc);
  52. res = Py_Main(argc, argv_copy);
  53. for (i = 0; i < argc; i++) {
  54. PyMem_Free(argv_copy2[i]);
  55. }
  56. PyMem_Free(argv_copy);
  57. PyMem_Free(argv_copy2);
  58. return res;
  59. }
  60. #endif