Ticket #4657: boost-1.44-py3.1.patch
File boost-1.44-py3.1.patch, 2.9 KB (added by , 12 years ago) |
---|
-
libs/mpi/src/python/datatypes.cpp
diff -urN -x '*~' boost_1_44_0/libs/mpi/src/python/datatypes.cpp boost_1_44_0-hacked/libs/mpi/src/python/datatypes.cpp
old new 17 17 18 18 void export_datatypes() 19 19 { 20 #if PY_MAJOR_VERSION < 3 20 21 register_serialized(long(0), &PyInt_Type); 22 #endif 21 23 register_serialized(false, &PyBool_Type); 22 24 register_serialized(double(0.0), &PyFloat_Type); 23 25 } -
libs/mpi/src/python/py_environment.cpp
diff -urN -x '*~' boost_1_44_0/libs/mpi/src/python/py_environment.cpp boost_1_44_0-hacked/libs/mpi/src/python/py_environment.cpp
old new 11 11 * This file reflects the Boost.MPI "environment" class into Python 12 12 * methods at module level. 13 13 */ 14 15 #include <locale> 16 #include <string> 14 17 #include <boost/python.hpp> 15 18 #include <boost/mpi.hpp> 16 19 … … 50 53 51 54 // If anything changed, convert C-style argc/argv into Python argv 52 55 if (mpi_argv != my_argv) 56 { 57 #if PY_MAJOR_VERSION >= 3 58 // Code stolen from py3k/Modules/python.c. 59 60 wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*mpi_argc); 61 /* We need a second copies, as Python might modify the first one. */ 62 wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*mpi_argc); 63 64 if (!argv_copy || !argv_copy2) { 65 fprintf(stderr, "out of memory\n"); 66 return false; 67 } 68 69 std::locale mylocale; 70 mbstate_t mystate; 71 72 const std::codecvt<char, wchar_t, mbstate_t>& myfacet = 73 std::use_facet<std::codecvt<char, wchar_t, mbstate_t> >(mylocale); 74 75 for (int i = 0; i < mpi_argc; i++) 76 { 77 size_t length = strlen(mpi_argv[i]); 78 79 wchar_t *dest = (wchar_t *) PyMem_Malloc(sizeof(wchar_t) * (length + 1)); 80 81 const char *from_next; 82 wchar_t *to_next; 83 84 std::codecvt<wchar_t,char,mbstate_t>::result myresult = 85 myfacet.out(mystate, 86 mpi_argv[i], mpi_argv[i] + length + 1, from_next, 87 dest, dest+length+1, to_next); 88 89 if (myresult != std::codecvt<wchar_t,char,mbstate_t>::ok ) 90 { 91 fprintf(stderr, "failure translating argv\n"); 92 return 1; 93 } 94 95 argv_copy2[i] = argv_copy[i] = dest; 96 if (!argv_copy[i]) 97 return false; 98 } 99 100 PySys_SetArgv(mpi_argc, argv_copy); 101 102 for (int i = 0; i < mpi_argc; i++) { 103 PyMem_Free(argv_copy2[i]); 104 } 105 PyMem_Free(argv_copy); 106 PyMem_Free(argv_copy2); 107 #else 53 108 PySys_SetArgv(mpi_argc, mpi_argv); 109 #endif 110 } 54 111 55 for (int arg = 0; arg < m y_argc; ++arg)56 free(m y_argv[arg]);57 delete [] m y_argv;112 for (int arg = 0; arg < mpi_argc; ++arg) 113 free(mpi_argv[arg]); 114 delete [] mpi_argv; 58 115 59 116 return true; 60 117 }