Blob Blame History Raw
commit b4ad589d54e47277a7831b1e145507db30eb4f39
Author: Tom Hughes <tom@compton.nu>
Date:   Thu Jul 13 16:49:43 2023 +0100

    Fix python 3.12 compatibility issues

diff --git a/src/python_grid_utils.cpp b/src/python_grid_utils.cpp
index 1140b4fe6..7b545a21b 100644
--- a/src/python_grid_utils.cpp
+++ b/src/python_grid_utils.cpp
@@ -42,6 +42,7 @@
 #include "python_grid_utils.hpp"
 
 // stl
+#include <cwchar>
 #include <stdexcept>
 
 namespace mapnik {
@@ -67,7 +68,7 @@ void grid2utf(T const& grid_type,
     for (std::size_t y = 0; y < data.height(); ++y)
     {
         std::uint16_t idx = 0;
-        const std::unique_ptr<Py_UNICODE[]> line(new Py_UNICODE[array_size]);
+        const std::unique_ptr<wchar_t[]> line(new wchar_t[array_size]);
         typename T::value_type const* row = data.get_row(y);
         for (std::size_t x = 0; x < data.width(); ++x)
         {
@@ -93,19 +94,19 @@ void grid2utf(T const& grid_type,
                         keys[val] = codepoint;
                         key_order.push_back(val);
                     }
-                    line[idx++] = static_cast<Py_UNICODE>(codepoint);
+                    line[idx++] = static_cast<wchar_t>(codepoint);
                     ++codepoint;
                 }
                 else
                 {
-                    line[idx++] = static_cast<Py_UNICODE>(key_pos->second);
+                    line[idx++] = static_cast<wchar_t>(key_pos->second);
                 }
             }
             // else, shouldn't get here...
         }
         l.append(boost::python::object(
                      boost::python::handle<>(
-                         PyUnicode_FromUnicode(line.get(), array_size))));
+                         PyUnicode_FromWideChar(line.get(), array_size))));
     }
 }
 
@@ -130,7 +131,7 @@ void grid2utf(T const& grid_type,
     for (unsigned y = 0; y < grid_type.height(); y=y+resolution)
     {
         std::uint16_t idx = 0;
-        const std::unique_ptr<Py_UNICODE[]> line(new Py_UNICODE[array_size]);
+        const std::unique_ptr<wchar_t[]> line(new wchar_t[array_size]);
         mapnik::grid::value_type const* row = grid_type.get_row(y);
         for (unsigned x = 0; x < grid_type.width(); x=x+resolution)
         {
@@ -156,19 +157,19 @@ void grid2utf(T const& grid_type,
                         keys[val] = codepoint;
                         key_order.push_back(val);
                     }
-                    line[idx++] = static_cast<Py_UNICODE>(codepoint);
+                    line[idx++] = static_cast<wchar_t>(codepoint);
                     ++codepoint;
                 }
                 else
                 {
-                    line[idx++] = static_cast<Py_UNICODE>(key_pos->second);
+                    line[idx++] = static_cast<wchar_t>(key_pos->second);
                 }
             }
             // else, shouldn't get here...
         }
         l.append(boost::python::object(
                      boost::python::handle<>(
-                         PyUnicode_FromUnicode(line.get(), array_size))));
+                         PyUnicode_FromWideChar(line.get(), array_size))));
     }
 }