Skip to content

Commit

Permalink
[mypyc] Avoid uses of _PyObject_CallMethodOneArg on 3.13 (python#17526)
Browse files Browse the repository at this point in the history
It's no longer available in CPython 3.13 betas.

This fixes some dict primitives on 3.13.

Work on mypyc/mypyc#1056.
  • Loading branch information
JukkaL authored Aug 14, 2024
1 parent 8332c6e commit fe15ee6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mypyc/lib-rt/dict_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ PyObject *CPyDict_SetDefault(PyObject *dict, PyObject *key, PyObject *value) {
return ret;
}
_Py_IDENTIFIER(setdefault);
return _PyObject_CallMethodIdObjArgs(dict, &PyId_setdefault, key, value, NULL);
PyObject *name = _PyUnicode_FromId(&PyId_setdefault); /* borrowed */
if (name == NULL) {
return NULL;
}
return PyObject_CallMethodObjArgs(dict, name, key, value, NULL);
}

PyObject *CPyDict_SetDefaultWithNone(PyObject *dict, PyObject *key) {
Expand Down Expand Up @@ -133,7 +137,11 @@ static inline int CPy_ObjectToStatus(PyObject *obj) {

static int CPyDict_UpdateGeneral(PyObject *dict, PyObject *stuff) {
_Py_IDENTIFIER(update);
PyObject *res = _PyObject_CallMethodIdOneArg(dict, &PyId_update, stuff);
PyObject *name = _PyUnicode_FromId(&PyId_update); /* borrowed */
if (name == NULL) {
return -1;
}
PyObject *res = PyObject_CallMethodOneArg(dict, name, stuff);
return CPy_ObjectToStatus(res);
}

Expand Down
2 changes: 2 additions & 0 deletions mypyc/lib-rt/pythonsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ _CPyObject_HasAttrId(PyObject *v, _Py_Identifier *name) {
_PyObject_CallMethodIdObjArgs((self), (name), NULL)
#define _PyObject_CallMethodIdOneArg(self, name, arg) \
_PyObject_CallMethodIdObjArgs((self), (name), (arg), NULL)
#define PyObject_CallMethodOneArg(self, name, arg) \
PyObject_CallMethodObjArgs((self), (name), (arg), NULL)
#endif

#if CPY_3_13_FEATURES
Expand Down

0 comments on commit fe15ee6

Please sign in to comment.