]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/python/src/exec.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / python / src / exec.cpp
index 171c6f4189b9cf051d1f13954d4143113a63a4d4..b2eabe59f617a9c91688255ec23aa808ffd29bcd 100644 (file)
@@ -104,14 +104,22 @@ object BOOST_PYTHON_DECL exec_file(char const *filename, object global, object l
   if (local.is_none()) local = global;
   // should be 'char const *' but older python versions don't use 'const' yet.
   char *f = const_cast<char *>(filename);
-  // Let python open the file to avoid potential binary incompatibilities.
-#if PY_VERSION_HEX >= 0x03040000
-  FILE *fs = _Py_fopen(f, "r");
+#if PY_VERSION_HEX >= 0x03010000
+  // Let python manage any UTF bits to avoid potential incompatibilities.
+  PyObject *fo = Py_BuildValue("s", f);
+  PyObject *fb = Py_None;
+  PyUnicode_FSConverter(fo, &fb);
+  f = PyBytes_AsString(fb);
+  FILE *fs = fopen(f, "r");
+  Py_DECREF(fo);
+  Py_DECREF(fb);
 #elif PY_VERSION_HEX >= 0x03000000
+  // Let python open the file to avoid potential binary incompatibilities.
   PyObject *fo = Py_BuildValue("s", f);
-  FILE *fs = _Py_fopen(fo, "r");
+  FILE *fs = _Py_fopen(fo, "r"); // Private CPython API
   Py_DECREF(fo);
 #else
+  // Let python open the file to avoid potential binary incompatibilities.
   PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
   if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");
   python::handle<> file(pyfile);