Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_ctypes/test_as_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ class A:
with self.assertRaises(RecursionError):
c_type.from_param(a)

function = CDLL(_ctypes_test.__file__)._testfunc_p_p
with self.assertRaisesRegex(ArgumentError, 'RecursionError'):
function(a)


class AsParamWrapper:
def __init__(self, param):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Detect recursive ``_as_parameter_`` chains for :mod:`ctypes` calls without argument types.
9 changes: 7 additions & 2 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module _ctypes
#define DONT_USE_SEH
#endif

#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "pycore_runtime.h" // _PyRuntime
#include "pycore_global_objects.h"// _Py_ID()
#include "pycore_traceback.h" // _PyTraceback_Add()
Expand Down Expand Up @@ -795,8 +796,12 @@ static int ConvParam(ctypes_state *st,
attribute)
*/
if (arg) {
int result;
result = ConvParam(st, arg, index, pa);
if (_Py_EnterRecursiveCall(" while processing _as_parameter_")) {
Py_DECREF(arg);
return -1;
}
int result = ConvParam(st, arg, index, pa);
_Py_LeaveRecursiveCall();
Py_DECREF(arg);
return result;
}
Expand Down
Loading