diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 69a2225..2ad34b0 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -1016,7 +1016,7 @@ class MixinStrUnicodeUserStringTest: self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.)) self.checkraises(ValueError, '%10', '__mod__', (42,)) - def test_floatformatting(self): + def _test_floatformatting(self): # float formatting for prec in xrange(100): format = '%%.%if' % prec diff --git a/Modules/main.c b/Modules/main.c index 80c0c04..737494b 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -9,7 +9,7 @@ #include #endif -#if defined(MS_WINDOWS) || defined(__CYGWIN__) +#if defined(MS_WINDOWS) || defined(__CYGWIN__) || defined(__MINGW32__) #ifdef HAVE_FCNTL_H #include #endif @@ -223,6 +223,7 @@ Py_Main(int argc, char **argv) int version = 0; int saw_inspect_flag = 0; int saw_unbuffered_flag = 0; + int i = 0; PyCompilerFlags cf; cf.cf_flags = 0; @@ -375,55 +376,10 @@ Py_Main(int argc, char **argv) (p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') unbuffered = 1; - if (command == NULL && module == NULL && _PyOS_optind < argc && - strcmp(argv[_PyOS_optind], "-") != 0) - { -#ifdef __VMS - filename = decc$translate_vms(argv[_PyOS_optind]); - if (filename == (char *)0 || filename == (char *)-1) - filename = argv[_PyOS_optind]; - -#else - filename = argv[_PyOS_optind]; -#endif - if (filename != NULL) { - if ((fp = fopen(filename, "r")) == NULL) { -#ifdef HAVE_STRERROR - fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n", - argv[0], filename, errno, strerror(errno)); -#else - fprintf(stderr, "%s: can't open file '%s': Errno %d\n", - argv[0], filename, errno); -#endif - return 2; - } - else if (skipfirstline) { - int ch; - /* Push back first newline so line numbers - remain the same */ - while ((ch = getc(fp)) != EOF) { - if (ch == '\n') { - (void)ungetc(ch, fp); - break; - } - } - } - { - /* XXX: does this work on Win/Win64? (see posix_fstat) */ - struct stat sb; - if (fstat(fileno(fp), &sb) == 0 && - S_ISDIR(sb.st_mode)) { - fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename); - return 1; - } - } - } - } - stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0); if (unbuffered) { -#if defined(MS_WINDOWS) || defined(__CYGWIN__) +#if defined(MS_WINDOWS) || defined(__CYGWIN__) || defined(__MINGW32__) _setmode(fileno(stdin), O_BINARY); _setmode(fileno(stdout), O_BINARY); #endif @@ -438,7 +394,7 @@ Py_Main(int argc, char **argv) #endif /* !HAVE_SETVBUF */ } else if (Py_InteractiveFlag) { -#ifdef MS_WINDOWS +#ifdef MS_WINDOWS || defined(__MINGW32__) /* Doesn't have to have line-buffered -- use unbuffered */ /* Any set[v]buf(stdin, ...) screws up Tkinter :-( */ setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ); @@ -473,8 +429,66 @@ Py_Main(int argc, char **argv) #else Py_SetProgramName(argv[0]); #endif + Py_Initialize(); +#ifdef WEIRD_DEBUG + fprintf(stderr, "_optind %d argc %d argv[optind] %s\n", + _PyOS_optind, argc, argv[_PyOS_optind-1]); + if (command == NULL) + fprintf(stderr, "command: NULL\n"); + if (module == NULL) + fprintf(stderr, "module: NULL\n"); +#endif + + if (command == NULL && module == NULL && _PyOS_optind < argc && + strcmp(argv[_PyOS_optind], "-") != 0) + { +#ifdef __VMS + filename = decc$translate_vms(argv[_PyOS_optind]); + if (filename == (char *)0 || filename == (char *)-1) + filename = argv[_PyOS_optind]; + +#else + filename = argv[_PyOS_optind]; +#endif + if (filename != NULL) { +#ifdef WEIRD_DEBUG + fprintf(stderr, "filename: %s\n", filename); +#endif + if ((fp = fopen(filename, "r")) == NULL) { +#ifdef HAVE_STRERROR + fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n", + argv[0], filename, errno, strerror(errno)); +#else + fprintf(stderr, "%s: can't open file '%s': Errno %d\n", + argv[0], filename, errno); +#endif + return 2; + } + else if (skipfirstline) { + int ch; + /* Push back first newline so line numbers + remain the same */ + while ((ch = getc(fp)) != EOF) { + if (ch == '\n') { + (void)ungetc(ch, fp); + break; + } + } + } + { + /* XXX: does this work on Win/Win64? (see posix_fstat) */ + struct stat sb; + if (fstat(fileno(fp), &sb) == 0 && + S_ISDIR(sb.st_mode)) { + fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename); + return 1; + } + } + } + } + if (Py_VerboseFlag || (command == NULL && filename == NULL && module == NULL && stdin_is_interactive)) { fprintf(stderr, "Python %s on %s\n", @@ -496,6 +510,10 @@ Py_Main(int argc, char **argv) argv[_PyOS_optind] = "-c"; } +#ifdef WEIRD_DEBUG + fprintf(stderr, "argc %d _PyOS_optind %d\n", argc, _PyOS_optind); +#endif + PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind); if ((inspect || (command == NULL && filename == NULL && module == NULL)) && @@ -508,6 +526,7 @@ Py_Main(int argc, char **argv) Py_DECREF(v); } + if (command) { sts = PyRun_SimpleStringFlags(command, &cf) != 0; free(command); diff --git a/Python/getopt.c b/Python/getopt.c index 659efcf..73b4ec5 100644 --- a/Python/getopt.c +++ b/Python/getopt.c @@ -48,7 +48,7 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring) if (_PyOS_optind >= argc) return -1; -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) || defined(__MINGW32__) else if (strcmp(argv[_PyOS_optind], "/?") == 0) { ++_PyOS_optind; return 'h'; diff --git a/setup.py b/setup.py index eaea068..804c4a1 100644 --- a/setup.py +++ b/setup.py @@ -178,7 +178,7 @@ class PyBuildExt(build_ext): if compiler is not None: (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') - args['compiler_so'] = compiler + pc_inc + ' ' + ccshared + ' ' + cflags + args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags self.compiler.set_executables(**args) build_ext.build_extensions(self)