MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / PyDict_SetDefaultRef

Function PyDict_SetDefaultRef

asyncpg/protocol/record/pythoncapi_compat.h:1316–1351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1314// gh-114329 added PyList_GetItemRef() to Python 3.13.0a4
1315#if PY_VERSION_HEX < 0x030D00A4
1316static inline int
1317PyDict_SetDefaultRef(PyObject *d, PyObject *key, PyObject *default_value,
1318 PyObject **result)
1319{
1320 PyObject *value;
1321 if (PyDict_GetItemRef(d, key, &value) < 0) {
1322 // get error
1323 if (result) {
1324 *result = NULL;
1325 }
1326 return -1;
1327 }
1328 if (value != NULL) {
1329 // present
1330 if (result) {
1331 *result = value;
1332 }
1333 else {
1334 Py_DECREF(value);
1335 }
1336 return 1;
1337 }
1338
1339 // missing: set the item
1340 if (PyDict_SetItem(d, key, default_value) < 0) {
1341 // set error
1342 if (result) {
1343 *result = NULL;
1344 }
1345 return -1;
1346 }
1347 if (result) {
1348 *result = Py_NewRef(default_value);
1349 }
1350 return 0;
1351}
1352#endif
1353
1354#if PY_VERSION_HEX < 0x030D00B3

Callers

nothing calls this directly

Calls 1

PyDict_GetItemRefFunction · 0.85

Tested by

no test coverage detected