Commit 7e2cbb56 authored by Kevin Modzelewski's avatar Kevin Modzelewski

More attrwrapper-instead-of-dict support

Specifically, when passed to PyArg_ParseTuple when a dict argument
is asked for.
parent a20593e8
......@@ -619,6 +619,8 @@ int _PyArg_ParseSingle_SizeT(PyObject* obj, int arg_idx, const char* fname, cons
return r;
}
extern PyTypeObject* attrwrapper_cls;
/* Convert a non-tuple argument. Return NULL if conversion went OK,
or a string with a message describing the failure. The message is
formatted as "must be <desired type>, not <actual type>".
......@@ -1279,7 +1281,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
type = va_arg(*p_va, PyTypeObject*);
p = va_arg(*p_va, PyObject **);
format++;
if (PyType_IsSubtype(arg->ob_type, type))
if (PyType_IsSubtype(arg->ob_type, type) || /* Pyston hack */ (arg->ob_type == attrwrapper_cls && type == &PyDict_Type))
*p = arg;
else
return converterr(type->tp_name, arg, msgbuf, bufsize);
......
......@@ -6,8 +6,18 @@ set_size(PyObject *self, PyObject *so)
return Py_BuildValue("i", PySet_Size(so));
}
static PyObject*
test_attrwrapper_parse(PyObject *self, PyObject* args) {
PyObject* d;
int r = PyArg_ParseTuple(args, "O!", &PyDict_Type, &d);
if (!r)
return NULL;
Py_RETURN_NONE;
}
static PyMethodDef TestMethods[] = {
{"set_size", set_size, METH_O, "Get set size by PySet_Size." },
{"test_attrwrapper_parse", test_attrwrapper_parse, METH_VARARGS, "Test PyArg_ParseTuple for attrwrappers." },
{NULL, NULL, 0, NULL} /* Sentinel */
};
......
# import ctypes
#
# print ctypes.pythonapi.PyArg_ParseTuple(globals()
import api_test
api_test.test_attrwrapper_parse(globals())
def f():
pass
api_test.test_attrwrapper_parse(f.__dict__)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment