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/Programs/test_frozenmain.h b/Programs/test_frozenmain.h index f77a16cf79ac75..3a6782bfa1abc4 100644 --- a/Programs/test_frozenmain.h +++ b/Programs/test_frozenmain.h @@ -1,29 +1,20 @@ // Auto-generated by Programs/freeze_test_frozenmain.py unsigned char M_test_frozenmain[] = { - 99,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0, + 99,250,1,0,0,11,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,7,0,0,0,0,0,0,0,1,0,0, - 0,90,8,60,109,111,100,117,108,101,62,90,8,60,109,111, - 100,117,108,101,62,122,18,116,101,115,116,95,102,114,111,122, - 101,110,109,97,105,110,46,112,121,115,86,0,0,0,100,0, - 100,1,108,0,90,0,100,0,100,1,108,1,90,1,101,2, - 100,2,131,1,1,0,101,2,100,3,101,0,106,3,131,2, - 1,0,101,1,106,4,131,0,100,4,25,0,90,5,100,5, - 68,0,93,14,90,6,101,2,100,6,101,6,155,0,100,7, - 101,5,101,6,25,0,155,0,157,4,131,1,1,0,113,26, - 100,1,83,0,41,8,105,0,0,0,0,78,122,18,70,114, - 111,122,101,110,32,72,101,108,108,111,32,87,111,114,108,100, - 122,8,115,121,115,46,97,114,103,118,90,6,99,111,110,102, - 105,103,41,5,90,12,112,114,111,103,114,97,109,95,110,97, - 109,101,90,10,101,120,101,99,117,116,97,98,108,101,90,15, - 117,115,101,95,101,110,118,105,114,111,110,109,101,110,116,90, - 17,99,111,110,102,105,103,117,114,101,95,99,95,115,116,100, - 105,111,90,14,98,117,102,102,101,114,101,100,95,115,116,100, - 105,111,122,7,99,111,110,102,105,103,32,122,2,58,32,41, - 7,90,3,115,121,115,90,17,95,116,101,115,116,105,110,116, - 101,114,110,97,108,99,97,112,105,90,5,112,114,105,110,116, - 90,4,97,114,103,118,90,11,103,101,116,95,99,111,110,102, - 105,103,115,90,6,99,111,110,102,105,103,90,3,107,101,121, - 41,0,115,0,0,0,0,115,16,0,0,0,8,3,8,1, + 0,218,8,60,109,111,100,117,108,101,62,114,0,0,0,0, + 250,18,116,101,115,116,95,102,114,111,122,101,110,109,97,105, + 110,46,112,121,115,86,0,0,0,100,0,100,1,108,0,90, + 0,100,0,100,1,108,1,90,1,101,2,100,2,131,1,1, + 0,101,2,100,3,101,0,106,3,131,2,1,0,101,1,106, + 4,131,0,100,4,25,0,90,5,100,5,68,0,93,14,90, + 6,101,2,100,6,101,6,155,0,100,7,101,5,101,6,25, + 0,155,0,157,4,131,1,1,0,113,26,100,1,83,0,41, + 7,218,3,115,121,115,90,17,95,116,101,115,116,105,110,116, + 101,114,110,97,108,99,97,112,105,218,5,112,114,105,110,116, + 218,4,97,114,103,118,90,11,103,101,116,95,99,111,110,102, + 105,103,115,218,6,99,111,110,102,105,103,218,3,107,101,121, + 169,0,243,0,0,0,0,115,16,0,0,0,8,3,8,1, 8,2,12,1,12,1,8,1,26,7,4,249,115,18,0,0, 0,8,3,8,1,8,2,12,1,12,1,2,7,4,1,2, 249,30,7,115,86,0,0,0,1,11,1,11,1,11,1,11, @@ -31,6 +22,14 @@ unsigned char M_test_frozenmain[] = { 1,6,7,17,19,22,19,27,1,28,1,28,10,27,10,39, 10,41,42,50,10,51,1,7,12,2,1,42,1,42,5,8, 5,10,11,41,21,24,11,41,11,41,28,34,35,38,28,39, - 11,41,11,41,5,42,5,42,5,42,1,42,1,42,115,0, - 0,0,0, + 11,41,11,41,5,42,5,42,5,42,1,42,1,42,114,8, + 0,0,0,41,8,233,0,0,0,0,78,122,18,70,114,111, + 122,101,110,32,72,101,108,108,111,32,87,111,114,108,100,122, + 8,115,121,115,46,97,114,103,118,114,5,0,0,0,41,5, + 90,12,112,114,111,103,114,97,109,95,110,97,109,101,218,10, + 101,120,101,99,117,116,97,98,108,101,90,15,117,115,101,95, + 101,110,118,105,114,111,110,109,101,110,116,90,17,99,111,110, + 102,105,103,117,114,101,95,99,95,115,116,100,105,111,90,14, + 98,117,102,102,101,114,101,100,95,115,116,100,105,111,122,7, + 99,111,110,102,105,103,32,122,2,58,32, }; 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,