databases/py-leveldb: Fix build with Python 3.12+

cc -fno-strict-overflow -Wsign-compare -Wunreachable-code -DNDEBUG -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -O2 -pipe -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -isystem /usr/local/include -fPIC -I/usr/local/include/python3.12 -c leveldb_object.cc -o build/temp.freebsd-15.0-RELEASE-p10-amd64-cpython-312/leveldb_object.o -I/usr/local/include -I. -fno-builtin-memcmp -O2 -fPIC -pthread -Wall -DOS_FREEBSD -DLEVELDB_PLATFORM_POSIX
leveldb_object.cc:795:19: error: use of undeclared identifier 'PyUnicode_AS_UNICODE'
  795 |                 Py_UNICODE* c = PyUnicode_AS_UNICODE(p);
      |                                 ^
1 error generated.
error: command '/usr/bin/cc' failed with exit code 1

ERROR Backend subprocess exited when trying to invoke build_wheel
*** Error code 1

Reference:	https://pkg-status.freebsd.org/beefy23/data/150amd64-default/a1fb4afca079/logs/py312-leveldb-0.201_1.log
This commit is contained in:
Po-Chuan Hsieh
2026-07-01 06:13:28 +08:00
parent 19ecf3de5e
commit 9cd647b604
@@ -1,5 +1,14 @@
--- leveldb_object.cc.orig 2016-12-27 23:03:15 UTC
+++ leveldb_object.cc
@@ -792,7 +792,7 @@ static int pyleveldb_str_eq(PyObject* p, const char* s
// unicode string
if (PyUnicode_Check(p)) {
size_t i = 0;
- Py_UNICODE* c = PyUnicode_AS_UNICODE(p);
+ const char* c = PyUnicode_AsUTF8(p);
while (s[i] && c[i] && (int)s[i] == (int)c[i])
i++;
@@ -901,9 +901,8 @@ static int PyLevelDB_init(PyLevelDB* sel
int block_size = 4096;
int max_open_files = 1000;