| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ static struct PyModuleDef thread_module; | |||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | 30 | typedef struct { | |
| 31 | + PyTypeObject *excepthook_type; | ||
| 31 | 32 | PyTypeObject *lock_type; | |
| 32 | 33 | PyTypeObject *local_type; | |
| 33 | 34 | PyTypeObject *local_dummy_type; | |
@@ -1473,8 +1474,6 @@ PyDoc_STRVAR(ExceptHookArgs__doc__, | |||
| 1473 | 1474 | \n\ | |
| 1474 | 1475 | Type used to pass arguments to threading.excepthook."); | |
| 1475 | 1476 | ||
| 1476 | - static PyTypeObject ExceptHookArgsType; | ||
| 1477 | - | ||
| 1478 | 1477 | static PyStructSequence_Field ExceptHookArgs_fields[] = { | |
| 1479 | 1478 | {"exc_type", "Exception type"}, | |
| 1480 | 1479 | {"exc_value", "Exception value"}, | |
@@ -1492,9 +1491,11 @@ static PyStructSequence_Desc ExceptHookArgs_desc = { | |||
| 1492 | 1491 | ||
| 1493 | 1492 | ||
| 1494 | 1493 | static PyObject * | |
| 1495 | - thread_excepthook(PyObject *self, PyObject *args) | ||
| 1494 | + thread_excepthook(PyObject *module, PyObject *args) | ||
| 1496 | 1495 | { | |
| 1497 | - if (!Py_IS_TYPE(args, &ExceptHookArgsType)) { | ||
| 1496 | + thread_module_state *state = get_thread_state(module); | ||
| 1497 | + | ||
| 1498 | + if (!Py_IS_TYPE(args, state->excepthook_type)) { | ||
| 1498 | 1499 | PyErr_SetString(PyExc_TypeError, | |
| 1499 | 1500 | "_thread.excepthook argument type " | |
| 1500 | 1501 | "must be ExceptHookArgs"); | |
@@ -1629,18 +1630,17 @@ thread_module_exec(PyObject *module) | |||
| 1629 | 1630 | return -1; | |
| 1630 | 1631 | } | |
| 1631 | 1632 | ||
| 1632 | - if (ExceptHookArgsType.tp_name == NULL) { | ||
| 1633 | - if (PyStructSequence_InitType2(&ExceptHookArgsType, | ||
| 1634 | - &ExceptHookArgs_desc) < 0) { | ||
| 1635 | - return -1; | ||
| 1636 | - } | ||
| 1637 | - } | ||
| 1638 | - | ||
| 1639 | 1633 | // Add module attributes | |
| 1640 | 1634 | if (PyDict_SetItemString(d, "error", ThreadError) < 0) { | |
| 1641 | 1635 | return -1; | |
| 1642 | 1636 | } | |
| 1643 | - if (PyModule_AddType(module, &ExceptHookArgsType) < 0) { | ||
| 1637 | + | ||
| 1638 | + // _ExceptHookArgs type | ||
| 1639 | + state->excepthook_type = PyStructSequence_NewType(&ExceptHookArgs_desc); | ||
| 1640 | + if (state->excepthook_type == NULL) { | ||
| 1641 | + return -1; | ||
| 1642 | + } | ||
| 1643 | + if (PyModule_AddType(module, state->excepthook_type) < 0) { | ||
| 1644 | 1644 | return -1; | |
| 1645 | 1645 | } | |
| 1646 | 1646 | ||
@@ -1664,6 +1664,7 @@ static int | |||
| 1664 | 1664 | thread_module_traverse(PyObject *module, visitproc visit, void *arg) | |
| 1665 | 1665 | { | |
| 1666 | 1666 | thread_module_state *state = get_thread_state(module); | |
| 1667 | + Py_VISIT(state->excepthook_type); | ||
| 1667 | 1668 | Py_VISIT(state->lock_type); | |
| 1668 | 1669 | Py_VISIT(state->local_type); | |
| 1669 | 1670 | Py_VISIT(state->local_dummy_type); | |
@@ -1674,6 +1675,7 @@ static int | |||
| 1674 | 1675 | thread_module_clear(PyObject *module) | |
| 1675 | 1676 | { | |
| 1676 | 1677 | thread_module_state *state = get_thread_state(module); | |
| 1678 | + Py_CLEAR(state->excepthook_type); | ||
| 1677 | 1679 | Py_CLEAR(state->lock_type); | |
| 1678 | 1680 | Py_CLEAR(state->local_type); | |
| 1679 | 1681 | Py_CLEAR(state->local_dummy_type); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments