Skip to content

Commit f01610e

Browse files
pythongh-157217: Add mappingproxy accessor for dict_merge
1 parent 23180c5 commit f01610e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎Include/internal/pycore_descrobject.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ extern PyTypeObject _PyMethodWrapper_Type;
2424

2525
extern void *_PyMember_GetOffset(PyObject *, PyMemberDef *);
2626

27+
/* Return a borrowed reference to the mapping wrapped by a mappingproxy.
28+
* The struct layout matches mappingproxyobject in Objects/descrobject.c.
29+
*/
30+
static inline PyObject *
31+
_PyDictProxy_GetMapping(PyObject *op)
32+
{
33+
typedef struct {
34+
PyObject_HEAD
35+
PyObject *mapping;
36+
} _PyMappingProxyObject;
37+
assert(op != NULL);
38+
assert(PyObject_TypeCheck(op, &PyDictProxy_Type));
39+
return ((_PyMappingProxyObject *)op)->mapping;
40+
}
41+
2742
#ifdef __cplusplus
2843
}
2944
#endif

0 commit comments

Comments
 (0)