Skip to content

Commit 855da31

Browse files
committed
[lldb/Interpreter] Relax Scripted Interface object creation requirements
Historically, some scripted extension would pass the embedded interpreter session dictionary as a argument of the extension initializer. In many cases, that argument ended up not being used but was still required for all new extension implementations. This patch relax this requirement by checking if the number of maximum positional argument is 1 argument more then the number of argument passed in the parameter pack, in which case it will pass the interpreter session dictionary with the rest of the arguments. If the implementation doesn't have it in the initializer, only the paramater pack is passed to it. Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 56ba282 commit 855da31

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,35 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
180180
llvm::Expected<PythonObject> expected_return_object =
181181
create_error("Resulting object is not initialized.");
182182

183-
std::apply(
184-
[&init, &expected_return_object](auto &&...args) {
185-
llvm::consumeError(expected_return_object.takeError());
186-
expected_return_object = init(args...);
187-
},
188-
transformed_args);
183+
// This relax the requirement on the number of argument for
184+
// initializing scripting extension if the size of the interface
185+
// parameter pack contains 1 less element than the extension maximum
186+
// number of positional arguments for this initializer.
187+
//
188+
// This addresses the cases where the embedded interpreter session
189+
// dictionary is passed to the extension initializer which is not used
190+
// most of the time.
191+
size_t num_args = sizeof...(Args);
192+
if (num_args != arg_info->max_positional_args) {
193+
if (num_args != arg_info->max_positional_args - 1)
194+
return create_error("Passed arguments ({0}) doesn't match the number "
195+
"of expected arguments ({1}).",
196+
num_args, arg_info->max_positional_args);
197+
198+
std::apply(
199+
[&init, &expected_return_object](auto &&...args) {
200+
llvm::consumeError(expected_return_object.takeError());
201+
expected_return_object = init(args...);
202+
},
203+
std::tuple_cat(transformed_args, std::make_tuple(dict)));
204+
} else {
205+
std::apply(
206+
[&init, &expected_return_object](auto &&...args) {
207+
llvm::consumeError(expected_return_object.takeError());
208+
expected_return_object = init(args...);
209+
},
210+
transformed_args);
211+
}
189212

190213
if (!expected_return_object)
191214
return expected_return_object.takeError();

lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class DummyStopHook:
11-
def __init__(self, target, args, internal_dict):
11+
def __init__(self, target, args):
1212
self.target = target
1313
self.args = args
1414

0 commit comments

Comments
 (0)