Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 84502:65f2c92ed079
Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup()
Replace strdup() with _PyMem_RawStrdup() or _PyMem_Strdup(), depending if the
GIL is held or not.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Sun, 07 Jul 2013 23:30:24 +0200 |
| parents | 213d6d7f5979 |
| children | af18829a7754 |
comparison
equal
deleted
inserted
replaced
| 84501:31a635303e55 | 84502:65f2c92ed079 |
|---|---|
| 172 goto error; | 172 goto error; |
| 173 | 173 |
| 174 name_utf8 = _PyUnicode_AsString(name); | 174 name_utf8 = _PyUnicode_AsString(name); |
| 175 if (name_utf8 == NULL) | 175 if (name_utf8 == NULL) |
| 176 goto error; | 176 goto error; |
| 177 name_str = strdup(name_utf8); | 177 name_str = _PyMem_RawStrdup(name_utf8); |
| 178 Py_DECREF(name); | 178 Py_DECREF(name); |
| 179 if (name_str == NULL) { | 179 if (name_str == NULL) { |
| 180 PyErr_NoMemory(); | 180 PyErr_NoMemory(); |
| 181 return NULL; | 181 return NULL; |
| 182 } | 182 } |
| 624 /* Cleanup Unicode implementation */ | 624 /* Cleanup Unicode implementation */ |
| 625 _PyUnicode_Fini(); | 625 _PyUnicode_Fini(); |
| 626 | 626 |
| 627 /* reset file system default encoding */ | 627 /* reset file system default encoding */ |
| 628 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) { | 628 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) { |
| 629 free((char*)Py_FileSystemDefaultEncoding); | 629 PyMem_RawFree((char*)Py_FileSystemDefaultEncoding); |
| 630 Py_FileSystemDefaultEncoding = NULL; | 630 Py_FileSystemDefaultEncoding = NULL; |
| 631 } | 631 } |
| 632 | 632 |
| 633 /* XXX Still allocated: | 633 /* XXX Still allocated: |
| 634 - various static ad-hoc pointers to interned strings | 634 - various static ad-hoc pointers to interned strings |
| 1079 Py_DECREF(wrapper); | 1079 Py_DECREF(wrapper); |
| 1080 | 1080 |
| 1081 encoding = Py_GETENV("PYTHONIOENCODING"); | 1081 encoding = Py_GETENV("PYTHONIOENCODING"); |
| 1082 errors = NULL; | 1082 errors = NULL; |
| 1083 if (encoding) { | 1083 if (encoding) { |
| 1084 encoding = strdup(encoding); | 1084 encoding = _PyMem_Strdup(encoding); |
| 1085 if (encoding == NULL) { | |
| 1086 PyErr_NoMemory(); | |
| 1087 goto error; | |
| 1088 } | |
| 1085 errors = strchr(encoding, ':'); | 1089 errors = strchr(encoding, ':'); |
| 1086 if (errors) { | 1090 if (errors) { |
| 1087 *errors = '\0'; | 1091 *errors = '\0'; |
| 1088 errors++; | 1092 errors++; |
| 1089 } | 1093 } |
| 1138 | 1142 |
| 1139 /* Same as hack above, pre-import stderr's codec to avoid recursion | 1143 /* Same as hack above, pre-import stderr's codec to avoid recursion |
| 1140 when import.c tries to write to stderr in verbose mode. */ | 1144 when import.c tries to write to stderr in verbose mode. */ |
| 1141 encoding_attr = PyObject_GetAttrString(std, "encoding"); | 1145 encoding_attr = PyObject_GetAttrString(std, "encoding"); |
| 1142 if (encoding_attr != NULL) { | 1146 if (encoding_attr != NULL) { |
| 1143 const char * encoding; | 1147 const char * std_encoding; |
| 1144 encoding = _PyUnicode_AsString(encoding_attr); | 1148 std_encoding = _PyUnicode_AsString(encoding_attr); |
| 1145 if (encoding != NULL) { | 1149 if (std_encoding != NULL) { |
| 1146 PyObject *codec_info = _PyCodec_Lookup(encoding); | 1150 PyObject *codec_info = _PyCodec_Lookup(std_encoding); |
| 1147 Py_XDECREF(codec_info); | 1151 Py_XDECREF(codec_info); |
| 1148 } | 1152 } |
| 1149 Py_DECREF(encoding_attr); | 1153 Py_DECREF(encoding_attr); |
| 1150 } | 1154 } |
| 1151 PyErr_Clear(); /* Not a fatal error if codec isn't available */ | 1155 PyErr_Clear(); /* Not a fatal error if codec isn't available */ |
| 1158 if (0) { | 1162 if (0) { |
| 1159 error: | 1163 error: |
| 1160 status = -1; | 1164 status = -1; |
| 1161 } | 1165 } |
| 1162 | 1166 |
| 1163 if (encoding) | 1167 PyMem_Free(encoding); |
| 1164 free(encoding); | |
| 1165 Py_XDECREF(bimod); | 1168 Py_XDECREF(bimod); |
| 1166 Py_XDECREF(iomod); | 1169 Py_XDECREF(iomod); |
| 1167 return status; | 1170 return status; |
| 1168 } | 1171 } |
| 1169 | 1172 |
