Mercurial > cpython-lru_cache-weakref
diff Objects/codeobject.c @ 65021:01b96f78fb70
Issue #9630: Redecode filenames when setting the filesystem encoding
Redecode the filenames of:
- all modules: __file__ and __path__ attributes
- all code objects: co_filename attribute
- sys.path
- sys.meta_path
- sys.executable
- sys.path_importer_cache (keys)
Keep weak references to all code objects until initfsencoding() is called, to
be able to redecode co_filename attribute of all code objects.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Wed, 29 Sep 2010 16:35:47 +0000 |
| parents | cab14be0ada1 |
| children | 453fd8182c2f |
line wrap: on
line diff
--- a/Objects/codeobject.c Wed Sep 29 16:19:50 2010 +0000 +++ b/Objects/codeobject.c Wed Sep 29 16:35:47 2010 +0000 @@ -5,6 +5,8 @@ #define NAME_CHARS \ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" +PyObject *_Py_code_object_list = NULL; + /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */ static int @@ -109,8 +111,23 @@ co->co_lnotab = lnotab; co->co_zombieframe = NULL; co->co_weakreflist = NULL; + + if (_Py_code_object_list != NULL) { + int err; + PyObject *ref = PyWeakref_NewRef((PyObject*)co, NULL); + if (ref == NULL) + goto error; + err = PyList_Append(_Py_code_object_list, ref); + Py_DECREF(ref); + if (err) + goto error; + } } return co; + +error: + Py_DECREF(co); + return NULL; } PyCodeObject *
