Skip to content

Commit 206a375

Browse files
AdamWillhroncok
andcommitted
Fix build with Python 3.13+
Avoid using PyObject_AsReadBuffer, do what PyObject_AsReadBuffer does. Note that this is not safe, and it has never been safe, but the code does *exactly* what it used to do (at least on Python 3.8+). Fixes #362 Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
1 parent 7d9dfdf commit 206a375

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lmdb/cpython.c

+12
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,21 @@ val_from_buffer(MDB_val *val, PyObject *buf)
545545
type_error("Won't implicitly convert Unicode to bytes; use .encode()");
546546
return -1;
547547
}
548+
#if PY_VERSION_HEX < 0x030d0000
548549
return PyObject_AsReadBuffer(buf,
549550
(const void **) &val->mv_data,
550551
(Py_ssize_t *) &val->mv_size);
552+
#else
553+
Py_buffer view;
554+
int ret;
555+
ret = PyObject_GetBuffer(buf, &view, PyBUF_SIMPLE);
556+
if(ret == 0) {
557+
val->mv_data = view.buf;
558+
val->mv_size = view.len;
559+
PyBuffer_Release(&view);
560+
}
561+
return ret;
562+
#endif
551563
}
552564

553565
/* ------------------- */

0 commit comments

Comments
 (0)