diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index ac178fabcd2027..71c61af774094c 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -372,7 +372,7 @@ def _write_atomic(path, data, mode=0o666): # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array # in PC/launcher.c must also be updated. -MAGIC_NUMBER = (9994).to_bytes(2, 'little') + b'\r\n' +MAGIC_NUMBER = (9996).to_bytes(2, 'little') + b'\r\n' _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c _PYCACHE = '__pycache__' diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 278ee43860e112..ad889ddb288ce2 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -324,6 +324,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con) co->co_name = con->name; Py_INCREF(con->qualname); co->co_qualname = con->qualname; + co->co_flags = con->flags; Py_XINCREF(con->code); @@ -420,6 +421,10 @@ _PyCode_New(struct _PyCodeConstructor *con) PyErr_NoMemory(); return NULL; } + co->co_filename = NULL; + co->co_name = NULL; + co->co_qualname = NULL; + init_code(co, con); return co; @@ -442,7 +447,11 @@ _PyCode_Update(struct _PyCodeConstructor *con, PyCodeObject *code) con->columntable = Py_None; } - init_code(code, con); // TODO: This leaks! + Py_XDECREF(code->co_filename); + Py_XDECREF(code->co_name); + Py_XDECREF(code->co_qualname); + + init_code(code, con); return code; } diff --git a/Python/importlib_external.h b/Python/importlib_external.h index d87b1dc1204127..501465be220d24 100644 --- a/Python/importlib_external.h +++ b/Python/importlib_external.h @@ -591,7 +591,7 @@ const unsigned char _Py_M__importlib_bootstrap_external[] = { 32,32,32,32,116,101,109,112,111,114,97,114,121,32,102,105, 108,101,32,105,115,32,97,116,116,101,109,112,116,101,100,46, 250,5,123,125,46,123,125,114,146,0,0,0,90,2,119,98, - 78,105,10,39,0,0,114,115,0,0,0,114,109,0,0,0, + 78,105,12,39,0,0,114,115,0,0,0,114,109,0,0,0, 115,2,0,0,0,13,10,90,11,95,95,112,121,99,97,99, 104,101,95,95,122,4,111,112,116,45,122,3,46,112,121,122, 4,46,112,121,119,122,4,46,112,121,99,41,1,218,12,111,