comparison 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
comparison
equal deleted inserted replaced
65020:5936ec3c4ec0 65021:01b96f78fb70
2 #include "code.h" 2 #include "code.h"
3 #include "structmember.h" 3 #include "structmember.h"
4 4
5 #define NAME_CHARS \ 5 #define NAME_CHARS \
6 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" 6 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
7
8 PyObject *_Py_code_object_list = NULL;
7 9
8 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */ 10 /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
9 11
10 static int 12 static int
11 all_name_chars(Py_UNICODE *s) 13 all_name_chars(Py_UNICODE *s)
107 co->co_firstlineno = firstlineno; 109 co->co_firstlineno = firstlineno;
108 Py_INCREF(lnotab); 110 Py_INCREF(lnotab);
109 co->co_lnotab = lnotab; 111 co->co_lnotab = lnotab;
110 co->co_zombieframe = NULL; 112 co->co_zombieframe = NULL;
111 co->co_weakreflist = NULL; 113 co->co_weakreflist = NULL;
114
115 if (_Py_code_object_list != NULL) {
116 int err;
117 PyObject *ref = PyWeakref_NewRef((PyObject*)co, NULL);
118 if (ref == NULL)
119 goto error;
120 err = PyList_Append(_Py_code_object_list, ref);
121 Py_DECREF(ref);
122 if (err)
123 goto error;
124 }
112 } 125 }
113 return co; 126 return co;
127
128 error:
129 Py_DECREF(co);
130 return NULL;
114 } 131 }
115 132
116 PyCodeObject * 133 PyCodeObject *
117 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) 134 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
118 { 135 {