aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2025-05-08 09:07:46 -0600
committerGitHub <noreply@github.com>2025-05-08 15:07:46 +0000
commitc81fa2b9cd1ed4d4ff5c13984d6582c27e5f2633 (patch)
treead0d56c7a551a8003c87a8b27fb2ebb4ec426470 /Python/pythonrun.c
parentf0f93ba5fa53ef5724250dd9f791d89abca04fa7 (diff)
downloadcpython-c81fa2b9cd1ed4d4ff5c13984d6582c27e5f2633.tar.gz
cpython-c81fa2b9cd1ed4d4ff5c13984d6582c27e5f2633.zip
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.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 4ee287af72f..f67b72aa91f 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -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)
{