diff options
| author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-09-29 16:35:47 +0000 |
|---|---|---|
| committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-09-29 16:35:47 +0000 |
| commit | 82deba1f06f5dedc64fab78febbed063b4b8f85d (patch) | |
| tree | ecf52cf5eb8beee96b3a85bdab4aba1b65db3124 /Objects/codeobject.c | |
| parent | a55d1ebe5d82617988251c885c91d42c5938cfb0 (diff) | |
| download | cpython-82deba1f06f5dedc64fab78febbed063b4b8f85d.tar.gz | |
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.
Diffstat (limited to 'Objects/codeobject.c')
| -rw-r--r-- | Objects/codeobject.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c index da5c09ac8d..470bf56150 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -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 @@ PyCode_New(int argcount, int kwonlyargcount, 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 * |
