Ticket #41568: patch-boost.diff

File patch-boost.diff, 3.7 KB (added by mamoll (Mark Moll), 11 years ago)
  • Portfile

     
    178178    set v [string index ${s} 0].[string index ${s} 1]
    179179    set i [lsearch -exact ${pythons_ports} ${p}]
    180180    set c [lreplace ${pythons_ports} ${i} ${i}]
    181     # patch for boost.python from
    182     # https://raw.github.com/archlinuxarm/PKGBUILDs/master/extra/boost/boost-1.53.0-python3.patch
    183     # see also https://svn.boost.org/trac/boost/ticket/4657)
    184181    if { ${s} > 30 } { set bppatch "patch-boost-python3.diff" } else { set bppatch "" }
    185182    eval [subst {
    186183        variant ${p} description "Build Boost.Python for Python ${v}" conflicts ${c} debug {
  • files/patch-boost-python3.diff

     
    1212 namespace boost { namespace mpi { namespace python {
    1313 
    1414 void export_datatypes()
    15 diff -Naur libs/mpi/src/python/py_environment.cpp libs/mpi/src/python/py_environment.cpp
    16 --- libs/mpi/src/python/py_environment.cpp      2007-11-25 13:38:02.000000000 -0500
    17 +++ libs/mpi/src/python/py_environment.cpp      2013-03-11 21:02:12.961737401 -0400
    18 @@ -11,6 +11,9 @@
    19   *  This file reflects the Boost.MPI "environment" class into Python
    20   *  methods at module level.
    21   */
    22 +
    23 +#include <locale>
    24 +#include <string>
    25  #include <boost/python.hpp>
    26  #include <boost/mpi.hpp>
    27  
    28 @@ -50,11 +53,65 @@
    29  
    30    // If anything changed, convert C-style argc/argv into Python argv
    31    if (mpi_argv != my_argv)
    32 +  {
    33 +#if PY_MAJOR_VERSION >= 3
    34 +    // Code stolen from py3k/Modules/python.c.
    35 +
    36 +    wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*mpi_argc);
    37 +    /* We need a second copies, as Python might modify the first one. */
    38 +    wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*mpi_argc);
    39 +
    40 +    if (!argv_copy || !argv_copy2) {
    41 +      fprintf(stderr, "out of memory\n");
    42 +      return false;
    43 +    }
    44 +
    45 +    std::locale mylocale;
    46 +    mbstate_t mystate;
    47 +
    48 +    const std::codecvt<char, wchar_t, mbstate_t>& myfacet =
    49 +      std::use_facet<std::codecvt<char, wchar_t, mbstate_t> >(mylocale);
    50 +
    51 +    for (int i = 0; i < mpi_argc; i++)
    52 +    {
    53 +      size_t length = strlen(mpi_argv[i]);
    54 +
    55 +      wchar_t *dest = (wchar_t *) PyMem_Malloc(sizeof(wchar_t) * (length + 1));
    56 +
    57 +      const char *from_next;
    58 +      wchar_t *to_next;
    59 +
    60 +      std::codecvt<wchar_t,char,mbstate_t>::result myresult =
    61 +        myfacet.out(mystate,
    62 +            mpi_argv[i], mpi_argv[i] + length + 1, from_next,
    63 +            dest, dest+length+1, to_next);
    64 +
    65 +      if (myresult != std::codecvt<wchar_t,char,mbstate_t>::ok )
    66 +      {
    67 +        fprintf(stderr, "failure translating argv\n");
    68 +        return 1;
    69 +      }
    70 +
    71 +      argv_copy2[i] = argv_copy[i] = dest;
    72 +      if (!argv_copy[i])
    73 +          return false;
    74 +    }
    75 +
    76 +    PySys_SetArgv(mpi_argc, argv_copy);
    77 +
    78 +    for (int i = 0; i < mpi_argc; i++) {
    79 +        PyMem_Free(argv_copy2[i]);
    80 +    }
    81 +    PyMem_Free(argv_copy);
    82 +    PyMem_Free(argv_copy2);
    83 +#else
    84      PySys_SetArgv(mpi_argc, mpi_argv);
    85 +#endif
    86 +  }
    87  
    88 -  for (int arg = 0; arg < my_argc; ++arg)
    89 -    free(my_argv[arg]);
    90 -  delete [] my_argv;
    91 +  for (int arg = 0; arg < mpi_argc; ++arg)
    92 +    free(mpi_argv[arg]);
    93 +  delete [] mpi_argv;
    94  
    95    return true;
    96  }
     15diff -Naur libs/mpi/build/__init__.py llibs/mpi/build/__init__.py
     16--- libs/mpi/build/__init__.py  2013-11-27 12:52:37.000000000 -0600
     17+++ libs/mpi/build/__init__.py  2013-11-27 12:52:55.000000000 -0600
     18@@ -6,5 +6,5 @@
     19     import mpi
     20     sys.setdlopenflags(flags)
     21 else:
     22-    import mpi
     23+    from . import mpi