|
54 | 54 | free((char *) $1);
|
55 | 55 | }
|
56 | 56 |
|
57 |
| -%typemap(out) lldb::ScriptedObject { |
| 57 | +%typecheck(SWIG_TYPECHECK_POINTER) lldb::ScriptObjectPtr { |
| 58 | + PythonObject obj(PyRefType::Borrowed, $input); |
| 59 | + if (!obj.IsValid()) { |
| 60 | + PyErr_Clear(); |
| 61 | + $1 = 0; |
| 62 | + } else { |
| 63 | + $1 = 1; |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +%typemap(in) lldb::ScriptObjectPtr { |
| 68 | + if ($input == Py_None) { |
| 69 | + $1 = nullptr; |
| 70 | + } else { |
| 71 | + PythonObject obj(PyRefType::Borrowed, $input); |
| 72 | + if (!obj.IsValid()) { |
| 73 | + PyErr_SetString(PyExc_TypeError, "Script object is not valid"); |
| 74 | + SWIG_fail; |
| 75 | + } |
| 76 | + |
| 77 | + auto lldb_module = PythonModule::Import("lldb"); |
| 78 | + if (!lldb_module) { |
| 79 | + std::string err_msg = llvm::toString(lldb_module.takeError()); |
| 80 | + PyErr_SetString(PyExc_TypeError, err_msg.c_str()); |
| 81 | + SWIG_fail; |
| 82 | + } |
| 83 | + |
| 84 | + auto sb_structured_data_class = lldb_module.get().Get("SBStructuredData"); |
| 85 | + if (!sb_structured_data_class) { |
| 86 | + std::string err_msg = llvm::toString(sb_structured_data_class.takeError()); |
| 87 | + PyErr_SetString(PyExc_TypeError, err_msg.c_str()); |
| 88 | + SWIG_fail; |
| 89 | + } |
| 90 | + |
| 91 | + if (obj.IsInstance(sb_structured_data_class.get())) { |
| 92 | + $1 = obj.get(); |
| 93 | + } else { |
| 94 | + auto type = obj.GetType(); |
| 95 | + if (!type) { |
| 96 | + std::string err_msg = llvm::toString(type.takeError()); |
| 97 | + PyErr_SetString(PyExc_TypeError, err_msg.c_str()); |
| 98 | + SWIG_fail; |
| 99 | + } |
| 100 | + |
| 101 | + auto type_name = As<std::string>(type.get().GetAttribute("__name__")); |
| 102 | + if (!type_name) { |
| 103 | + std::string err_msg = llvm::toString(type_name.takeError()); |
| 104 | + PyErr_SetString(PyExc_TypeError, err_msg.c_str()); |
| 105 | + SWIG_fail; |
| 106 | + } |
| 107 | + |
| 108 | + if (llvm::StringRef(type_name.get()).startswith("SB")) { |
| 109 | + std::string error_msg = "Input type is invalid: " + type_name.get(); |
| 110 | + PyErr_SetString(PyExc_TypeError, error_msg.c_str()); |
| 111 | + SWIG_fail; |
| 112 | + } else { |
| 113 | + $1 = obj.get(); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +%typemap(out) lldb::ScriptObjectPtr { |
| 120 | + $result = (PyObject*) $1; |
| 121 | + if (!$result) |
| 122 | + $result = Py_None; |
| 123 | + Py_INCREF($result); |
| 124 | +} |
| 125 | + |
| 126 | +%typemap(out) lldb::SBScriptObject { |
58 | 127 | $result = nullptr;
|
59 |
| - if (const void* impl = $1) |
| 128 | + if (const void* impl = $1.GetPointer()) |
60 | 129 | $result = (PyObject*) impl;
|
61 | 130 | if (!$result) {
|
62 | 131 | $result = Py_None;
|
|
0 commit comments