Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use PyObject_GetBuffer() in _imp.get_frozen_object().
  • Loading branch information
ericsnowcurrently committed Oct 13, 2021
commit 4f5160ed135e167a44f70fb909081f176f54d658
21 changes: 12 additions & 9 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -2118,14 +2118,13 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject *name,
/*[clinic end generated code: output=54368a673a35e745 input=034bdb88f6460b7b]*/
{
struct frozen_info info = {};
if (PyBytes_Check(dataobj)) {
info.data = PyBytes_AS_STRING(dataobj);
info.size = PyBytes_Size(dataobj);
}
else if (PyMemoryView_Check(dataobj)) {
Py_buffer *buf = PyMemoryView_GET_BUFFER(dataobj);
info.data = (const char *)buf->buf;
info.size = buf->len;
Py_buffer buf = {};
if (PyObject_CheckBuffer(dataobj)) {
if (PyObject_GetBuffer(dataobj, &buf, PyBUF_READ) != 0) {
return NULL;
}
info.data = (const char *)buf.buf;
info.size = buf.len;
}
else if (dataobj != Py_None) {
_PyArg_BadArgument("get_frozen_object", "argument 2", "bytes", dataobj);
Expand All @@ -2147,7 +2146,11 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject *name,
return NULL;
}

return unmarshal_frozen_code(&info);
PyObject *codeobj = unmarshal_frozen_code(&info);
if (dataobj != Py_None) {
PyBuffer_Release(&buf);
}
return codeobj;
}

/*[clinic input]
Expand Down