|
6 | 6 | #include "cinderx/StaticPython/vtable.h" |
7 | 7 | #include "cinderx/StaticPython/vtable_builder.h" |
8 | 8 | #include "cinderx/UpstreamBorrow/borrowed.h" |
| 9 | +#include "cinderx/module_c_state.h" |
9 | 10 |
|
10 | 11 | #if PY_VERSION_HEX < 0x030C0000 |
11 | 12 | #include "cinder/exports.h" |
12 | 13 | #endif |
13 | 14 |
|
14 | | -static PyObject* genericinst_cache; |
15 | | - |
16 | 15 | void _PyClassLoader_ClearGenericTypes() { |
17 | | - Py_CLEAR(genericinst_cache); |
| 16 | + Ci_ClearGenericInstCache(); |
18 | 17 | } |
19 | 18 |
|
20 | 19 | static PyObject* get_optional_type(PyObject* type) { |
@@ -398,19 +397,22 @@ PyObject* _PyClassLoader_GetGenericInst( |
398 | 397 | PyObject* type, |
399 | 398 | PyObject** args, |
400 | 399 | Py_ssize_t nargs) { |
401 | | - if (genericinst_cache == NULL) { |
402 | | - genericinst_cache = PyDict_New(); |
403 | | - if (genericinst_cache == NULL) { |
| 400 | + PyObject* cache = Ci_GetGenericInstCache(); |
| 401 | + if (cache == NULL) { |
| 402 | + cache = PyDict_New(); |
| 403 | + if (cache == NULL) { |
404 | 404 | return NULL; |
405 | 405 | } |
| 406 | + Ci_SetGenericInstCache((PyDictObject*)cache); |
| 407 | + Py_DECREF(cache); |
406 | 408 | } |
407 | 409 |
|
408 | 410 | PyObject* key = gtd_make_key(type, args, nargs); |
409 | 411 | if (key == NULL) { |
410 | 412 | return NULL; |
411 | 413 | } |
412 | 414 |
|
413 | | - PyObject* inst = PyDict_GetItem(genericinst_cache, key); |
| 415 | + PyObject* inst = PyDict_GetItem(cache, key); |
414 | 416 | if (inst != NULL) { |
415 | 417 | Py_DECREF(key); |
416 | 418 | Py_INCREF(inst); |
@@ -442,7 +444,7 @@ PyObject* _PyClassLoader_GetGenericInst( |
442 | 444 | } |
443 | 445 | } |
444 | 446 |
|
445 | | - if (res == NULL || PyDict_SetItem(genericinst_cache, key, res)) { |
| 447 | + if (res == NULL || PyDict_SetItem(cache, key, res)) { |
446 | 448 | Py_XDECREF(res); |
447 | 449 | Py_DECREF(key); |
448 | 450 | return NULL; |
|
0 commit comments