-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails to build with Python 3.13 due to removal of PyObject_AsReadBuffer #362
Comments
So I can nearly fix this, but I'm struggling with the lifecycle of the view buffer
If you uncomment the I can't figure out a good way to handle this, because there are a lot of things that call |
Thanks for the heads up about 3.13. I haven't looked at that yet. I'm afraid This is a hard API break, and it probably means that the version that implements this will be the first version that doesn't support Python 2.7. You're welcome to submit a PR that implements this. If not, I'll work on it after I have my current 3.12 branch working. |
Thanks! That's more or less what I was talking about at the end of my message, I think. But - if I'm understanding things correctly - it's difficult because it doesn't seem like we're always done using the data even within the scope of the immediate caller of That seemed like a lot of work that would be very easy to get wrong for me, since I don't know the codebase and I'm not at all a C hacker, so I passed on trying to write a PR, sorry! |
NP at all. I appreciate the report. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Taking the patch by @AdamWill and not makign it crash is a matter of never releasing the buffer when the ret is not 0: --- a/lmdb/cpython.c
+++ b/lmdb/cpython.c
@@ -583,9 +583,15 @@ val_from_buffer(MDB_val *val, PyObject *buf)
type_error("Won't implicitly convert Unicode to bytes; use .encode()");
return -1;
}
- return PyObject_AsReadBuffer(buf,
- (const void **) &val->mv_data,
- (Py_ssize_t *) &val->mv_size);
+ Py_buffer view;
+ int ret;
+ ret = PyObject_GetBuffer(buf, &view, PyBUF_SIMPLE);
+ if(ret == 0) {
+ val->mv_data = view.buf;
+ val->mv_size = view.len;
+ PyBuffer_Release (&view);
+ }
+ return ret;
} It does exactly the same thing as Python, so calling PyBuffer_Release before reading the buf and len is as safe as it ever was (i.e. it is not safe, which is why Python removed the function in the first place, but it does not make things worse). |
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 jnwatson#362 Co-Authored-By: Miro Hrončok <[email protected]>
Fix in #368 |
For me the current pypi version 1.5.1 builds on Github actions with
but not with
I can see the API was removed. So I don't really understand why it still builds on Linux. |
Affected Operating Systems
All
Affected py-lmdb Version
All
py-lmdb Installation Method
Irrelevant
Using bundled or distribution-provided LMDB library?
Irrelevant
Distribution name and LMDB library version
Irrelevant
Machine "free -m" output
Irrelevant
Other important machine info
Irrelevant
Describe Your Problem
py-lmdb does not build against Python 3.13 because it uses
PyObject_AsReadBuffer
, which was removed in Python 3.13. The recommended replacement isPyObject_GetBuffer
andPyBuffer_Release
.Errors/exceptions Encountered
Describe What You Expected To Happen
Successful build.
Describe What Happened Instead
Failed build.
The text was updated successfully, but these errors were encountered: