FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-159739: Detect recursive untyped ctypes arguments by jelle-openai · Pull Request #160194 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions Lib/test/test_ctypes/test_as_parameter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL