1/* Typemap definitions, to allow SWIG to properly handle 'char**' data types. 2 3NOTE: If there's logic to free memory in a %typemap(freearg), it will also be 4run if you call SWIG_fail on an error path. Don't manually free() an argument 5AND call SWIG_fail at the same time, because it will result in a double free. 6 7*/ 8 9%inline %{ 10 11#include "../bindings/python/python-typemaps.h" 12 13%} 14 15%typemap(in) char ** { 16 /* Check if is a list */ 17 if (PythonList::Check($input)) { 18 PythonList list(PyRefType::Borrowed, $input); 19 int size = list.GetSize(); 20 int i = 0; 21 $1 = (char **)malloc((size + 1) * sizeof(char *)); 22 for (i = 0; i < size; i++) { 23 PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>(); 24 if (!py_str.IsAllocated()) { 25 PyErr_SetString(PyExc_TypeError, "list must contain strings"); 26 SWIG_fail; 27 } 28 29 $1[i] = const_cast<char *>(py_str.GetString().data()); 30 } 31 $1[i] = 0; 32 } else if ($input == Py_None) { 33 $1 = NULL; 34 } else { 35 PyErr_SetString(PyExc_TypeError, "not a list"); 36 SWIG_fail; 37 } 38} 39 40%typemap(typecheck) char ** { 41 /* Check if is a list */ 42 $1 = 1; 43 if (PythonList::Check($input)) { 44 PythonList list(PyRefType::Borrowed, $input); 45 int size = list.GetSize(); 46 int i = 0; 47 for (i = 0; i < size; i++) { 48 PythonString s = list.GetItemAtIndex(i).AsType<PythonString>(); 49 if (!s.IsAllocated()) { 50 $1 = 0; 51 } 52 } 53 } else { 54 $1 = (($input == Py_None) ? 1 : 0); 55 } 56} 57 58%typemap(freearg) char** { 59 free((char *) $1); 60} 61 62%typecheck(SWIG_TYPECHECK_POINTER) lldb::ScriptObjectPtr { 63 PythonObject obj(PyRefType::Borrowed, $input); 64 if (!obj.IsValid()) { 65 PyErr_Clear(); 66 $1 = 0; 67 } else { 68 $1 = 1; 69 } 70} 71 72%typemap(in) lldb::ScriptObjectPtr { 73 if ($input == Py_None) { 74 $1 = nullptr; 75 } else { 76 PythonObject obj(PyRefType::Borrowed, $input); 77 if (!obj.IsValid()) { 78 PyErr_SetString(PyExc_TypeError, "Script object is not valid"); 79 SWIG_fail; 80 } 81 82 auto lldb_module = PythonModule::Import("lldb"); 83 if (!lldb_module) { 84 std::string err_msg = llvm::toString(lldb_module.takeError()); 85 PyErr_SetString(PyExc_TypeError, err_msg.c_str()); 86 SWIG_fail; 87 } 88 89 auto sb_structured_data_class = lldb_module.get().Get("SBStructuredData"); 90 if (!sb_structured_data_class) { 91 std::string err_msg = llvm::toString(sb_structured_data_class.takeError()); 92 PyErr_SetString(PyExc_TypeError, err_msg.c_str()); 93 SWIG_fail; 94 } 95 96 if (obj.IsInstance(sb_structured_data_class.get())) { 97 $1 = obj.get(); 98 } else { 99 auto type = obj.GetType(); 100 if (!type) { 101 std::string err_msg = llvm::toString(type.takeError()); 102 PyErr_SetString(PyExc_TypeError, err_msg.c_str()); 103 SWIG_fail; 104 } 105 106 auto type_name = As<std::string>(type.get().GetAttribute("__name__")); 107 if (!type_name) { 108 std::string err_msg = llvm::toString(type_name.takeError()); 109 PyErr_SetString(PyExc_TypeError, err_msg.c_str()); 110 SWIG_fail; 111 } 112 113 if (llvm::StringRef(type_name.get()).startswith("SB")) { 114 std::string error_msg = "Input type is invalid: " + type_name.get(); 115 PyErr_SetString(PyExc_TypeError, error_msg.c_str()); 116 SWIG_fail; 117 } else { 118 $1 = obj.get(); 119 } 120 } 121 } 122} 123 124%typemap(out) lldb::ScriptObjectPtr { 125 $result = (PyObject*) $1; 126 if (!$result) 127 $result = Py_None; 128 Py_INCREF($result); 129} 130 131%typemap(out) lldb::SBScriptObject { 132 $result = nullptr; 133 if (const void* impl = $1.GetPointer()) 134 $result = (PyObject*) impl; 135 if (!$result) { 136 $result = Py_None; 137 Py_INCREF(Py_None); 138 } else { 139 Py_INCREF($result); 140 } 141} 142 143%typemap(out) char** { 144 int len; 145 int i; 146 len = 0; 147 while ($1[len]) 148 len++; 149 PythonList list(len); 150 for (i = 0; i < len; i++) 151 list.SetItemAtIndex(i, PythonString($1[i])); 152 $result = list.release(); 153} 154 155%typemap(in) lldb::tid_t { 156 PythonObject obj = Retain<PythonObject>($input); 157 lldb::tid_t value = unwrapOrSetPythonException(As<unsigned long long>(obj)); 158 if (PyErr_Occurred()) 159 SWIG_fail; 160 $1 = value; 161} 162 163%typemap(in) lldb::StateType { 164 PythonObject obj = Retain<PythonObject>($input); 165 unsigned long long state_type_value = 166 unwrapOrSetPythonException(As<unsigned long long>(obj)); 167 if (PyErr_Occurred()) 168 SWIG_fail; 169 if (state_type_value > lldb::StateType::kLastStateType) { 170 PyErr_SetString(PyExc_ValueError, "Not a valid StateType value"); 171 SWIG_fail; 172 } 173 $1 = static_cast<lldb::StateType>(state_type_value); 174} 175 176/* Typemap definitions to allow SWIG to properly handle char buffer. */ 177 178// typemap for a char buffer 179%typemap(in) (char *dst, size_t dst_len) { 180 if (!PyLong_Check($input)) { 181 PyErr_SetString(PyExc_ValueError, "Expecting an integer"); 182 SWIG_fail; 183 } 184 $2 = PyLong_AsLong($input); 185 if ($2 <= 0) { 186 PyErr_SetString(PyExc_ValueError, "Positive integer expected"); 187 SWIG_fail; 188 } 189 $1 = (char *)malloc($2); 190} 191// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated 192// as char data instead of byte data. 193%typemap(in) (void *char_buf, size_t size) = (char *dst, size_t dst_len); 194 195// Return the char buffer. Discarding any previous return result 196%typemap(argout) (char *dst, size_t dst_len) { 197 Py_XDECREF($result); /* Blow away any previous result */ 198 if (result == 0) { 199 PythonString string(""); 200 $result = string.release(); 201 Py_INCREF($result); 202 } else { 203 llvm::StringRef ref(static_cast<const char *>($1), result); 204 PythonString string(ref); 205 $result = string.release(); 206 } 207 free($1); 208} 209// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated 210// as char data instead of byte data. 211%typemap(argout) (void *char_buf, size_t size) = (char *dst, size_t dst_len); 212 213 214// typemap for handling an snprintf-like API like SBThread::GetStopDescription. 215%typemap(in) (char *dst_or_null, size_t dst_len) { 216 if (!PyLong_Check($input)) { 217 PyErr_SetString(PyExc_ValueError, "Expecting an integer"); 218 SWIG_fail; 219 } 220 $2 = PyLong_AsLong($input); 221 if ($2 <= 0) { 222 PyErr_SetString(PyExc_ValueError, "Positive integer expected"); 223 SWIG_fail; 224 } 225 $1 = (char *)malloc($2); 226} 227%typemap(argout) (char *dst_or_null, size_t dst_len) { 228 Py_XDECREF($result); /* Blow away any previous result */ 229 llvm::StringRef ref($1); 230 PythonString string(ref); 231 $result = string.release(); 232 free($1); 233} 234 235 236// typemap for an outgoing buffer 237// See also SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len). 238// Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len). 239%typemap(in) (const char *cstr, uint32_t cstr_len), 240 (const char *src, size_t src_len) { 241 if (PythonString::Check($input)) { 242 PythonString str(PyRefType::Borrowed, $input); 243 $1 = (char *)str.GetString().data(); 244 $2 = str.GetSize(); 245 } else if (PythonByteArray::Check($input)) { 246 PythonByteArray bytearray(PyRefType::Borrowed, $input); 247 $1 = (char *)bytearray.GetBytes().data(); 248 $2 = bytearray.GetSize(); 249 } else if (PythonBytes::Check($input)) { 250 PythonBytes bytes(PyRefType::Borrowed, $input); 251 $1 = (char *)bytes.GetBytes().data(); 252 $2 = bytes.GetSize(); 253 } else { 254 PyErr_SetString(PyExc_ValueError, "Expecting a string"); 255 SWIG_fail; 256 } 257} 258// For SBProcess::WriteMemory, SBTarget::GetInstructions and SBDebugger::DispatchInput. 259%typemap(in) (const void *buf, size_t size), 260 (const void *data, size_t data_len) { 261 if (PythonString::Check($input)) { 262 PythonString str(PyRefType::Borrowed, $input); 263 $1 = (void *)str.GetString().data(); 264 $2 = str.GetSize(); 265 } else if (PythonByteArray::Check($input)) { 266 PythonByteArray bytearray(PyRefType::Borrowed, $input); 267 $1 = (void *)bytearray.GetBytes().data(); 268 $2 = bytearray.GetSize(); 269 } else if (PythonBytes::Check($input)) { 270 PythonBytes bytes(PyRefType::Borrowed, $input); 271 $1 = (void *)bytes.GetBytes().data(); 272 $2 = bytes.GetSize(); 273 } else { 274 PyErr_SetString(PyExc_ValueError, "Expecting a buffer"); 275 SWIG_fail; 276 } 277} 278 279// typemap for an incoming buffer 280// See also SBProcess::ReadMemory. 281%typemap(in) (void *buf, size_t size) { 282 if (PyLong_Check($input)) { 283 $2 = PyLong_AsLong($input); 284 } else { 285 PyErr_SetString(PyExc_ValueError, "Expecting an integer or long object"); 286 SWIG_fail; 287 } 288 if ($2 <= 0) { 289 PyErr_SetString(PyExc_ValueError, "Positive integer expected"); 290 SWIG_fail; 291 } 292 $1 = (void *)malloc($2); 293} 294 295// Return the buffer. Discarding any previous return result 296// See also SBProcess::ReadMemory. 297%typemap(argout) (void *buf, size_t size) { 298 Py_XDECREF($result); /* Blow away any previous result */ 299 if (result == 0) { 300 $result = Py_None; 301 Py_INCREF($result); 302 } else { 303 PythonBytes bytes(static_cast<const uint8_t *>($1), result); 304 $result = bytes.release(); 305 } 306 free($1); 307} 308 309%{ 310namespace { 311template <class T> 312T PyLongAsT(PyObject *obj) { 313 static_assert(true, "unsupported type"); 314} 315 316template <> uint64_t PyLongAsT<uint64_t>(PyObject *obj) { 317 return static_cast<uint64_t>(PyLong_AsUnsignedLongLong(obj)); 318} 319 320template <> uint32_t PyLongAsT<uint32_t>(PyObject *obj) { 321 return static_cast<uint32_t>(PyLong_AsUnsignedLong(obj)); 322} 323 324template <> int64_t PyLongAsT<int64_t>(PyObject *obj) { 325 return static_cast<int64_t>(PyLong_AsLongLong(obj)); 326} 327 328template <> int32_t PyLongAsT<int32_t>(PyObject *obj) { 329 return static_cast<int32_t>(PyLong_AsLong(obj)); 330} 331 332template <class T> bool SetNumberFromPyObject(T &number, PyObject *obj) { 333 if (PyLong_Check(obj)) 334 number = PyLongAsT<T>(obj); 335 else 336 return false; 337 338 return true; 339} 340 341template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) { 342 if (PyFloat_Check(obj)) { 343 number = PyFloat_AsDouble(obj); 344 return true; 345 } 346 347 return false; 348} 349 350} // namespace 351%} 352 353// these typemaps allow Python users to pass list objects 354// and have them turn into C++ arrays (this is useful, for instance 355// when creating SBData objects from lists of numbers) 356%typemap(in) (uint64_t* array, size_t array_len), 357 (uint32_t* array, size_t array_len), 358 (int64_t* array, size_t array_len), 359 (int32_t* array, size_t array_len), 360 (double* array, size_t array_len) { 361 /* Check if is a list */ 362 if (PyList_Check($input)) { 363 int size = PyList_Size($input); 364 int i = 0; 365 $2 = size; 366 $1 = ($1_type)malloc(size * sizeof($*1_type)); 367 for (i = 0; i < size; i++) { 368 PyObject *o = PyList_GetItem($input, i); 369 if (!SetNumberFromPyObject($1[i], o)) { 370 PyErr_SetString(PyExc_TypeError, "list must contain numbers"); 371 SWIG_fail; 372 } 373 374 if (PyErr_Occurred()) { 375 SWIG_fail; 376 } 377 } 378 } else if ($input == Py_None) { 379 $1 = NULL; 380 $2 = 0; 381 } else { 382 PyErr_SetString(PyExc_TypeError, "not a list"); 383 SWIG_fail; 384 } 385} 386 387%typemap(freearg) (uint64_t* array, size_t array_len), 388 (uint32_t* array, size_t array_len), 389 (int64_t* array, size_t array_len), 390 (int32_t* array, size_t array_len), 391 (double* array, size_t array_len) { 392 free($1); 393} 394 395// these typemaps wrap SBModule::GetVersion() from requiring a memory buffer 396// to the more Pythonic style where a list is returned and no previous allocation 397// is necessary - this will break if more than 50 versions are ever returned 398%typemap(typecheck) (uint32_t *versions, uint32_t num_versions) { 399 $1 = ($input == Py_None ? 1 : 0); 400} 401 402%typemap(in, numinputs=0) (uint32_t *versions) { 403 $1 = (uint32_t *)malloc(sizeof(uint32_t) * 50); 404} 405 406%typemap(in, numinputs=0) (uint32_t num_versions) { 407 $1 = 50; 408} 409 410%typemap(argout) (uint32_t *versions, uint32_t num_versions) { 411 uint32_t count = result; 412 if (count >= $2) 413 count = $2; 414 PyObject *list = PyList_New(count); 415 for (uint32_t j = 0; j < count; j++) { 416 PyObject *item = PyLong_FromLong($1[j]); 417 int ok = PyList_SetItem(list, j, item); 418 if (ok != 0) { 419 $result = Py_None; 420 break; 421 } 422 } 423 $result = list; 424} 425 426%typemap(freearg) (uint32_t *versions) { 427 free($1); 428} 429 430 431// For Log::LogOutputCallback 432%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) { 433 if (!($input == Py_None || 434 PyCallable_Check(reinterpret_cast<PyObject *>($input)))) { 435 PyErr_SetString(PyExc_TypeError, "Need a callable object or None!"); 436 SWIG_fail; 437 } 438 439 // FIXME (filcab): We can't currently check if our callback is already 440 // LLDBSwigPythonCallPythonLogOutputCallback (to DECREF the previous 441 // baton) nor can we just remove all traces of a callback, if we want to 442 // revert to a file logging mechanism. 443 444 // Don't lose the callback reference 445 Py_INCREF($input); 446 $1 = LLDBSwigPythonCallPythonLogOutputCallback; 447 $2 = $input; 448} 449 450%typemap(typecheck) (lldb::LogOutputCallback log_callback, void *baton) { 451 $1 = $input == Py_None; 452 $1 = $1 || PyCallable_Check(reinterpret_cast<PyObject *>($input)); 453} 454 455// For lldb::SBDebuggerDestroyCallback 456%typemap(in) (lldb::SBDebuggerDestroyCallback destroy_callback, void *baton) { 457 if (!($input == Py_None || 458 PyCallable_Check(reinterpret_cast<PyObject *>($input)))) { 459 PyErr_SetString(PyExc_TypeError, "Need a callable object or None!"); 460 SWIG_fail; 461 } 462 463 // FIXME (filcab): We can't currently check if our callback is already 464 // LLDBSwigPythonCallPythonSBDebuggerTerminateCallback (to DECREF the previous 465 // baton) nor can we just remove all traces of a callback, if we want to 466 // revert to a file logging mechanism. 467 468 // Don't lose the callback reference 469 Py_INCREF($input); 470 $1 = LLDBSwigPythonCallPythonSBDebuggerTerminateCallback; 471 $2 = $input; 472} 473 474%typemap(typecheck) (lldb::SBDebuggerDestroyCallback destroy_callback, void *baton) { 475 $1 = $input == Py_None; 476 $1 = $1 || PyCallable_Check(reinterpret_cast<PyObject *>($input)); 477} 478 479%typemap(in) lldb::FileSP { 480 PythonFile py_file(PyRefType::Borrowed, $input); 481 if (!py_file) { 482 PyErr_SetString(PyExc_TypeError, "not a file"); 483 SWIG_fail; 484 } 485 auto sp = unwrapOrSetPythonException(py_file.ConvertToFile()); 486 if (!sp) 487 SWIG_fail; 488 $1 = sp; 489} 490 491%typemap(in) lldb::FileSP FORCE_IO_METHODS { 492 PythonFile py_file(PyRefType::Borrowed, $input); 493 if (!py_file) { 494 PyErr_SetString(PyExc_TypeError, "not a file"); 495 SWIG_fail; 496 } 497 auto sp = unwrapOrSetPythonException( 498 py_file.ConvertToFileForcingUseOfScriptingIOMethods()); 499 if (!sp) 500 SWIG_fail; 501 $1 = sp; 502} 503 504%typemap(in) lldb::FileSP BORROWED { 505 PythonFile py_file(PyRefType::Borrowed, $input); 506 if (!py_file) { 507 PyErr_SetString(PyExc_TypeError, "not a file"); 508 SWIG_fail; 509 } 510 auto sp = 511 unwrapOrSetPythonException(py_file.ConvertToFile(/*borrowed=*/true)); 512 if (!sp) 513 SWIG_fail; 514 $1 = sp; 515} 516 517%typemap(in) lldb::FileSP BORROWED_FORCE_IO_METHODS { 518 PythonFile py_file(PyRefType::Borrowed, $input); 519 if (!py_file) { 520 PyErr_SetString(PyExc_TypeError, "not a file"); 521 SWIG_fail; 522 } 523 auto sp = unwrapOrSetPythonException( 524 py_file.ConvertToFileForcingUseOfScriptingIOMethods(/*borrowed=*/true)); 525 if (!sp) 526 SWIG_fail; 527 $1 = sp; 528} 529 530%typecheck(SWIG_TYPECHECK_POINTER) lldb::FileSP { 531 if (PythonFile::Check($input)) { 532 $1 = 1; 533 } else { 534 PyErr_Clear(); 535 $1 = 0; 536 } 537} 538 539%typemap(out) lldb::FileSP { 540 $result = nullptr; 541 const lldb::FileSP &sp = $1; 542 if (sp) { 543 PythonFile pyfile = unwrapOrSetPythonException(PythonFile::FromFile(*sp)); 544 if (!pyfile.IsValid()) 545 SWIG_fail; 546 $result = pyfile.release(); 547 } 548 if (!$result) { 549 $result = Py_None; 550 Py_INCREF(Py_None); 551 } 552} 553 554%typemap(in) (const char* string, int len) { 555 if ($input == Py_None) { 556 $1 = NULL; 557 $2 = 0; 558 } else if (PythonString::Check($input)) { 559 PythonString py_str(PyRefType::Borrowed, $input); 560 llvm::StringRef str = py_str.GetString(); 561 $1 = const_cast<char *>(str.data()); 562 $2 = str.size(); 563 // In Python 2, if $input is a PyUnicode object then this 564 // will trigger a Unicode -> String conversion, in which 565 // case the `PythonString` will now own the PyString. Thus 566 // if it goes out of scope, the data will be deleted. The 567 // only way to avoid this is to leak the Python object in 568 // that case. Note that if there was no conversion, then 569 // releasing the string will not leak anything, since we 570 // created this as a borrowed reference. 571 py_str.release(); 572 } else { 573 PyErr_SetString(PyExc_TypeError, "not a string-like object"); 574 SWIG_fail; 575 } 576} 577 578// These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i, 579// and fixed so they will not crash if PyObject_GetBuffer fails. 580// https://github.com/swig/swig/issues/1640 581// 582// I've also moved the call to PyBuffer_Release to the end of the SWIG wrapper, 583// doing it right away is not legal according to the python buffer protocol. 584 585%define %pybuffer_mutable_binary(TYPEMAP, SIZE) 586%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) { 587 int res; 588 Py_ssize_t size = 0; 589 void *buf = 0; 590 res = PyObject_GetBuffer($input, &view.buffer, PyBUF_WRITABLE); 591 if (res < 0) { 592 PyErr_Clear(); 593 %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum); 594 } 595 size = view.buffer.len; 596 buf = view.buffer.buf; 597 $1 = ($1_ltype)buf; 598 $2 = ($2_ltype)(size / sizeof($*1_type)); 599} 600%enddef 601 602%define %pybuffer_binary(TYPEMAP, SIZE) 603%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) { 604 int res; 605 Py_ssize_t size = 0; 606 const void *buf = 0; 607 res = PyObject_GetBuffer($input, &view.buffer, PyBUF_CONTIG_RO); 608 if (res < 0) { 609 PyErr_Clear(); 610 %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum); 611 } 612 size = view.buffer.len; 613 buf = view.buffer.buf; 614 $1 = ($1_ltype)buf; 615 $2 = ($2_ltype)(size / sizeof($*1_type)); 616} 617%enddef 618 619%pybuffer_binary(const uint8_t *buf, size_t num_bytes); 620%pybuffer_mutable_binary(uint8_t *buf, size_t num_bytes); 621 622%typemap(in) (const char **symbol_name, uint32_t num_names) { 623 using namespace lldb_private; 624 /* Check if is a list */ 625 if (PythonList::Check($input)) { 626 PythonList list(PyRefType::Borrowed, $input); 627 $2 = list.GetSize(); 628 int i = 0; 629 $1 = (char**)malloc(($2+1)*sizeof(char*)); 630 for (i = 0; i < $2; i++) { 631 PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>(); 632 if (!py_str.IsAllocated()) { 633 PyErr_SetString(PyExc_TypeError,"list must contain strings and blubby"); 634 free($1); 635 return nullptr; 636 } 637 638 $1[i] = const_cast<char*>(py_str.GetString().data()); 639 } 640 $1[i] = 0; 641 } else if ($input == Py_None) { 642 $1 = NULL; 643 } else { 644 PyErr_SetString(PyExc_TypeError,"not a list"); 645 return NULL; 646 } 647} 648 649// For lldb::SBPlatformLocateModuleCallback 650%typemap(in) (lldb::SBPlatformLocateModuleCallback callback, 651 void *callback_baton) { 652 if (!($input == Py_None || 653 PyCallable_Check(reinterpret_cast<PyObject *>($input)))) { 654 PyErr_SetString(PyExc_TypeError, "Need a callable object or None!"); 655 SWIG_fail; 656 } 657 658 if ($input == Py_None) { 659 $1 = nullptr; 660 $2 = nullptr; 661 } else { 662 PythonCallable callable = Retain<PythonCallable>($input); 663 if (!callable.IsValid()) { 664 PyErr_SetString(PyExc_TypeError, "Need a valid callable object"); 665 SWIG_fail; 666 } 667 668 llvm::Expected<PythonCallable::ArgInfo> arg_info = callable.GetArgInfo(); 669 if (!arg_info) { 670 PyErr_SetString(PyExc_TypeError, 671 ("Could not get arguments: " + 672 llvm::toString(arg_info.takeError())).c_str()); 673 SWIG_fail; 674 } 675 676 if (arg_info.get().max_positional_args != 3) { 677 PyErr_SetString(PyExc_TypeError, "Expected 3 argument callable object"); 678 SWIG_fail; 679 } 680 681 // NOTE: When this is called multiple times, this will leak the Python 682 // callable object as other callbacks, because this does not call Py_DECREF 683 // the object. But it should be almost zero impact since this method is 684 // expected to be called only once. 685 686 // Don't lose the callback reference 687 Py_INCREF($input); 688 689 $1 = LLDBSwigPythonCallLocateModuleCallback; 690 $2 = $input; 691 } 692} 693 694%typemap(typecheck) (lldb::SBPlatformLocateModuleCallback callback, 695 void *callback_baton) { 696 $1 = $input == Py_None; 697 $1 = $1 || PyCallable_Check(reinterpret_cast<PyObject *>($input)); 698} 699