# HG changeset patch # User Nick Coghlan # Date 1369827916 -36000 # Node ID 4c84f09bd8de88c2ce1532769b0fe82bee43fcaf # Parent 7a6a8a00355329d247339519f100521c5516edac [mq]: move_programs diff -r 7a6a8a003553 -r 4c84f09bd8de .gitignore --- a/.gitignore Tue May 28 22:22:14 2013 -0400 +++ b/.gitignore Wed May 29 21:45:16 2013 +1000 @@ -26,8 +26,8 @@ Modules/Setup.local Modules/config.c Modules/ld_so_aix -Modules/_freeze_importlib -Modules/_testembed +Programs/_freeze_importlib +Programs/_testembed PCbuild/*.bsc PCbuild/*.dll PCbuild/*.exe diff -r 7a6a8a003553 -r 4c84f09bd8de .hgignore --- a/.hgignore Tue May 28 22:22:14 2013 -0400 +++ b/.hgignore Wed May 29 21:45:16 2013 +1000 @@ -86,8 +86,8 @@ PCbuild/amd64 BuildLog.htm __pycache__ -Modules/_freeze_importlib -Modules/_testembed +Programs/_freeze_importlib +Programs/_testembed .coverage coverage/ htmlcov/ diff -r 7a6a8a003553 -r 4c84f09bd8de .hgtouch --- a/.hgtouch Tue May 28 22:22:14 2013 -0400 +++ b/.hgtouch Wed May 29 21:45:16 2013 +1000 @@ -2,7 +2,7 @@ # Define dependencies of generated files that are checked into hg. # The syntax of this file uses make rule dependencies, without actions -Python/importlib.h: Lib/importlib/_bootstrap.py Modules/_freeze_importlib.c +Python/importlib.h: Lib/importlib/_bootstrap.py Programs/_freeze_importlib.c Include/ast.h: Parser/Python.asdl Parser/asdl.py Parser/asdl_c.py Python/Python-ast.c: Include/ast.h diff -r 7a6a8a003553 -r 4c84f09bd8de Makefile.pre.in --- a/Makefile.pre.in Tue May 28 22:22:14 2013 -0400 +++ b/Makefile.pre.in Wed May 29 21:45:16 2013 +1000 @@ -439,7 +439,7 @@ # Default target all: build_all -build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed python-config +build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config # Compile a binary with gcc profile guided optimization. profile-opt: @@ -470,8 +470,8 @@ # Build the interpreter -$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) - $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) +$(BUILDPYTHON): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) + $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) platform: $(BUILDPYTHON) pybuilddir.txt $(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform @@ -595,18 +595,18 @@ echo "-----------------------------------------------"; \ fi -Modules/_testembed: Modules/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) - $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) +Programs/_testembed: Programs/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) + $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) ############################################################################ # Importlib -Modules/_freeze_importlib: Modules/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN) - $(LINKCC) $(PY_LDFLAGS) -o $@ Modules/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) +Programs/_freeze_importlib: Programs/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN) + $(LINKCC) $(PY_LDFLAGS) -o $@ Programs/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) -Python/importlib.h: $(srcdir)/Lib/importlib/_bootstrap.py Modules/_freeze_importlib.c - $(MAKE) Modules/_freeze_importlib - ./Modules/_freeze_importlib \ +Python/importlib.h: $(srcdir)/Lib/importlib/_bootstrap.py Programs/_freeze_importlib.c + $(MAKE) Programs/_freeze_importlib + ./Programs/_freeze_importlib \ $(srcdir)/Lib/importlib/_bootstrap.py Python/importlib.h @@ -634,11 +634,11 @@ -DVPATH='"$(VPATH)"' \ -o $@ $(srcdir)/Modules/getpath.c -Modules/python.o: $(srcdir)/Modules/python.c - $(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Modules/python.c +Programs/python.o: $(srcdir)/Programs/python.c + $(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Programs/python.c -Modules/_testembed.o: $(srcdir)/Modules/_testembed.c - $(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Modules/_testembed.c +Programs/_testembed.o: $(srcdir)/Programs/_testembed.c + $(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Programs/_testembed.c Modules/posixmodule.o: $(srcdir)/Modules/posixmodule.c $(srcdir)/Modules/posixmodule.h @@ -845,7 +845,7 @@ pyconfig.h \ $(PARSER_HEADERS) -$(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS) +$(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS) ###################################################################### @@ -1206,7 +1206,7 @@ fi; \ fi $(INSTALL_DATA) Modules/config.c $(DESTDIR)$(LIBPL)/config.c - $(INSTALL_DATA) Modules/python.o $(DESTDIR)$(LIBPL)/python.o + $(INSTALL_DATA) Programs/python.o $(DESTDIR)$(LIBPL)/python.o $(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in $(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile $(INSTALL_DATA) Modules/Setup $(DESTDIR)$(LIBPL)/Setup @@ -1217,10 +1217,10 @@ $(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh $(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py $(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config - @if [ -s Modules/python.exp -a \ + @if [ -s Programs/python.exp -a \ "`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \ echo; echo "Installing support files for building shared extension modules on AIX:"; \ - $(INSTALL_DATA) Modules/python.exp \ + $(INSTALL_DATA) Programs/python.exp \ $(DESTDIR)$(LIBPL)/python.exp; \ echo; echo "$(LIBPL)/python.exp"; \ $(INSTALL_SCRIPT) $(srcdir)/Modules/makexp_aix \ @@ -1392,7 +1392,7 @@ find build -name '*.py[co]' -exec rm -f {} ';' || true -rm -f pybuilddir.txt -rm -f Lib/lib2to3/*Grammar*.pickle - -rm -f Modules/_testembed Modules/_freeze_importlib + -rm -f Programs/_testembed Programs/_freeze_importlib profile-removal: find . -name '*.gc??' -exec rm -f {} ';' @@ -1414,7 +1414,7 @@ done -rm -f core Makefile Makefile.pre config.status \ Modules/Setup Modules/Setup.local Modules/Setup.config \ - Modules/ld_so_aix Modules/python.exp Misc/python.pc + Modules/ld_so_aix Programs/python.exp Misc/python.pc -rm -f python*-gdb.py find $(srcdir) '(' -name '*.fdc' -o -name '*~' \ -o -name '[@,#]*' -o -name '*.old' \ diff -r 7a6a8a003553 -r 4c84f09bd8de Modules/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/README Wed May 29 21:45:16 2013 +1000 @@ -0,0 +1,2 @@ +Source files for standard library extension modules, +and former extension modules that are now builtin modules. diff -r 7a6a8a003553 -r 4c84f09bd8de Modules/_freeze_importlib.c --- a/Modules/_freeze_importlib.c Tue May 28 22:22:14 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/* This is built as a stand-alone executable by the Makefile, and helps turn - Lib/importlib/_bootstrap.py into a frozen module in Python/importlib.h -*/ - -#include -#include - -#include -#include -#include -#ifndef MS_WINDOWS -#include -#endif - - -/* To avoid a circular dependency on frozen.o, we create our own structure - of frozen modules instead, left deliberately blank so as to avoid - unintentional import of a stale version of _frozen_importlib. */ - -const static struct _frozen _PyImport_FrozenModules[] = { - {0, 0, 0} /* sentinel */ -}; - -#ifndef MS_WINDOWS -/* On Windows, this links with the regular pythonXY.dll, so this variable comes - from frozen.obj. In the Makefile, frozen.o is not linked into this executable, - so we define the variable here. */ -const struct _frozen *PyImport_FrozenModules; -#endif - -const char header[] = "/* Auto-generated by Modules/_freeze_importlib.c */"; - -int -main(int argc, char *argv[]) -{ - char *inpath, *outpath; - FILE *infile, *outfile = NULL; - struct stat st; - size_t text_size, data_size, n; - char *text; - unsigned char *data; - PyObject *code, *marshalled; - - PyImport_FrozenModules = _PyImport_FrozenModules; - - if (argc != 3) { - fprintf(stderr, "need to specify input and output paths\n"); - return 2; - } - inpath = argv[1]; - outpath = argv[2]; - infile = fopen(inpath, "rb"); - if (infile == NULL) { - fprintf(stderr, "cannot open '%s' for reading\n", inpath); - return 1; - } - if (fstat(fileno(infile), &st)) { - fclose(infile); - fprintf(stderr, "cannot fstat '%s'\n", inpath); - return 1; - } - text_size = st.st_size; - text = (char *) malloc(text_size + 1); - if (text == NULL) { - fclose(infile); - fprintf(stderr, "could not allocate %ld bytes\n", (long) text_size); - return 1; - } - n = fread(text, 1, text_size, infile); - fclose(infile); - infile = NULL; - if (n < text_size) { - fprintf(stderr, "read too short: got %ld instead of %ld bytes\n", - (long) n, (long) text_size); - return 1; - } - text[text_size] = '\0'; - - Py_NoUserSiteDirectory++; - Py_NoSiteFlag++; - Py_IgnoreEnvironmentFlag++; - - Py_SetProgramName(L"./_freeze_importlib"); - /* Don't install importlib, since it could execute outdated bytecode. */ - _Py_InitializeEx_Private(1, 0); - - code = Py_CompileStringExFlags(text, "", - Py_file_input, NULL, 0); - if (code == NULL) - goto error; - marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION); - Py_DECREF(code); - if (marshalled == NULL) - goto error; - - assert(PyBytes_CheckExact(marshalled)); - data = (unsigned char *) PyBytes_AS_STRING(marshalled); - data_size = PyBytes_GET_SIZE(marshalled); - - /* Open the file in text mode. The hg checkout should be using the eol extension, - which in turn should cause the EOL style match the C library's text mode */ - outfile = fopen(outpath, "w"); - if (outfile == NULL) { - fprintf(stderr, "cannot open '%s' for writing\n", outpath); - return 1; - } - fprintf(outfile, "%s\n", header); - fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n"); - for (n = 0; n < data_size; n += 16) { - size_t i, end = Py_MIN(n + 16, data_size); - fprintf(outfile, " "); - for (i = n; i < end; i++) { - fprintf(outfile, "%d,", (unsigned int) data[i]); - } - fprintf(outfile, "\n"); - } - fprintf(outfile, "};\n"); - - Py_DECREF(marshalled); - - Py_Finalize(); - if (infile) - fclose(infile); - if (outfile) { - if (ferror(outfile)) { - fprintf(stderr, "error when writing to '%s'\n", outpath); - fclose(outfile); - return 1; - } - fclose(outfile); - } - return 0; - -error: - PyErr_Print(); - Py_Finalize(); - if (infile) - fclose(infile); - if (outfile) - fclose(outfile); - return 1; -} diff -r 7a6a8a003553 -r 4c84f09bd8de Modules/_testembed.c --- a/Modules/_testembed.c Tue May 28 22:22:14 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -#include -#include - -void print_subinterp(void) -{ - /* Just output some debug stuff */ - PyThreadState *ts = PyThreadState_Get(); - printf("interp %p, thread state %p: ", ts->interp, ts); - fflush(stdout); - PyRun_SimpleString( - "import sys;" - "print('id(modules) =', id(sys.modules));" - "sys.stdout.flush()" - ); -} - -int main(int argc, char *argv[]) -{ - PyThreadState *mainstate, *substate; -#ifdef WITH_THREAD - PyGILState_STATE gilstate; -#endif - int i, j; - - for (i=0; i<3; i++) { - printf("--- Pass %d ---\n", i); - /* HACK: the "./" at front avoids a search along the PATH in - Modules/getpath.c */ - Py_SetProgramName(L"./_testembed"); - Py_Initialize(); - mainstate = PyThreadState_Get(); - -#ifdef WITH_THREAD - PyEval_InitThreads(); - PyEval_ReleaseThread(mainstate); - - gilstate = PyGILState_Ensure(); -#endif - print_subinterp(); - PyThreadState_Swap(NULL); - - for (j=0; j<3; j++) { - substate = Py_NewInterpreter(); - print_subinterp(); - Py_EndInterpreter(substate); - } - - PyThreadState_Swap(mainstate); - print_subinterp(); -#ifdef WITH_THREAD - PyGILState_Release(gilstate); -#endif - - PyEval_RestoreThread(mainstate); - Py_Finalize(); - } - return 0; -} diff -r 7a6a8a003553 -r 4c84f09bd8de Modules/python.c --- a/Modules/python.c Tue May 28 22:22:14 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* Minimal main program -- everything is loaded from the library */ - -#include "Python.h" -#include - -#ifdef __FreeBSD__ -#include -#endif - -#ifdef MS_WINDOWS -int -wmain(int argc, wchar_t **argv) -{ - return Py_Main(argc, argv); -} -#else - -int -main(int argc, char **argv) -{ - wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); - /* We need a second copies, as Python might modify the first one. */ - wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); - int i, res; - char *oldloc; - /* 754 requires that FP exceptions run in "no stop" mode by default, - * and until C vendors implement C99's ways to control FP exceptions, - * Python requires non-stop mode. Alas, some platforms enable FP - * exceptions by default. Here we disable them. - */ -#ifdef __FreeBSD__ - fp_except_t m; - - m = fpgetmask(); - fpsetmask(m & ~FP_X_OFL); -#endif - if (!argv_copy || !argv_copy2) { - fprintf(stderr, "out of memory\n"); - return 1; - } - oldloc = strdup(setlocale(LC_ALL, NULL)); - setlocale(LC_ALL, ""); - for (i = 0; i < argc; i++) { - argv_copy[i] = _Py_char2wchar(argv[i], NULL); - if (!argv_copy[i]) { - free(oldloc); - fprintf(stderr, "Fatal Python error: " - "unable to decode the command line argument #%i\n", - i + 1); - return 1; - } - argv_copy2[i] = argv_copy[i]; - } - argv_copy2[argc] = argv_copy[argc] = NULL; - - setlocale(LC_ALL, oldloc); - free(oldloc); - res = Py_Main(argc, argv_copy); - for (i = 0; i < argc; i++) { - PyMem_Free(argv_copy2[i]); - } - PyMem_Free(argv_copy); - PyMem_Free(argv_copy2); - return res; -} -#endif diff -r 7a6a8a003553 -r 4c84f09bd8de Objects/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Objects/README Wed May 29 21:45:16 2013 +1000 @@ -0,0 +1,1 @@ +Source files for various builtin objects diff -r 7a6a8a003553 -r 4c84f09bd8de PCbuild/_freeze_importlib.vcxproj --- a/PCbuild/_freeze_importlib.vcxproj Tue May 28 22:22:14 2013 -0400 +++ b/PCbuild/_freeze_importlib.vcxproj Wed May 29 21:45:16 2013 +1000 @@ -167,7 +167,7 @@ - + @@ -185,4 +185,4 @@ - \ No newline at end of file + diff -r 7a6a8a003553 -r 4c84f09bd8de PCbuild/_freeze_importlib.vcxproj.filters --- a/PCbuild/_freeze_importlib.vcxproj.filters Tue May 28 22:22:14 2013 -0400 +++ b/PCbuild/_freeze_importlib.vcxproj.filters Wed May 29 21:45:16 2013 +1000 @@ -15,7 +15,7 @@ - + Source Files @@ -24,4 +24,4 @@ Source Files - \ No newline at end of file + diff -r 7a6a8a003553 -r 4c84f09bd8de PCbuild/python.vcxproj --- a/PCbuild/python.vcxproj Tue May 28 22:22:14 2013 -0400 +++ b/PCbuild/python.vcxproj Wed May 29 21:45:16 2013 +1000 @@ -350,7 +350,7 @@ - + diff -r 7a6a8a003553 -r 4c84f09bd8de PCbuild/python.vcxproj.filters --- a/PCbuild/python.vcxproj.filters Tue May 28 22:22:14 2013 -0400 +++ b/PCbuild/python.vcxproj.filters Wed May 29 21:45:16 2013 +1000 @@ -19,8 +19,8 @@ - + Source Files - \ No newline at end of file + diff -r 7a6a8a003553 -r 4c84f09bd8de Programs/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Programs/README Wed May 29 21:45:16 2013 +1000 @@ -0,0 +1,1 @@ +Source files for binary executables (as opposed to shared modules) diff -r 7a6a8a003553 -r 4c84f09bd8de Programs/_freeze_importlib.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Programs/_freeze_importlib.c Wed May 29 21:45:16 2013 +1000 @@ -0,0 +1,142 @@ +/* This is built as a stand-alone executable by the Makefile, and helps turn + Lib/importlib/_bootstrap.py into a frozen module in Python/importlib.h +*/ + +#include +#include + +#include +#include +#include +#ifndef MS_WINDOWS +#include +#endif + + +/* To avoid a circular dependency on frozen.o, we create our own structure + of frozen modules instead, left deliberately blank so as to avoid + unintentional import of a stale version of _frozen_importlib. */ + +const static struct _frozen _PyImport_FrozenModules[] = { + {0, 0, 0} /* sentinel */ +}; + +#ifndef MS_WINDOWS +/* On Windows, this links with the regular pythonXY.dll, so this variable comes + from frozen.obj. In the Makefile, frozen.o is not linked into this executable, + so we define the variable here. */ +const struct _frozen *PyImport_FrozenModules; +#endif + +const char header[] = "/* Auto-generated by Modules/_freeze_importlib.c */"; + +int +main(int argc, char *argv[]) +{ + char *inpath, *outpath; + FILE *infile, *outfile = NULL; + struct stat st; + size_t text_size, data_size, n; + char *text; + unsigned char *data; + PyObject *code, *marshalled; + + PyImport_FrozenModules = _PyImport_FrozenModules; + + if (argc != 3) { + fprintf(stderr, "need to specify input and output paths\n"); + return 2; + } + inpath = argv[1]; + outpath = argv[2]; + infile = fopen(inpath, "rb"); + if (infile == NULL) { + fprintf(stderr, "cannot open '%s' for reading\n", inpath); + return 1; + } + if (fstat(fileno(infile), &st)) { + fclose(infile); + fprintf(stderr, "cannot fstat '%s'\n", inpath); + return 1; + } + text_size = st.st_size; + text = (char *) malloc(text_size + 1); + if (text == NULL) { + fclose(infile); + fprintf(stderr, "could not allocate %ld bytes\n", (long) text_size); + return 1; + } + n = fread(text, 1, text_size, infile); + fclose(infile); + infile = NULL; + if (n < text_size) { + fprintf(stderr, "read too short: got %ld instead of %ld bytes\n", + (long) n, (long) text_size); + return 1; + } + text[text_size] = '\0'; + + Py_NoUserSiteDirectory++; + Py_NoSiteFlag++; + Py_IgnoreEnvironmentFlag++; + + Py_SetProgramName(L"./_freeze_importlib"); + /* Don't install importlib, since it could execute outdated bytecode. */ + _Py_InitializeEx_Private(1, 0); + + code = Py_CompileStringExFlags(text, "", + Py_file_input, NULL, 0); + if (code == NULL) + goto error; + marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION); + Py_DECREF(code); + if (marshalled == NULL) + goto error; + + assert(PyBytes_CheckExact(marshalled)); + data = (unsigned char *) PyBytes_AS_STRING(marshalled); + data_size = PyBytes_GET_SIZE(marshalled); + + /* Open the file in text mode. The hg checkout should be using the eol extension, + which in turn should cause the EOL style match the C library's text mode */ + outfile = fopen(outpath, "w"); + if (outfile == NULL) { + fprintf(stderr, "cannot open '%s' for writing\n", outpath); + return 1; + } + fprintf(outfile, "%s\n", header); + fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n"); + for (n = 0; n < data_size; n += 16) { + size_t i, end = Py_MIN(n + 16, data_size); + fprintf(outfile, " "); + for (i = n; i < end; i++) { + fprintf(outfile, "%d,", (unsigned int) data[i]); + } + fprintf(outfile, "\n"); + } + fprintf(outfile, "};\n"); + + Py_DECREF(marshalled); + + Py_Finalize(); + if (infile) + fclose(infile); + if (outfile) { + if (ferror(outfile)) { + fprintf(stderr, "error when writing to '%s'\n", outpath); + fclose(outfile); + return 1; + } + fclose(outfile); + } + return 0; + +error: + PyErr_Print(); + Py_Finalize(); + if (infile) + fclose(infile); + if (outfile) + fclose(outfile); + return 1; +} diff -r 7a6a8a003553 -r 4c84f09bd8de Programs/_testembed.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Programs/_testembed.c Wed May 29 21:45:16 2013 +1000 @@ -0,0 +1,58 @@ +#include +#include + +void print_subinterp(void) +{ + /* Just output some debug stuff */ + PyThreadState *ts = PyThreadState_Get(); + printf("interp %p, thread state %p: ", ts->interp, ts); + fflush(stdout); + PyRun_SimpleString( + "import sys;" + "print('id(modules) =', id(sys.modules));" + "sys.stdout.flush()" + ); +} + +int main(int argc, char *argv[]) +{ + PyThreadState *mainstate, *substate; +#ifdef WITH_THREAD + PyGILState_STATE gilstate; +#endif + int i, j; + + for (i=0; i<3; i++) { + printf("--- Pass %d ---\n", i); + /* HACK: the "./" at front avoids a search along the PATH in + Modules/getpath.c */ + Py_SetProgramName(L"./_testembed"); + Py_Initialize(); + mainstate = PyThreadState_Get(); + +#ifdef WITH_THREAD + PyEval_InitThreads(); + PyEval_ReleaseThread(mainstate); + + gilstate = PyGILState_Ensure(); +#endif + print_subinterp(); + PyThreadState_Swap(NULL); + + for (j=0; j<3; j++) { + substate = Py_NewInterpreter(); + print_subinterp(); + Py_EndInterpreter(substate); + } + + PyThreadState_Swap(mainstate); + print_subinterp(); +#ifdef WITH_THREAD + PyGILState_Release(gilstate); +#endif + + PyEval_RestoreThread(mainstate); + Py_Finalize(); + } + return 0; +} diff -r 7a6a8a003553 -r 4c84f09bd8de Programs/python.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Programs/python.c Wed May 29 21:45:16 2013 +1000 @@ -0,0 +1,66 @@ +/* Minimal main program -- everything is loaded from the library */ + +#include "Python.h" +#include + +#ifdef __FreeBSD__ +#include +#endif + +#ifdef MS_WINDOWS +int +wmain(int argc, wchar_t **argv) +{ + return Py_Main(argc, argv); +} +#else + +int +main(int argc, char **argv) +{ + wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); + /* We need a second copies, as Python might modify the first one. */ + wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); + int i, res; + char *oldloc; + /* 754 requires that FP exceptions run in "no stop" mode by default, + * and until C vendors implement C99's ways to control FP exceptions, + * Python requires non-stop mode. Alas, some platforms enable FP + * exceptions by default. Here we disable them. + */ +#ifdef __FreeBSD__ + fp_except_t m; + + m = fpgetmask(); + fpsetmask(m & ~FP_X_OFL); +#endif + if (!argv_copy || !argv_copy2) { + fprintf(stderr, "out of memory\n"); + return 1; + } + oldloc = strdup(setlocale(LC_ALL, NULL)); + setlocale(LC_ALL, ""); + for (i = 0; i < argc; i++) { + argv_copy[i] = _Py_char2wchar(argv[i], NULL); + if (!argv_copy[i]) { + free(oldloc); + fprintf(stderr, "Fatal Python error: " + "unable to decode the command line argument #%i\n", + i + 1); + return 1; + } + argv_copy2[i] = argv_copy[i]; + } + argv_copy2[argc] = argv_copy[argc] = NULL; + + setlocale(LC_ALL, oldloc); + free(oldloc); + res = Py_Main(argc, argv_copy); + for (i = 0; i < argc; i++) { + PyMem_Free(argv_copy2[i]); + } + PyMem_Free(argv_copy); + PyMem_Free(argv_copy2); + return res; +} +#endif diff -r 7a6a8a003553 -r 4c84f09bd8de Python/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Python/README Wed May 29 21:45:16 2013 +1000 @@ -0,0 +1,1 @@ +Miscellaneous source files for the main Python shared library