PyDict_SetDefaultRef was added in Python 3.13.0a4. See also: https://github.com/python/pythoncapi-compat/blob/main/pythoncapi_compat.h
| 1032 | // PyDict_SetDefaultRef was added in Python 3.13.0a4. |
| 1033 | // See also: https://github.com/python/pythoncapi-compat/blob/main/pythoncapi_compat.h |
| 1034 | inline PyObject *dict_setdefaultstringref(PyObject *v, const char *key, PyObject *defaultobj) { |
| 1035 | #if PY_VERSION_HEX >= 0x030D00A4 |
| 1036 | PyObject *kv = PyUnicode_FromString(key); |
| 1037 | if (kv == nullptr) { |
| 1038 | throw error_already_set(); |
| 1039 | } |
| 1040 | |
| 1041 | PyObject *rv = nullptr; |
| 1042 | if (PyDict_SetDefaultRef(v, kv, defaultobj, &rv) < 0) { |
| 1043 | Py_DECREF(kv); |
| 1044 | throw error_already_set(); |
| 1045 | } |
| 1046 | Py_DECREF(kv); |
| 1047 | return rv; |
| 1048 | #else |
| 1049 | PyObject *rv = dict_setdefaultstring(v, key, defaultobj); |
| 1050 | if (rv == nullptr || PyErr_Occurred()) { |
| 1051 | throw error_already_set(); |
| 1052 | } |
| 1053 | Py_XINCREF(rv); |
| 1054 | return rv; |
| 1055 | #endif |
| 1056 | } |
| 1057 | |
| 1058 | // Helper aliases/functions to support implicit casting of values given to python |
| 1059 | // accessors/methods. When given a pyobject, this simply returns the pyobject as-is; for other C++ |
nothing calls this directly
no test coverage detected