aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/import.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/Python/import.c b/Python/import.c
index 4bc1e518bf5..f2160928c4f 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2049,6 +2049,8 @@ _imp.find_frozen
name: unicode
/
+ *
+ withdata: bool = False
Return info about the corresponding frozen module (if there is one) or None.
@@ -2062,8 +2064,8 @@ The returned info (a 2-tuple):
[clinic start generated code]*/
static PyObject *
-_imp_find_frozen_impl(PyObject *module, PyObject *name)
-/*[clinic end generated code: output=3fd17da90d417e4e input=6aa7b9078a89280a]*/
+_imp_find_frozen_impl(PyObject *module, PyObject *name, int withdata)
+/*[clinic end generated code: output=8c1c3c7f925397a5 input=22a8847c201542fd]*/
{
struct frozen_info info;
frozen_status status = find_frozen(name, &info);
@@ -2078,9 +2080,12 @@ _imp_find_frozen_impl(PyObject *module, PyObject *name)
return NULL;
}
- PyObject *data = PyBytes_FromStringAndSize(info.data, info.size);
- if (data == NULL) {
- return NULL;
+ PyObject *data = NULL;
+ if (withdata) {
+ data = PyMemoryView_FromMemory((char *)info.data, info.size, PyBUF_READ);
+ if (data == NULL) {
+ return NULL;
+ }
}
PyObject *origname = NULL;
@@ -2092,11 +2097,11 @@ _imp_find_frozen_impl(PyObject *module, PyObject *name)
}
}
- PyObject *result = PyTuple_Pack(3, data,
+ PyObject *result = PyTuple_Pack(3, data ? data : Py_None,
info.is_package ? Py_True : Py_False,
origname ? origname : Py_None);
Py_XDECREF(origname);
- Py_DECREF(data);
+ Py_XDECREF(data);
return result;
}
@@ -2115,15 +2120,14 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject *name,
PyObject *dataobj)
/*[clinic end generated code: output=54368a673a35e745 input=034bdb88f6460b7b]*/
{
- struct frozen_info info;
- if (PyBytes_Check(dataobj)) {
- info.nameobj = name;
- info.data = PyBytes_AS_STRING(dataobj);
- info.size = PyBytes_Size(dataobj);
- if (info.size == 0) {
- set_frozen_error(FROZEN_INVALID, name);
+ struct frozen_info info = {0};
+ Py_buffer buf = {0};
+ 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);
@@ -2136,7 +2140,20 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject *name,
return NULL;
}
}
- return unmarshal_frozen_code(&info);
+
+ if (info.nameobj == NULL) {
+ info.nameobj = name;
+ }
+ if (info.size == 0) {
+ set_frozen_error(FROZEN_INVALID, name);
+ return NULL;
+ }
+
+ PyObject *codeobj = unmarshal_frozen_code(&info);
+ if (dataobj != Py_None) {
+ PyBuffer_Release(&buf);
+ }
+ return codeobj;
}
/*[clinic input]