mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-132775: Add _PyCode_GetScriptXIData() (gh-133480)
This converts functions, code, str, bytes, bytearray, and memoryview objects to PyCodeObject, and ensure that the object looks like a script. That means no args, no return, and no closure. _PyCode_GetPureScriptXIData() takes it a step further and ensures there are no globals. We also add _PyObject_SupportedAsScript() to the internal C-API.
This commit is contained in:
parent
f0f93ba5fa
commit
c81fa2b9cd
8 changed files with 366 additions and 0 deletions
|
@ -1524,6 +1524,26 @@ Py_CompileStringExFlags(const char *str, const char *filename_str, int start,
|
|||
return co;
|
||||
}
|
||||
|
||||
int
|
||||
_PyObject_SupportedAsScript(PyObject *cmd)
|
||||
{
|
||||
if (PyUnicode_Check(cmd)) {
|
||||
return 1;
|
||||
}
|
||||
else if (PyBytes_Check(cmd)) {
|
||||
return 1;
|
||||
}
|
||||
else if (PyByteArray_Check(cmd)) {
|
||||
return 1;
|
||||
}
|
||||
else if (PyObject_CheckBuffer(cmd)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
_Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyCompilerFlags *cf, PyObject **cmd_copy)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue