| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -271,8 +271,8 @@ extern void _PyDebug_PrintTotalRefs(void); | |||
| 271 | 271 | ||
| 272 | 272 | #ifdef Py_TRACE_REFS | |
| 273 | 273 | extern void _Py_AddToAllObjects(PyObject *op, int force); | |
| 274 | - extern void _Py_PrintReferences(PyInterpreterState *, FILE *); | ||
| 275 | - extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *); | ||
| 274 | + extern void _Py_PrintReferences(FILE *); | ||
| 275 | + extern void _Py_PrintReferenceAddresses(FILE *); | ||
| 276 | 276 | #endif | |
| 277 | 277 | ||
| 278 | 278 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,22 +11,17 @@ extern "C" { | |||
| 11 | 11 | struct _py_object_runtime_state { | |
| 12 | 12 | #ifdef Py_REF_DEBUG | |
| 13 | 13 | Py_ssize_t interpreter_leaks; | |
| 14 | - #endif | ||
| 14 | + #else | ||
| 15 | 15 | int _not_used; | |
| 16 | + #endif | ||
| 16 | 17 | }; | |
| 17 | 18 | ||
| 18 | 19 | struct _py_object_state { | |
| 19 | 20 | #ifdef Py_REF_DEBUG | |
| 20 | 21 | Py_ssize_t reftotal; | |
| 21 | - #endif | ||
| 22 | - #ifdef Py_TRACE_REFS | ||
| 23 | - /* Head of circular doubly-linked list of all objects. These are linked | ||
| 24 | - * together via the _ob_prev and _ob_next members of a PyObject, which | ||
| 25 | - * exist only in a Py_TRACE_REFS build. | ||
| 26 | - */ | ||
| 27 | - PyObject refchain; | ||
| 28 | - #endif | ||
| 22 | + #else | ||
| 29 | 23 | int _not_used; | |
| 24 | + #endif | ||
| 30 | 25 | }; | |
| 31 | 26 | ||
| 32 | 27 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,7 +101,6 @@ extern PyTypeObject _PyExc_MemoryError; | |||
| 101 | 101 | { .threshold = 10, }, \ | |
| 102 | 102 | }, \ | |
| 103 | 103 | }, \ | |
| 104 | - .object_state = _py_object_state_INIT(INTERP), \ | ||
| 105 | 104 | .dtoa = _dtoa_state_INIT(&(INTERP)), \ | |
| 106 | 105 | .dict_state = _dict_state_INIT, \ | |
| 107 | 106 | .func_state = { \ | |
@@ -131,16 +130,6 @@ extern PyTypeObject _PyExc_MemoryError; | |||
| 131 | 130 | .context_ver = 1, \ | |
| 132 | 131 | } | |
| 133 | 132 | ||
| 134 | - #ifdef Py_TRACE_REFS | ||
| 135 | - # define _py_object_state_INIT(INTERP) \ | ||
| 136 | - { \ | ||
| 137 | - .refchain = {&INTERP.object_state.refchain, &INTERP.object_state.refchain}, \ | ||
| 138 | - } | ||
| 139 | - #else | ||
| 140 | - # define _py_object_state_INIT(INTERP) \ | ||
| 141 | - { 0 } | ||
| 142 | - #endif | ||
| 143 | - | ||
| 144 | 133 | ||
| 145 | 134 | // global objects | |
| 146 | 135 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,8 +158,11 @@ _PyDebug_PrintTotalRefs(void) { | |||
| 158 | 158 | Do not call them otherwise, they do not initialize the object! */ | |
| 159 | 159 | ||
| 160 | 160 | #ifdef Py_TRACE_REFS | |
| 161 | - | ||
| 162 | - #define REFCHAIN(interp) &interp->object_state.refchain | ||
| 161 | + /* Head of circular doubly-linked list of all objects. These are linked | ||
| 162 | + * together via the _ob_prev and _ob_next members of a PyObject, which | ||
| 163 | + * exist only in a Py_TRACE_REFS build. | ||
| 164 | + */ | ||
| 165 | + static PyObject refchain = {&refchain, &refchain}; | ||
| 163 | 166 | ||
| 164 | 167 | /* Insert op at the front of the list of all objects. If force is true, | |
| 165 | 168 | * op is added even if _ob_prev and _ob_next are non-NULL already. If | |
@@ -184,11 +187,10 @@ _Py_AddToAllObjects(PyObject *op, int force) | |||
| 184 | 187 | } | |
| 185 | 188 | #endif | |
| 186 | 189 | if (force || op->_ob_prev == NULL) { | |
| 187 | - PyObject *refchain = REFCHAIN(_PyInterpreterState_GET()); | ||
| 188 | - op->_ob_next = refchain->_ob_next; | ||
| 189 | - op->_ob_prev = refchain; | ||
| 190 | - refchain->_ob_next->_ob_prev = op; | ||
| 191 | - refchain->_ob_next = op; | ||
| 190 | + op->_ob_next = refchain._ob_next; | ||
| 191 | + op->_ob_prev = &refchain; | ||
| 192 | + refchain._ob_next->_ob_prev = op; | ||
| 193 | + refchain._ob_next = op; | ||
| 192 | 194 | } | |
| 193 | 195 | } | |
| 194 | 196 | #endif /* Py_TRACE_REFS */ | |
@@ -2204,21 +2206,20 @@ _Py_ForgetReference(PyObject *op) | |||
| 2204 | 2206 | _PyObject_ASSERT_FAILED_MSG(op, "negative refcnt"); | |
| 2205 | 2207 | } | |
| 2206 | 2208 | ||
| 2207 | - PyObject *refchain = REFCHAIN(_PyInterpreterState_GET()); | ||
| 2208 | - if (op == refchain || | ||
| 2209 | + if (op == &refchain || | ||
| 2209 | 2210 | op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op) | |
| 2210 | 2211 | { | |
| 2211 | 2212 | _PyObject_ASSERT_FAILED_MSG(op, "invalid object chain"); | |
| 2212 | 2213 | } | |
| 2213 | 2214 | ||
| 2214 | 2215 | #ifdef SLOW_UNREF_CHECK | |
| 2215 | 2216 | PyObject *p; | |
| 2216 | - for (p = refchain->_ob_next; p != refchain; p = p->_ob_next) { | ||
| 2217 | + for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) { | ||
| 2217 | 2218 | if (p == op) { | |
| 2218 | 2219 | break; | |
| 2219 | 2220 | } | |
| 2220 | 2221 | } | |
| 2221 | - if (p == refchain) { | ||
| 2222 | + if (p == &refchain) { | ||
| 2222 | 2223 | /* Not found */ | |
| 2223 | 2224 | _PyObject_ASSERT_FAILED_MSG(op, | |
| 2224 | 2225 | "object not found in the objects list"); | |
@@ -2234,15 +2235,11 @@ _Py_ForgetReference(PyObject *op) | |||
| 2234 | 2235 | * interpreter must be in a healthy state. | |
| 2235 | 2236 | */ | |
| 2236 | 2237 | void | |
| 2237 | - _Py_PrintReferences(PyInterpreterState *interp, FILE *fp) | ||
| 2238 | + _Py_PrintReferences(FILE *fp) | ||
| 2238 | 2239 | { | |
| 2239 | 2240 | PyObject *op; | |
| 2240 | - if (interp == NULL) { | ||
| 2241 | - interp = _PyInterpreterState_Main(); | ||
| 2242 | - } | ||
| 2243 | 2241 | fprintf(fp, "Remaining objects:\n"); | |
| 2244 | - PyObject *refchain = REFCHAIN(interp); | ||
| 2245 | - for (op = refchain->_ob_next; op != refchain; op = op->_ob_next) { | ||
| 2242 | + for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) { | ||
| 2246 | 2243 | fprintf(fp, "%p [%zd] ", (void *)op, Py_REFCNT(op)); | |
| 2247 | 2244 | if (PyObject_Print(op, fp, 0) != 0) { | |
| 2248 | 2245 | PyErr_Clear(); | |
@@ -2254,42 +2251,34 @@ _Py_PrintReferences(PyInterpreterState *interp, FILE *fp) | |||
| 2254 | 2251 | /* Print the addresses of all live objects. Unlike _Py_PrintReferences, this | |
| 2255 | 2252 | * doesn't make any calls to the Python C API, so is always safe to call. | |
| 2256 | 2253 | */ | |
| 2257 | - // XXX This function is not safe to use if the interpreter has been | ||
| 2258 | - // freed or is in an unhealthy state (e.g. late in finalization). | ||
| 2259 | - // The call in Py_FinalizeEx() is okay since the main interpreter | ||
| 2260 | - // is statically allocated. | ||
| 2261 | 2254 | void | |
| 2262 | - _Py_PrintReferenceAddresses(PyInterpreterState *interp, FILE *fp) | ||
| 2255 | + _Py_PrintReferenceAddresses(FILE *fp) | ||
| 2263 | 2256 | { | |
| 2264 | 2257 | PyObject *op; | |
| 2265 | - PyObject *refchain = REFCHAIN(interp); | ||
| 2266 | 2258 | fprintf(fp, "Remaining object addresses:\n"); | |
| 2267 | - for (op = refchain->_ob_next; op != refchain; op = op->_ob_next) | ||
| 2259 | + for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) | ||
| 2268 | 2260 | fprintf(fp, "%p [%zd] %s\n", (void *)op, | |
| 2269 | 2261 | Py_REFCNT(op), Py_TYPE(op)->tp_name); | |
| 2270 | 2262 | } | |
| 2271 | 2263 | ||
| 2272 | - /* The implementation of sys.getobjects(). */ | ||
| 2273 | 2264 | PyObject * | |
| 2274 | 2265 | _Py_GetObjects(PyObject *self, PyObject *args) | |
| 2275 | 2266 | { | |
| 2276 | 2267 | int i, n; | |
| 2277 | 2268 | PyObject *t = NULL; | |
| 2278 | 2269 | PyObject *res, *op; | |
| 2279 | - PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
| 2280 | 2270 | ||
| 2281 | 2271 | if (!PyArg_ParseTuple(args, "i|O", &n, &t)) | |
| 2282 | 2272 | return NULL; | |
| 2283 | - PyObject *refchain = REFCHAIN(interp); | ||
| 2284 | - op = refchain->_ob_next; | ||
| 2273 | + op = refchain._ob_next; | ||
| 2285 | 2274 | res = PyList_New(0); | |
| 2286 | 2275 | if (res == NULL) | |
| 2287 | 2276 | return NULL; | |
| 2288 | - for (i = 0; (n == 0 || i < n) && op != refchain; i++) { | ||
| 2277 | + for (i = 0; (n == 0 || i < n) && op != &refchain; i++) { | ||
| 2289 | 2278 | while (op == self || op == args || op == res || op == t || | |
| 2290 | 2279 | (t != NULL && !Py_IS_TYPE(op, (PyTypeObject *) t))) { | |
| 2291 | 2280 | op = op->_ob_next; | |
| 2292 | - if (op == refchain) | ||
| 2281 | + if (op == &refchain) | ||
| 2293 | 2282 | return res; | |
| 2294 | 2283 | } | |
| 2295 | 2284 | if (PyList_Append(res, op) < 0) { | |
@@ -2301,8 +2290,6 @@ _Py_GetObjects(PyObject *self, PyObject *args) | |||
| 2301 | 2290 | return res; | |
| 2302 | 2291 | } | |
| 2303 | 2292 | ||
| 2304 | - #undef REFCHAIN | ||
| 2305 | - | ||
| 2306 | 2293 | #endif | |
| 2307 | 2294 | ||
| 2308 | 2295 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1920,11 +1920,11 @@ Py_FinalizeEx(void) | |||
| 1920 | 1920 | } | |
| 1921 | 1921 | ||
| 1922 | 1922 | if (dump_refs) { | |
| 1923 | - _Py_PrintReferences(tstate->interp, stderr); | ||
| 1923 | + _Py_PrintReferences(stderr); | ||
| 1924 | 1924 | } | |
| 1925 | 1925 | ||
| 1926 | 1926 | if (dump_refs_fp != NULL) { | |
| 1927 | - _Py_PrintReferences(tstate->interp, dump_refs_fp); | ||
| 1927 | + _Py_PrintReferences(dump_refs_fp); | ||
| 1928 | 1928 | } | |
| 1929 | 1929 | #endif /* Py_TRACE_REFS */ | |
| 1930 | 1930 | ||
@@ -1960,11 +1960,11 @@ Py_FinalizeEx(void) | |||
| 1960 | 1960 | */ | |
| 1961 | 1961 | ||
| 1962 | 1962 | if (dump_refs) { | |
| 1963 | - _Py_PrintReferenceAddresses(tstate->interp, stderr); | ||
| 1963 | + _Py_PrintReferenceAddresses(stderr); | ||
| 1964 | 1964 | } | |
| 1965 | 1965 | ||
| 1966 | 1966 | if (dump_refs_fp != NULL) { | |
| 1967 | - _Py_PrintReferenceAddresses(tstate->interp, dump_refs_fp); | ||
| 1967 | + _Py_PrintReferenceAddresses(dump_refs_fp); | ||
| 1968 | 1968 | fclose(dump_refs_fp); | |
| 1969 | 1969 | } | |
| 1970 | 1970 | #endif /* Py_TRACE_REFS */ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments