Skip to content

Commit

Permalink
A 'PyObject *' parameter in PyErr_Format must use %S parameter, not %s.
Browse files Browse the repository at this point in the history
Added unittest for calling a function with paramflags.
  • Loading branch information
Thomas Heller committed Oct 24, 2007
1 parent bd1c68c commit 39013cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Lib/ctypes/test/test_prototypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ def setUp(self):
func.restype = c_long
func.argtypes = None

def test_paramflags(self):
# function returns c_void_p result,
# and has a required parameter named 'input'
prototype = CFUNCTYPE(c_void_p, c_void_p)
func = prototype(("_testfunc_p_p", testdll),
((1, "input"),))

try:
func()
except TypeError as details:
self.failUnlessEqual(str(details), "required argument 'input' missing")
else:
self.fail("TypeError not raised")

self.failUnlessEqual(func(None), None)
self.failUnlessEqual(func(input=None), None)


def test_int_pointer_arg(self):
func = testdll._testfunc_p_p
func.restype = c_long
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2992,7 +2992,7 @@ _get_arg(int *pindex, PyObject *name, PyObject *defval, PyObject *inargs, PyObje
/* we can't currently emit a better error message */
if (name)
PyErr_Format(PyExc_TypeError,
"required argument '%s' missing", name);
"required argument '%S' missing", name);
else
PyErr_Format(PyExc_TypeError,
"not enough arguments");
Expand Down

0 comments on commit 39013cd

Please sign in to comment.