summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-02-26 16:35:03 (GMT)
committerGitHub <noreply@github.com>2022-02-26 16:35:03 (GMT)
commit0d9b565e62a5fc8c3e9b8c64cce764fe084ccb2b (patch)
tree240f3538d78b4f390b97fc1e0a2c1e17102f0d49
parentedbee56d698ebb4489aa68311f44d104a23f5eb7 (diff)
downloadcpython-0d9b565e62a5fc8c3e9b8c64cce764fe084ccb2b.zip
cpython-0d9b565e62a5fc8c3e9b8c64cce764fe084ccb2b.tar.gz
cpython-0d9b565e62a5fc8c3e9b8c64cce764fe084ccb2b.tar.bz2
Propagate errors (however unlikely) from _Py_Deepfreeze_Init() (GH-31596)
-rw-r--r--Include/internal/pycore_code.h2
-rw-r--r--Include/internal/pycore_pylifecycle.h2
-rw-r--r--Objects/codeobject.c16
-rw-r--r--Programs/_bootstrap_python.c3
-rw-r--r--Programs/_freeze_module.c3
-rw-r--r--Python/pylifecycle.c4
-rw-r--r--Tools/scripts/deepfreeze.py8
7 files changed, 25 insertions, 13 deletions
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index d83df5e..0c4850f 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -317,7 +317,7 @@ extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
/* Deallocator function for static codeobjects used in deepfreeze.py */
extern void _PyStaticCode_Dealloc(PyCodeObject *co);
/* Function to intern strings of codeobjects */
-extern void _PyStaticCode_InternStrings(PyCodeObject *co);
+extern int _PyStaticCode_InternStrings(PyCodeObject *co);
#ifdef Py_STATS
diff --git a/Include/internal/pycore_pylifecycle.h b/Include/internal/pycore_pylifecycle.h
index 00d13b8..295505f 100644
--- a/Include/internal/pycore_pylifecycle.h
+++ b/Include/internal/pycore_pylifecycle.h
@@ -65,7 +65,7 @@ extern PyStatus _Py_HashRandomization_Init(const PyConfig *);
extern PyStatus _PyImportZip_Init(PyThreadState *tstate);
extern PyStatus _PyGC_Init(PyInterpreterState *interp);
extern PyStatus _PyAtExit_Init(PyInterpreterState *interp);
-extern void _Py_Deepfreeze_Init(void);
+extern int _Py_Deepfreeze_Init(void);
/* Various internal finalizers */
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index f947595..5a87e6c 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -1931,14 +1931,20 @@ _PyStaticCode_Dealloc(PyCodeObject *co)
}
}
-void
+int
_PyStaticCode_InternStrings(PyCodeObject *co)
{
int res = intern_strings(co->co_names);
- assert(res == 0);
+ if (res < 0) {
+ return -1;
+ }
res = intern_string_constants(co->co_consts, NULL);
- assert(res == 0);
+ if (res < 0) {
+ return -1;
+ }
res = intern_strings(co->co_localsplusnames);
- assert(res == 0);
- (void)res;
+ if (res < 0) {
+ return -1;
+ }
+ return 0;
}
diff --git a/Programs/_bootstrap_python.c b/Programs/_bootstrap_python.c
index 75d455c..f6b49c8 100644
--- a/Programs/_bootstrap_python.c
+++ b/Programs/_bootstrap_python.c
@@ -15,8 +15,9 @@
/* End includes */
/* Empty initializer for deepfrozen modules */
-void _Py_Deepfreeze_Init(void)
+int _Py_Deepfreeze_Init(void)
{
+ return 0;
}
/* Empty finalizer for deepfrozen modules */
void
diff --git a/Programs/_freeze_module.c b/Programs/_freeze_module.c
index d5a236a..3d27b79 100644
--- a/Programs/_freeze_module.c
+++ b/Programs/_freeze_module.c
@@ -23,8 +23,9 @@
#endif
/* Empty initializer for deepfrozen modules */
-void _Py_Deepfreeze_Init(void)
+int _Py_Deepfreeze_Init(void)
{
+ return 0;
}
/* Empty finalizer for deepfrozen modules */
void
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index a671bca..6153474 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -828,7 +828,9 @@ pycore_interp_init(PyThreadState *tstate)
}
// Intern strings in deep-frozen modules first so that others
// can use it instead of creating a heap allocated string.
- _Py_Deepfreeze_Init();
+ if (_Py_Deepfreeze_Init() < 0) {
+ return _PyStatus_ERR("failed to initialize deep-frozen modules");
+ }
status = pycore_init_types(interp);
if (_PyStatus_EXCEPTION(status)) {
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index 8ea232f..cdd34dd 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -283,7 +283,7 @@ class Printer:
self.write(f".co_cellvars = {co_cellvars},")
self.write(f".co_freevars = {co_freevars},")
self.deallocs.append(f"_PyStaticCode_Dealloc(&{name});")
- self.interns.append(f"_PyStaticCode_InternStrings(&{name});")
+ self.interns.append(f"_PyStaticCode_InternStrings(&{name})")
return f"& {name}.ob_base"
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
@@ -450,9 +450,11 @@ def generate(args: list[str], output: TextIO) -> None:
with printer.block(f"void\n_Py_Deepfreeze_Fini(void)"):
for p in printer.deallocs:
printer.write(p)
- with printer.block(f"void\n_Py_Deepfreeze_Init(void)"):
+ with printer.block(f"int\n_Py_Deepfreeze_Init(void)"):
for p in printer.interns:
- printer.write(p)
+ with printer.block(f"if ({p} < 0)"):
+ printer.write("return -1;")
+ printer.write("return 0;")
if verbose:
print(f"Cache hits: {printer.hits}, misses: {printer.misses}")