Changeset 388 for python/vendor/current/Objects/exceptions.c
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Objects/exceptions.c
r2 r388 10 10 #include "osdefs.h" 11 11 12 #define MAKE_IT_NONE(x) (x) = Py_None; Py_INCREF(Py_None);13 12 #define EXC_MODULE_NAME "exceptions." 14 13 … … 219 218 {"__reduce__", (PyCFunction)BaseException_reduce, METH_NOARGS }, 220 219 {"__setstate__", (PyCFunction)BaseException_setstate, METH_O }, 221 #ifdef Py_USING_UNICODE 220 #ifdef Py_USING_UNICODE 222 221 {"__unicode__", (PyCFunction)BaseException_unicode, METH_NOARGS }, 223 222 #endif … … 238 237 static PyObject * 239 238 BaseException_getslice(PyBaseExceptionObject *self, 240 239 Py_ssize_t start, Py_ssize_t stop) 241 240 { 242 241 if (PyErr_WarnPy3k("__getslice__ not supported for exception " … … 308 307 } 309 308 seq = PySequence_Tuple(val); 310 if (!seq) return -1; 309 if (!seq) 310 return -1; 311 311 Py_CLEAR(self->args); 312 312 self->args = seq; … … 318 318 { 319 319 PyObject *msg; 320 320 321 321 /* if "message" is in self->dict, accessing a user-set message attribute */ 322 322 if (self->dict && … … 350 350 return -1; 351 351 } 352 Py_XDECREF(self->message); 353 self->message = NULL; 352 Py_CLEAR(self->message); 354 353 return 0; 355 354 } 356 355 357 356 /* else set it in __dict__, but may need to create the dict first */ 358 357 if (self->dict == NULL) { … … 368 367 {"args", (getter)BaseException_get_args, (setter)BaseException_set_args}, 369 368 {"message", (getter)BaseException_get_message, 370 369 (setter)BaseException_set_message}, 371 370 {NULL}, 372 371 }; … … 395 394 0, /*tp_as_buffer*/ 396 395 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | 397 396 Py_TPFLAGS_BASE_EXC_SUBCLASS, /*tp_flags*/ 398 397 PyDoc_STR("Common base class for all exceptions"), /* tp_doc */ 399 398 (traverseproc)BaseException_traverse, /* tp_traverse */ … … 775 774 if (PyTuple_GET_SIZE(args) == 2 && self->filename) { 776 775 args = PyTuple_New(3); 777 if (!args) return NULL; 776 if (!args) 777 return NULL; 778 778 779 779 tmp = PyTuple_GET_ITEM(self->args, 0); … … 1073 1073 info = PyTuple_GET_ITEM(args, 1); 1074 1074 info = PySequence_Tuple(info); 1075 if (!info) return -1; 1075 if (!info) 1076 return -1; 1076 1077 1077 1078 if (PyTuple_GET_SIZE(info) != 4) { … … 1169 1170 else 1170 1171 str = PyObject_Str(Py_None); 1171 if (!str) return NULL; 1172 if (!str) 1173 return NULL; 1172 1174 /* Don't fiddle with non-string return (shouldn't happen anyway) */ 1173 if (!PyString_Check(str)) return str; 1175 if (!PyString_Check(str)) 1176 return str; 1174 1177 1175 1178 /* XXX -- do all the additional formatting with filename and … … 1786 1789 Py_ssize_t start, Py_ssize_t end, const char *reason) 1787 1790 { 1788 assert(length < INT_MAX);1789 assert(start < INT_MAX);1790 assert(end < INT_MAX);1791 1791 return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#nns", 1792 1792 encoding, object, length, start, end, reason); … … 2050 2050 if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \ 2051 2051 Py_FatalError("Module dictionary insertion problem."); 2052 2053 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)2054 /* crt variable checking in VisualStudio .NET 2005 */2055 #include <crtdbg.h>2056 2057 static int prevCrtReportMode;2058 static _invalid_parameter_handler prevCrtHandler;2059 2060 /* Invalid parameter handler. Sets a ValueError exception */2061 static void2062 InvalidParameterHandler(2063 const wchar_t * expression,2064 const wchar_t * function,2065 const wchar_t * file,2066 unsigned int line,2067 uintptr_t pReserved)2068 {2069 /* Do nothing, allow execution to continue. Usually this2070 * means that the CRT will set errno to EINVAL2071 */2072 }2073 #endif2074 2052 2075 2053 … … 2138 2116 m = Py_InitModule4("exceptions", functions, exceptions_doc, 2139 2117 (PyObject *)NULL, PYTHON_API_VERSION); 2140 if (m == NULL) return; 2118 if (m == NULL) 2119 return; 2141 2120 2142 2121 bltinmod = PyImport_ImportModule("__builtin__"); … … 2206 2185 PyExc_MemoryErrorInst = BaseException_new(&_PyExc_MemoryError, NULL, NULL); 2207 2186 if (!PyExc_MemoryErrorInst) 2208 Py_FatalError("Cannot pre-allocate MemoryError instance \n");2187 Py_FatalError("Cannot pre-allocate MemoryError instance"); 2209 2188 2210 2189 PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL); 2211 2190 if (!PyExc_RecursionErrorInst) 2212 2213 2191 Py_FatalError("Cannot pre-allocate RuntimeError instance for " 2192 "recursion errors"); 2214 2193 else { 2215 PyBaseExceptionObject *err_inst = 2216 (PyBaseExceptionObject *)PyExc_RecursionErrorInst; 2217 PyObject *args_tuple; 2218 PyObject *exc_message; 2219 exc_message = PyString_FromString("maximum recursion depth exceeded"); 2220 if (!exc_message) 2221 Py_FatalError("cannot allocate argument for RuntimeError " 2222 "pre-allocation"); 2223 args_tuple = PyTuple_Pack(1, exc_message); 2224 if (!args_tuple) 2225 Py_FatalError("cannot allocate tuple for RuntimeError " 2226 "pre-allocation"); 2227 Py_DECREF(exc_message); 2228 if (BaseException_init(err_inst, args_tuple, NULL)) 2229 Py_FatalError("init of pre-allocated RuntimeError failed"); 2230 Py_DECREF(args_tuple); 2231 } 2232 2194 PyBaseExceptionObject *err_inst = 2195 (PyBaseExceptionObject *)PyExc_RecursionErrorInst; 2196 PyObject *args_tuple; 2197 PyObject *exc_message; 2198 exc_message = PyString_FromString("maximum recursion depth exceeded"); 2199 if (!exc_message) 2200 Py_FatalError("cannot allocate argument for RuntimeError " 2201 "pre-allocation"); 2202 args_tuple = PyTuple_Pack(1, exc_message); 2203 if (!args_tuple) 2204 Py_FatalError("cannot allocate tuple for RuntimeError " 2205 "pre-allocation"); 2206 Py_DECREF(exc_message); 2207 if (BaseException_init(err_inst, args_tuple, NULL)) 2208 Py_FatalError("init of pre-allocated RuntimeError failed"); 2209 Py_DECREF(args_tuple); 2210 } 2233 2211 Py_DECREF(bltinmod); 2234 2235 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)2236 /* Set CRT argument error handler */2237 prevCrtHandler = _set_invalid_parameter_handler(InvalidParameterHandler);2238 /* turn off assertions in debug mode */2239 prevCrtReportMode = _CrtSetReportMode(_CRT_ASSERT, 0);2240 #endif2241 2212 } 2242 2213 … … 2244 2215 _PyExc_Fini(void) 2245 2216 { 2246 Py_XDECREF(PyExc_MemoryErrorInst); 2247 PyExc_MemoryErrorInst = NULL; 2248 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) 2249 /* reset CRT error handling */ 2250 _set_invalid_parameter_handler(prevCrtHandler); 2251 _CrtSetReportMode(_CRT_ASSERT, prevCrtReportMode); 2252 #endif 2253 } 2217 Py_CLEAR(PyExc_MemoryErrorInst); 2218 Py_CLEAR(PyExc_RecursionErrorInst); 2219 }
Note:
See TracChangeset
for help on using the changeset viewer.