Author: Devin Jeanpierre <jeanpierr...@gmail.com> Branch: cpyext-macros-cast Changeset: r84391:f1c7124eea15 Date: 2016-05-11 15:32 -0700 http://bitbucket.org/pypy/pypy/changeset/f1c7124eea15/
Log: Unwrapper: Don't require PyObject* for a void* param that isn't a w_foo. When it *is* a w_foo, we still require that they be either a real Python object or a PyObject*, of course, because there is no other meaning for a void* w_foo. diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -366,13 +366,22 @@ assert len(args) == len(api_function.argtypes) for i, (ARG, is_wrapped) in types_names_enum_ui: input_arg = args[i] - if (is_PyObject(ARG) or ARG == rffi.VOIDP) and not is_wrapped: + if is_PyObject(ARG) and not is_wrapped: # build a 'PyObject *' (not holding a reference) if not is_pyobj(input_arg): keepalives += (input_arg,) arg = rffi.cast(ARG, as_pyobj(space, input_arg)) else: arg = rffi.cast(ARG, input_arg) + elif ARG == rffi.VOIDP and not is_wrapped: + # unlike is_PyObject case above, we allow any kind of + # argument -- just, if it's an object, we assume the + # caller meant for it to become a PyObject*. + if input_arg is None or isinstance(input_arg, W_Root): + keepalives += (input_arg,) + arg = rffi.cast(ARG, as_pyobj(space, input_arg)) + else: + arg = rffi.cast(ARG, input_arg) elif (is_PyObject(ARG) or ARG == rffi.VOIDP) and is_wrapped: # build a W_Root, possibly from a 'PyObject *' if is_pyobj(input_arg): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit