@@ -152,12 +152,12 @@ bool lldb_private::LLDBSwigPythonCallTypeScript(
152
152
return true;
153
153
}
154
154
155
- void * lldb_private::LLDBSwigPythonCreateSyntheticProvider(
155
+ PythonObject lldb_private::LLDBSwigPythonCreateSyntheticProvider(
156
156
const char *python_class_name, const char *session_dictionary_name,
157
157
const lldb::ValueObjectSP &valobj_sp) {
158
158
if (python_class_name == NULL || python_class_name[0] == '\0' ||
159
159
!session_dictionary_name)
160
- Py_RETURN_NONE ;
160
+ return PythonObject() ;
161
161
162
162
PyErr_Cleaner py_err_cleaner(true);
163
163
@@ -167,29 +167,29 @@ void *lldb_private::LLDBSwigPythonCreateSyntheticProvider(
167
167
python_class_name, dict);
168
168
169
169
if (!pfunc.IsAllocated())
170
- Py_RETURN_NONE ;
170
+ return PythonObject() ;
171
171
172
172
auto sb_value = std::make_unique<lldb::SBValue>(valobj_sp);
173
173
sb_value->SetPreferSyntheticValue(false);
174
174
175
175
PythonObject val_arg = ToSWIGWrapper(std::move(sb_value));
176
176
if (!val_arg.IsAllocated())
177
- Py_RETURN_NONE ;
177
+ return PythonObject() ;
178
178
179
179
PythonObject result = pfunc(val_arg, dict);
180
180
181
181
if (result.IsAllocated())
182
- return result.release() ;
182
+ return result;
183
183
184
- Py_RETURN_NONE ;
184
+ return PythonObject() ;
185
185
}
186
186
187
- void * lldb_private::LLDBSwigPythonCreateCommandObject(
187
+ PythonObject lldb_private::LLDBSwigPythonCreateCommandObject(
188
188
const char *python_class_name, const char *session_dictionary_name,
189
189
lldb::DebuggerSP debugger_sp) {
190
190
if (python_class_name == NULL || python_class_name[0] == '\0' ||
191
191
!session_dictionary_name)
192
- Py_RETURN_NONE ;
192
+ return PythonObject() ;
193
193
194
194
PyErr_Cleaner py_err_cleaner(true);
195
195
auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(
@@ -198,24 +198,19 @@ void *lldb_private::LLDBSwigPythonCreateCommandObject(
198
198
python_class_name, dict);
199
199
200
200
if (!pfunc.IsAllocated())
201
- return nullptr;
202
-
203
- PythonObject result = pfunc(ToSWIGWrapper(std::move(debugger_sp)), dict);
201
+ return PythonObject();
204
202
205
- if (result.IsAllocated())
206
- return result.release();
207
-
208
- Py_RETURN_NONE;
203
+ return pfunc(ToSWIGWrapper(std::move(debugger_sp)), dict);
209
204
}
210
205
211
- void * lldb_private::LLDBSwigPythonCreateScriptedProcess(
206
+ PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
212
207
const char *python_class_name, const char *session_dictionary_name,
213
208
const lldb::TargetSP &target_sp,
214
209
const lldb_private::StructuredDataImpl &args_impl,
215
210
std::string &error_string) {
216
211
if (python_class_name == NULL || python_class_name[0] == '\0' ||
217
212
!session_dictionary_name)
218
- Py_RETURN_NONE ;
213
+ return PythonObject() ;
219
214
220
215
PyErr_Cleaner py_err_cleaner(true);
221
216
@@ -227,7 +222,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
227
222
if (!pfunc.IsAllocated()) {
228
223
error_string.append("could not find script class: ");
229
224
error_string.append(python_class_name);
230
- return nullptr ;
225
+ return PythonObject() ;
231
226
}
232
227
233
228
PythonObject target_arg = ToSWIGWrapper(target_sp);
@@ -240,7 +235,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
240
235
[&](const llvm::ErrorInfoBase &E) {
241
236
error_string.append(E.message());
242
237
});
243
- Py_RETURN_NONE ;
238
+ return PythonObject() ;
244
239
}
245
240
246
241
PythonObject result = {};
@@ -249,21 +244,17 @@ void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
249
244
} else {
250
245
error_string.assign("wrong number of arguments in __init__, should be 2 "
251
246
"(not including self)");
252
- Py_RETURN_NONE;
253
247
}
254
-
255
- if (result.IsAllocated())
256
- return result.release();
257
- Py_RETURN_NONE;
248
+ return result;
258
249
}
259
250
260
- void * lldb_private::LLDBSwigPythonCreateScriptedThread(
251
+ PythonObject lldb_private::LLDBSwigPythonCreateScriptedThread(
261
252
const char *python_class_name, const char *session_dictionary_name,
262
253
const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
263
254
std::string &error_string) {
264
255
if (python_class_name == NULL || python_class_name[0] == '\0' ||
265
256
!session_dictionary_name)
266
- Py_RETURN_NONE ;
257
+ return PythonObject() ;
267
258
268
259
PyErr_Cleaner py_err_cleaner(true);
269
260
@@ -275,7 +266,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedThread(
275
266
if (!pfunc.IsAllocated()) {
276
267
error_string.append("could not find script class: ");
277
268
error_string.append(python_class_name);
278
- return nullptr ;
269
+ return PythonObject() ;
279
270
}
280
271
281
272
llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
@@ -286,30 +277,24 @@ void *lldb_private::LLDBSwigPythonCreateScriptedThread(
286
277
[&](const llvm::ErrorInfoBase &E) {
287
278
error_string.append(E.message());
288
279
});
289
- Py_RETURN_NONE ;
280
+ return PythonObject() ;
290
281
}
291
282
292
- PythonObject result = {};
293
- if (arg_info.get().max_positional_args == 2) {
294
- result = pfunc(ToSWIGWrapper(process_sp), ToSWIGWrapper(args_impl));
295
- } else {
296
- error_string.assign("wrong number of arguments in __init__, should be 2 "
297
- "(not including self)");
298
- Py_RETURN_NONE;
299
- }
283
+ if (arg_info.get().max_positional_args == 2)
284
+ return pfunc(ToSWIGWrapper(process_sp), ToSWIGWrapper(args_impl));
300
285
301
- if (result.IsAllocated())
302
- return result.release( );
303
- Py_RETURN_NONE ;
286
+ error_string.assign("wrong number of arguments in __init__, should be 2 "
287
+ "(not including self)" );
288
+ return PythonObject() ;
304
289
}
305
290
306
- void * lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
291
+ PythonObject lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
307
292
const char *python_class_name, const char *session_dictionary_name,
308
293
const lldb_private::StructuredDataImpl &args_impl,
309
294
std::string &error_string, const lldb::ThreadPlanSP &thread_plan_sp) {
310
295
if (python_class_name == NULL || python_class_name[0] == '\0' ||
311
296
!session_dictionary_name)
312
- Py_RETURN_NONE ;
297
+ return PythonObject() ;
313
298
314
299
PyErr_Cleaner py_err_cleaner(true);
315
300
@@ -321,7 +306,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
321
306
if (!pfunc.IsAllocated()) {
322
307
error_string.append("could not find script class: ");
323
308
error_string.append(python_class_name);
324
- return nullptr ;
309
+ return PythonObject() ;
325
310
}
326
311
327
312
PythonObject tp_arg = ToSWIGWrapper(thread_plan_sp);
@@ -334,7 +319,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
334
319
[&](const llvm::ErrorInfoBase &E) {
335
320
error_string.append(E.message());
336
321
});
337
- Py_RETURN_NONE ;
322
+ return PythonObject() ;
338
323
}
339
324
340
325
PythonObject result = {};
@@ -343,23 +328,21 @@ void *lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
343
328
if (args_sb->IsValid()) {
344
329
error_string.assign(
345
330
"args passed, but __init__ does not take an args dictionary");
346
- Py_RETURN_NONE ;
331
+ return PythonObject() ;
347
332
}
348
333
result = pfunc(tp_arg, dict);
349
334
} else if (arg_info.get().max_positional_args >= 3) {
350
335
result = pfunc(tp_arg, ToSWIGWrapper(std::move(args_sb)), dict);
351
336
} else {
352
337
error_string.assign("wrong number of arguments in __init__, should be 2 or "
353
338
"3 (not including self)");
354
- Py_RETURN_NONE ;
339
+ return PythonObject() ;
355
340
}
356
341
357
342
// FIXME: At this point we should check that the class we found supports all
358
343
// the methods that we need.
359
344
360
- if (result.IsAllocated())
361
- return result.release();
362
- Py_RETURN_NONE;
345
+ return result;
363
346
}
364
347
365
348
bool lldb_private::LLDBSWIGPythonCallThreadPlan(
@@ -400,14 +383,14 @@ bool lldb_private::LLDBSWIGPythonCallThreadPlan(
400
383
return false;
401
384
}
402
385
403
- void * lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
386
+ PythonObject lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
404
387
const char *python_class_name, const char *session_dictionary_name,
405
388
const StructuredDataImpl &args_impl,
406
389
const lldb::BreakpointSP &breakpoint_sp) {
407
390
408
391
if (python_class_name == NULL || python_class_name[0] == '\0' ||
409
392
!session_dictionary_name)
410
- Py_RETURN_NONE ;
393
+ return PythonObject() ;
411
394
412
395
PyErr_Cleaner py_err_cleaner(true);
413
396
@@ -417,7 +400,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
417
400
python_class_name, dict);
418
401
419
402
if (!pfunc.IsAllocated())
420
- return nullptr ;
403
+ return PythonObject() ;
421
404
422
405
PythonObject result =
423
406
pfunc(ToSWIGWrapper(breakpoint_sp), ToSWIGWrapper(args_impl), dict);
@@ -428,11 +411,9 @@ void *lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
428
411
// Check that __callback__ is defined:
429
412
auto callback_func = result.ResolveName<PythonCallable>("__callback__");
430
413
if (callback_func.IsAllocated())
431
- return result.release();
432
- else
433
- result.release();
414
+ return result;
434
415
}
435
- Py_RETURN_NONE ;
416
+ return PythonObject() ;
436
417
}
437
418
438
419
unsigned int lldb_private::LLDBSwigPythonCallBreakpointResolver(
@@ -474,17 +455,17 @@ unsigned int lldb_private::LLDBSwigPythonCallBreakpointResolver(
474
455
return ret_val;
475
456
}
476
457
477
- void * lldb_private::LLDBSwigPythonCreateScriptedStopHook(
458
+ PythonObject lldb_private::LLDBSwigPythonCreateScriptedStopHook(
478
459
lldb::TargetSP target_sp, const char *python_class_name,
479
460
const char *session_dictionary_name, const StructuredDataImpl &args_impl,
480
461
Status &error) {
481
462
if (python_class_name == NULL || python_class_name[0] == '\0') {
482
463
error.SetErrorString("Empty class name.");
483
- Py_RETURN_NONE ;
464
+ return PythonObject() ;
484
465
}
485
466
if (!session_dictionary_name) {
486
467
error.SetErrorString("No session dictionary");
487
- Py_RETURN_NONE ;
468
+ return PythonObject() ;
488
469
}
489
470
490
471
PyErr_Cleaner py_err_cleaner(true);
@@ -497,7 +478,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedStopHook(
497
478
if (!pfunc.IsAllocated()) {
498
479
error.SetErrorStringWithFormat("Could not find class: %s.",
499
480
python_class_name);
500
- return nullptr ;
481
+ return PythonObject() ;
501
482
}
502
483
503
484
PythonObject result =
@@ -514,23 +495,22 @@ void *lldb_private::LLDBSwigPythonCreateScriptedStopHook(
514
495
"Wrong number of args for "
515
496
"handle_stop callback, should be 2 (excluding self), got: %zu",
516
497
num_args);
517
- Py_RETURN_NONE ;
498
+ return PythonObject() ;
518
499
} else
519
- return result.release() ;
500
+ return result;
520
501
} else {
521
502
error.SetErrorString("Couldn't get num arguments for handle_stop "
522
503
"callback.");
523
- Py_RETURN_NONE ;
504
+ return PythonObject() ;
524
505
}
525
- return result.release() ;
506
+ return result;
526
507
} else {
527
508
error.SetErrorStringWithFormat("Class \"%s\" is missing the required "
528
509
"handle_stop callback.",
529
510
python_class_name);
530
- result.release();
531
511
}
532
512
}
533
- Py_RETURN_NONE ;
513
+ return PythonObject() ;
534
514
}
535
515
536
516
bool lldb_private::LLDBSwigPythonStopHookCallHandleStop(
@@ -842,12 +822,12 @@ bool lldb_private::LLDBSwigPythonCallCommandObject(
842
822
return true;
843
823
}
844
824
845
- void * lldb_private::LLDBSWIGPythonCreateOSPlugin(
825
+ PythonObject lldb_private::LLDBSWIGPythonCreateOSPlugin(
846
826
const char *python_class_name, const char *session_dictionary_name,
847
827
const lldb::ProcessSP &process_sp) {
848
828
if (python_class_name == NULL || python_class_name[0] == '\0' ||
849
829
!session_dictionary_name)
850
- Py_RETURN_NONE ;
830
+ return PythonObject() ;
851
831
852
832
PyErr_Cleaner py_err_cleaner(true);
853
833
@@ -857,21 +837,16 @@ void *lldb_private::LLDBSWIGPythonCreateOSPlugin(
857
837
python_class_name, dict);
858
838
859
839
if (!pfunc.IsAllocated())
860
- Py_RETURN_NONE;
861
-
862
- auto result = pfunc(ToSWIGWrapper(process_sp));
863
-
864
- if (result.IsAllocated())
865
- return result.release();
840
+ return PythonObject();
866
841
867
- Py_RETURN_NONE ;
842
+ return pfunc(ToSWIGWrapper(process_sp)) ;
868
843
}
869
844
870
- void * lldb_private::LLDBSWIGPython_CreateFrameRecognizer(
845
+ PythonObject lldb_private::LLDBSWIGPython_CreateFrameRecognizer(
871
846
const char *python_class_name, const char *session_dictionary_name) {
872
847
if (python_class_name == NULL || python_class_name[0] == '\0' ||
873
848
!session_dictionary_name)
874
- Py_RETURN_NONE ;
849
+ return PythonObject() ;
875
850
876
851
PyErr_Cleaner py_err_cleaner(true);
877
852
@@ -881,14 +856,9 @@ void *lldb_private::LLDBSWIGPython_CreateFrameRecognizer(
881
856
python_class_name, dict);
882
857
883
858
if (!pfunc.IsAllocated())
884
- Py_RETURN_NONE;
885
-
886
- auto result = pfunc();
887
-
888
- if (result.IsAllocated())
889
- return result.release();
859
+ return PythonObject();
890
860
891
- Py_RETURN_NONE ;
861
+ return pfunc() ;
892
862
}
893
863
894
864
PyObject *lldb_private::LLDBSwigPython_GetRecognizedArguments(
0 commit comments