Skip to content

Commit b9284ed

Browse files
author
Victor Stinner
committed
_sandbox: dictionary_of() calls PyType_Ready()
If the argument is a type object and if tp_dict is NULL.
1 parent 871cd93 commit b9284ed

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

_sandbox/module.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,31 @@ static PyObject *
8686
dictionary_of(PyObject *self, PyObject *args)
8787
{
8888
PyObject *obj, **dict_ptr, *dict;
89+
PyTypeObject *type;
8990

9091
if (!PyArg_ParseTuple(args, "O:dictionary_of", &obj))
9192
return NULL;
9293

93-
dict_ptr = _PyObject_GetDictPtr(obj);
94-
if (dict_ptr == NULL) {
95-
PyErr_SetString(sandbox_error, "Object has no dict");
96-
return NULL;
94+
if (PyType_Check(obj)) {
95+
type = (PyTypeObject*)obj;
96+
if (type->tp_dict == NULL) {
97+
if(PyType_Ready(type) < 0)
98+
return NULL;
99+
}
97100
}
101+
102+
dict_ptr = _PyObject_GetDictPtr(obj);
103+
if (dict_ptr == NULL)
104+
goto error;
98105
dict = *dict_ptr;
106+
if (dict == NULL)
107+
goto error;
99108
Py_INCREF(dict);
100109
return dict;
110+
111+
error:
112+
PyErr_SetString(sandbox_error, "Object has no dict");
113+
return NULL;
101114
}
102115

103116
static PyMethodDef sandbox_methods[] = {

0 commit comments

Comments
 (0)