forked from OSchip/llvm-project
[lldb] (Semi-automatically) format .swig files
I've found my recent ventures into the swig land painful because of the strange way they are formatted. This patch attempts to alleviate future headaches by formatting these files into something resembling the normal llvm style. Unfortunately, completely formatting these files automatically does not work because clang format gets confused by swigs % syntax, so I have employed a hybrid approach where I formatted blocks of c++ code with clang-format and then manually massaged the code until it looked reasonable (and compiled). I don't expect these files to remain perfectly formatted (although, if one's editor is configured to configure the current line/block on request, one can get pretty good results by using it judiciously), but at least it will prevent the (mangled form of the) old lldb style being proliferated endlessly. Differential Revision: https://reviews.llvm.org/D115736
This commit is contained in:
parent
5b139a583d
commit
9d5e37ed8c
|
@ -1,27 +1,20 @@
|
||||||
template <typename SBClass>
|
template <typename SBClass> void PushSBClass(lua_State *L, SBClass *obj);
|
||||||
void
|
|
||||||
PushSBClass (lua_State* L, SBClass* obj);
|
|
||||||
|
|
||||||
void
|
void PushSBClass(lua_State *L, lldb::SBFrame *frame_sb) {
|
||||||
PushSBClass (lua_State* L, lldb::SBFrame* frame_sb)
|
SWIG_NewPointerObj(L, frame_sb, SWIGTYPE_p_lldb__SBFrame, 0);
|
||||||
{
|
|
||||||
SWIG_NewPointerObj(L, frame_sb, SWIGTYPE_p_lldb__SBFrame, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PushSBClass(lua_State *L,
|
||||||
PushSBClass (lua_State* L, lldb::SBBreakpointLocation* breakpoint_location_sb)
|
lldb::SBBreakpointLocation *breakpoint_location_sb) {
|
||||||
{
|
SWIG_NewPointerObj(L, breakpoint_location_sb,
|
||||||
SWIG_NewPointerObj(L, breakpoint_location_sb, SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
|
SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PushSBClass(lua_State *L, lldb::SBWatchpoint *watchpoint_sb) {
|
||||||
PushSBClass (lua_State* L, lldb::SBWatchpoint* watchpoint_sb)
|
SWIG_NewPointerObj(L, watchpoint_sb, SWIGTYPE_p_lldb__SBWatchpoint, 0);
|
||||||
{
|
|
||||||
SWIG_NewPointerObj(L, watchpoint_sb, SWIGTYPE_p_lldb__SBWatchpoint, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PushSBClass(lua_State *L, lldb::SBStructuredData *structured_data_sb) {
|
||||||
PushSBClass (lua_State* L, lldb::SBStructuredData* structured_data_sb)
|
SWIG_NewPointerObj(L, structured_data_sb, SWIGTYPE_p_lldb__SBStructuredData,
|
||||||
{
|
0);
|
||||||
SWIG_NewPointerObj(L, structured_data_sb, SWIGTYPE_p_lldb__SBStructuredData, 0);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,11 +76,11 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
|
|
||||||
// typemap for a char buffer
|
// typemap for a char buffer
|
||||||
%typemap(in) (char *dst, size_t dst_len) {
|
%typemap(in) (char *dst, size_t dst_len) {
|
||||||
$2 = luaL_checkinteger(L, $input);
|
$2 = luaL_checkinteger(L, $input);
|
||||||
if ($2 <= 0) {
|
if ($2 <= 0) {
|
||||||
return luaL_error(L, "Positive integer expected");
|
return luaL_error(L, "Positive integer expected");
|
||||||
}
|
}
|
||||||
$1 = (char *) malloc($2);
|
$1 = (char *)malloc($2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated
|
// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated
|
||||||
|
@ -92,14 +92,14 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
|
|
||||||
// Return the char buffer. Discarding any previous return result
|
// Return the char buffer. Discarding any previous return result
|
||||||
%typemap(argout) (char *dst, size_t dst_len) {
|
%typemap(argout) (char *dst, size_t dst_len) {
|
||||||
lua_pop(L, 1); // Blow away the previous result
|
lua_pop(L, 1); // Blow away the previous result
|
||||||
if ($result == 0) {
|
if ($result == 0) {
|
||||||
lua_pushliteral(L, "");
|
lua_pushliteral(L, "");
|
||||||
} else {
|
} else {
|
||||||
lua_pushlstring(L, (const char *)$1, $result);
|
lua_pushlstring(L, (const char *)$1, $result);
|
||||||
}
|
}
|
||||||
free($1);
|
free($1);
|
||||||
// SWIG_arg was already incremented
|
// SWIG_arg was already incremented
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated
|
// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated
|
||||||
|
@ -114,18 +114,18 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
// Typemap for handling a snprintf-like API like SBThread::GetStopDescription.
|
// Typemap for handling a snprintf-like API like SBThread::GetStopDescription.
|
||||||
|
|
||||||
%typemap(in) (char *dst_or_null, size_t dst_len) {
|
%typemap(in) (char *dst_or_null, size_t dst_len) {
|
||||||
$2 = luaL_checkinteger(L, $input);
|
$2 = luaL_checkinteger(L, $input);
|
||||||
if ($2 <= 0) {
|
if ($2 <= 0) {
|
||||||
return luaL_error(L, "Positive integer expected");
|
return luaL_error(L, "Positive integer expected");
|
||||||
}
|
}
|
||||||
$1 = (char *)malloc($2);
|
$1 = (char *)malloc($2);
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(argout) (char *dst_or_null, size_t dst_len) {
|
%typemap(argout) (char *dst_or_null, size_t dst_len) {
|
||||||
lua_pop(L, 1); // Blow away the previous result
|
lua_pop(L, 1); // Blow away the previous result
|
||||||
lua_pushlstring(L, (const char *)$1, $result);
|
lua_pushlstring(L, (const char *)$1, $result);
|
||||||
free($1);
|
free($1);
|
||||||
// SWIG_arg was already incremented
|
// SWIG_arg was already incremented
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -133,22 +133,22 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
// Typemap for handling SBModule::GetVersion
|
// Typemap for handling SBModule::GetVersion
|
||||||
|
|
||||||
%typemap(in) (uint32_t *versions, uint32_t num_versions) {
|
%typemap(in) (uint32_t *versions, uint32_t num_versions) {
|
||||||
$2 = 99;
|
$2 = 99;
|
||||||
$1 = (uint32_t *)malloc(sizeof(uint32_t) * $2);
|
$1 = (uint32_t *)malloc(sizeof(uint32_t) * $2);
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(argout) (uint32_t *versions, uint32_t num_versions) {
|
%typemap(argout) (uint32_t *versions, uint32_t num_versions) {
|
||||||
uint32_t count = result;
|
uint32_t count = result;
|
||||||
if (count >= $2)
|
if (count >= $2)
|
||||||
count = $2;
|
count = $2;
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i++ < count) {
|
while (i++ < count) {
|
||||||
lua_pushinteger(L, $1[i - 1]);
|
lua_pushinteger(L, $1[i - 1]);
|
||||||
lua_seti(L, -2, i);
|
lua_seti(L, -2, i);
|
||||||
}
|
}
|
||||||
SWIG_arg++;
|
SWIG_arg++;
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -156,15 +156,15 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
// Typemap for handling SBDebugger::SetLoggingCallback
|
// Typemap for handling SBDebugger::SetLoggingCallback
|
||||||
|
|
||||||
%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
|
%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
|
||||||
$1 = LLDBSwigLuaCallLuaLogOutputCallback;
|
$1 = LLDBSwigLuaCallLuaLogOutputCallback;
|
||||||
$2 = (void *)L;
|
$2 = (void *)L;
|
||||||
|
|
||||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||||
lua_settop(L, 2);
|
lua_settop(L, 2);
|
||||||
|
|
||||||
lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
|
lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
|
||||||
lua_insert(L, 2);
|
lua_insert(L, 2);
|
||||||
lua_settable(L, LUA_REGISTRYINDEX);
|
lua_settable(L, LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -172,20 +172,20 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
// Typemap for handling SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len)
|
// Typemap for handling SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len)
|
||||||
|
|
||||||
%typemap(in) (const char *cstr, uint32_t cstr_len) {
|
%typemap(in) (const char *cstr, uint32_t cstr_len) {
|
||||||
$1 = (char *)luaL_checklstring(L, $input, (size_t *)&$2);
|
$1 = (char *)luaL_checklstring(L, $input, (size_t *)&$2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Typemap for handling SBProcess::PutSTDIN
|
// Typemap for handling SBProcess::PutSTDIN
|
||||||
|
|
||||||
%typemap(in) (const char *src, size_t src_len) {
|
%typemap(in) (const char *src, size_t src_len) {
|
||||||
$1 = (char *)luaL_checklstring(L, $input, &$2);
|
$1 = (char *)luaL_checklstring(L, $input, &$2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Typemap for handling SBProcess::WriteMemory, SBTarget::GetInstructions...
|
// Typemap for handling SBProcess::WriteMemory, SBTarget::GetInstructions...
|
||||||
|
|
||||||
%typemap(in) (const void *buf, size_t size),
|
%typemap(in) (const void *buf, size_t size),
|
||||||
(const void *data, size_t data_len) {
|
(const void *data, size_t data_len) {
|
||||||
$1 = (void *)luaL_checklstring(L, $input, &$2);
|
$1 = (void *)luaL_checklstring(L, $input, &$2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -195,35 +195,35 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
// It should accept a Lua table of strings, for stuff like "argv" and "envp".
|
// It should accept a Lua table of strings, for stuff like "argv" and "envp".
|
||||||
|
|
||||||
%typemap(in) char ** {
|
%typemap(in) char ** {
|
||||||
if (lua_istable(L, $input)) {
|
if (lua_istable(L, $input)) {
|
||||||
size_t size = lua_rawlen(L, $input);
|
size_t size = lua_rawlen(L, $input);
|
||||||
$1 = (char **)malloc((size + 1) * sizeof(char *));
|
$1 = (char **)malloc((size + 1) * sizeof(char *));
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
while (i++ < size) {
|
while (i++ < size) {
|
||||||
lua_rawgeti(L, $input, i);
|
lua_rawgeti(L, $input, i);
|
||||||
if (!lua_isstring(L, -1)) {
|
if (!lua_isstring(L, -1)) {
|
||||||
// if current element cannot be converted to string, raise an error
|
// if current element cannot be converted to string, raise an error
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
return luaL_error(L, "List should only contain strings");
|
return luaL_error(L, "List should only contain strings");
|
||||||
}
|
|
||||||
$1[j++] = (char *)lua_tostring(L, -1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
}
|
||||||
$1[j] = 0;
|
$1[j++] = (char *)lua_tostring(L, -1);
|
||||||
} else if (lua_isnil(L, $input)) {
|
lua_pop(L, 1);
|
||||||
// "nil" is also acceptable, equivalent as an empty table
|
}
|
||||||
$1 = NULL;
|
$1[j] = 0;
|
||||||
} else {
|
} else if (lua_isnil(L, $input)) {
|
||||||
return luaL_error(L, "A list of strings expected");
|
// "nil" is also acceptable, equivalent as an empty table
|
||||||
}
|
$1 = NULL;
|
||||||
|
} else {
|
||||||
|
return luaL_error(L, "A list of strings expected");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(freearg) char ** {
|
%typemap(freearg) char ** {
|
||||||
free((char *) $1);
|
free((char *) $1);
|
||||||
}
|
}
|
||||||
|
|
||||||
%typecheck(SWIG_TYPECHECK_STRING_ARRAY) char ** {
|
%typecheck(SWIG_TYPECHECK_STRING_ARRAY) char ** {
|
||||||
$1 = (lua_istable(L, $input) || lua_isnil(L, $input));
|
$1 = (lua_istable(L, $input) || lua_isnil(L, $input));
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -231,30 +231,30 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
// Typemap for file handles (e.g. used in SBDebugger::SetOutputFile)
|
// Typemap for file handles (e.g. used in SBDebugger::SetOutputFile)
|
||||||
|
|
||||||
%typemap(in) lldb::FileSP {
|
%typemap(in) lldb::FileSP {
|
||||||
luaL_Stream *p = (luaL_Stream *)luaL_checkudata(L, $input, LUA_FILEHANDLE);
|
luaL_Stream *p = (luaL_Stream *)luaL_checkudata(L, $input, LUA_FILEHANDLE);
|
||||||
lldb::FileSP file_sp;
|
lldb::FileSP file_sp;
|
||||||
file_sp = std::make_shared<lldb_private::NativeFile>(p->f, false);
|
file_sp = std::make_shared<lldb_private::NativeFile>(p->f, false);
|
||||||
if (!file_sp->IsValid())
|
if (!file_sp->IsValid())
|
||||||
return luaL_error(L, "Invalid file");
|
return luaL_error(L, "Invalid file");
|
||||||
$1 = file_sp;
|
$1 = file_sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typecheck(SWIG_TYPECHECK_POINTER) lldb::FileSP {
|
%typecheck(SWIG_TYPECHECK_POINTER) lldb::FileSP {
|
||||||
$1 = (lua_isuserdata(L, $input)) &&
|
$1 = (lua_isuserdata(L, $input)) &&
|
||||||
(luaL_testudata(L, $input, LUA_FILEHANDLE) != nullptr);
|
(luaL_testudata(L, $input, LUA_FILEHANDLE) != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Typemap for file handles (e.g. used in SBDebugger::GetOutputFileHandle)
|
// Typemap for file handles (e.g. used in SBDebugger::GetOutputFileHandle)
|
||||||
|
|
||||||
%typemap(out) lldb::FileSP {
|
%typemap(out) lldb::FileSP {
|
||||||
lldb::FileSP &sp = $1;
|
lldb::FileSP &sp = $1;
|
||||||
if (sp && sp->IsValid()) {
|
if (sp && sp->IsValid()) {
|
||||||
luaL_Stream *p = (luaL_Stream *)lua_newuserdata(L, sizeof(luaL_Stream));
|
luaL_Stream *p = (luaL_Stream *)lua_newuserdata(L, sizeof(luaL_Stream));
|
||||||
p->closef = &LLDBSwigLuaCloseFileHandle;
|
p->closef = &LLDBSwigLuaCloseFileHandle;
|
||||||
p->f = sp->GetStream();
|
p->f = sp->GetStream();
|
||||||
luaL_setmetatable(L, LUA_FILEHANDLE);
|
luaL_setmetatable(L, LUA_FILEHANDLE);
|
||||||
SWIG_arg++;
|
SWIG_arg++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -266,29 +266,29 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
(int64_t* array, size_t array_len),
|
(int64_t* array, size_t array_len),
|
||||||
(int32_t* array, size_t array_len),
|
(int32_t* array, size_t array_len),
|
||||||
(double* array, size_t array_len) {
|
(double* array, size_t array_len) {
|
||||||
if (lua_istable(L, $input)) {
|
if (lua_istable(L, $input)) {
|
||||||
// It should accept a table of numbers.
|
// It should accept a table of numbers.
|
||||||
$2 = lua_rawlen(L, $input);
|
$2 = lua_rawlen(L, $input);
|
||||||
$1 = ($1_ltype)malloc(($2) * sizeof($*1_type));
|
$1 = ($1_ltype)malloc(($2) * sizeof($*1_type));
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
while (i++ < $2) {
|
while (i++ < $2) {
|
||||||
lua_rawgeti(L, $input, i);
|
lua_rawgeti(L, $input, i);
|
||||||
if (!lua_isnumber(L, -1)) {
|
if (!lua_isnumber(L, -1)) {
|
||||||
// if current element cannot be converted to number, raise an error
|
// if current element cannot be converted to number, raise an error
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
return luaL_error(L, "List should only contain numbers");
|
return luaL_error(L, "List should only contain numbers");
|
||||||
}
|
|
||||||
$1[j++] = ($*1_ltype)lua_tonumber(L, -1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
}
|
||||||
} else if (lua_isnil(L, $input)) {
|
$1[j++] = ($*1_ltype) lua_tonumber(L, -1);
|
||||||
// "nil" is also acceptable, equivalent as an empty table
|
lua_pop(L, 1);
|
||||||
$1 = NULL;
|
}
|
||||||
$2 = 0;
|
} else if (lua_isnil(L, $input)) {
|
||||||
} else {
|
// "nil" is also acceptable, equivalent as an empty table
|
||||||
// else raise an error
|
$1 = NULL;
|
||||||
return luaL_error(L, "A list of numbers expected.");
|
$2 = 0;
|
||||||
}
|
} else {
|
||||||
|
// else raise an error
|
||||||
|
return luaL_error(L, "A list of numbers expected.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(freearg) (uint64_t* array, size_t array_len),
|
%typemap(freearg) (uint64_t* array, size_t array_len),
|
||||||
|
@ -296,7 +296,7 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
(int64_t* array, size_t array_len),
|
(int64_t* array, size_t array_len),
|
||||||
(int32_t* array, size_t array_len),
|
(int32_t* array, size_t array_len),
|
||||||
(double* array, size_t array_len) {
|
(double* array, size_t array_len) {
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -304,13 +304,12 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
// Typemap for SBCommandReturnObject::PutCString
|
// Typemap for SBCommandReturnObject::PutCString
|
||||||
|
|
||||||
%typemap(in) (const char *string, int len) {
|
%typemap(in) (const char *string, int len) {
|
||||||
if (lua_isnil(L, $input)) {
|
if (lua_isnil(L, $input)) {
|
||||||
$1 = NULL;
|
$1 = NULL;
|
||||||
$2 = 0;
|
$2 = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
$1 = (char *)luaL_checklstring(L, $input, (size_t *)&$2);
|
||||||
$1 = (char *)luaL_checklstring(L, $input, (size_t *)&$2);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -1,101 +1,87 @@
|
||||||
%header %{
|
%header %{
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> void PushSBClass(lua_State * L, T * obj);
|
||||||
void
|
|
||||||
PushSBClass(lua_State* L, T* obj);
|
|
||||||
|
|
||||||
// This function is called from Lua::CallBreakpointCallback
|
// This function is called from Lua::CallBreakpointCallback
|
||||||
llvm::Expected<bool>
|
llvm::Expected<bool> lldb_private::LLDBSwigLuaBreakpointCallbackFunction(
|
||||||
lldb_private::LLDBSwigLuaBreakpointCallbackFunction
|
lua_State * L, lldb::StackFrameSP stop_frame_sp,
|
||||||
(
|
lldb::BreakpointLocationSP bp_loc_sp,
|
||||||
lua_State *L,
|
const StructuredDataImpl &extra_args_impl) {
|
||||||
lldb::StackFrameSP stop_frame_sp,
|
lldb::SBFrame sb_frame(stop_frame_sp);
|
||||||
lldb::BreakpointLocationSP bp_loc_sp,
|
lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
|
||||||
const StructuredDataImpl &extra_args_impl
|
int nargs = 2;
|
||||||
)
|
|
||||||
{
|
|
||||||
lldb::SBFrame sb_frame(stop_frame_sp);
|
|
||||||
lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
|
|
||||||
int nargs = 2;
|
|
||||||
|
|
||||||
lldb::SBStructuredData extra_args(extra_args_impl);
|
lldb::SBStructuredData extra_args(extra_args_impl);
|
||||||
|
|
||||||
// Push the Lua wrappers
|
// Push the Lua wrappers
|
||||||
PushSBClass(L, &sb_frame);
|
PushSBClass(L, &sb_frame);
|
||||||
PushSBClass(L, &sb_bp_loc);
|
PushSBClass(L, &sb_bp_loc);
|
||||||
|
|
||||||
if (extra_args.IsValid()) {
|
if (extra_args.IsValid()) {
|
||||||
PushSBClass(L, &extra_args);
|
PushSBClass(L, &extra_args);
|
||||||
nargs++;
|
nargs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call into the Lua callback passing 'sb_frame' and 'sb_bp_loc'.
|
// Call into the Lua callback passing 'sb_frame' and 'sb_bp_loc'.
|
||||||
// Expects a boolean return.
|
// Expects a boolean return.
|
||||||
if (lua_pcall(L, nargs, 1, 0) != LUA_OK) {
|
if (lua_pcall(L, nargs, 1, 0) != LUA_OK) {
|
||||||
llvm::Error E = llvm::make_error<llvm::StringError>(
|
llvm::Error E = llvm::make_error<llvm::StringError>(
|
||||||
llvm::formatv("{0}\n", lua_tostring(L, -1)),
|
llvm::formatv("{0}\n", lua_tostring(L, -1)),
|
||||||
llvm::inconvertibleErrorCode());
|
llvm::inconvertibleErrorCode());
|
||||||
// Pop error message from the stack.
|
// Pop error message from the stack.
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
return std::move(E);
|
return std::move(E);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boolean return from the callback
|
// Boolean return from the callback
|
||||||
bool stop = lua_toboolean(L, -1);
|
bool stop = lua_toboolean(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
return stop;
|
return stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is called from Lua::CallWatchpointCallback
|
// This function is called from Lua::CallWatchpointCallback
|
||||||
llvm::Expected<bool>
|
llvm::Expected<bool> lldb_private::LLDBSwigLuaWatchpointCallbackFunction(
|
||||||
lldb_private::LLDBSwigLuaWatchpointCallbackFunction
|
lua_State * L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
|
||||||
(
|
lldb::SBFrame sb_frame(stop_frame_sp);
|
||||||
lua_State *L,
|
lldb::SBWatchpoint sb_wp(wp_sp);
|
||||||
lldb::StackFrameSP stop_frame_sp,
|
int nargs = 2;
|
||||||
lldb::WatchpointSP wp_sp
|
|
||||||
)
|
|
||||||
{
|
|
||||||
lldb::SBFrame sb_frame(stop_frame_sp);
|
|
||||||
lldb::SBWatchpoint sb_wp(wp_sp);
|
|
||||||
int nargs = 2;
|
|
||||||
|
|
||||||
// Push the Lua wrappers
|
// Push the Lua wrappers
|
||||||
PushSBClass(L, &sb_frame);
|
PushSBClass(L, &sb_frame);
|
||||||
PushSBClass(L, &sb_wp);
|
PushSBClass(L, &sb_wp);
|
||||||
|
|
||||||
// Call into the Lua callback passing 'sb_frame' and 'sb_wp'.
|
// Call into the Lua callback passing 'sb_frame' and 'sb_wp'.
|
||||||
// Expects a boolean return.
|
// Expects a boolean return.
|
||||||
if (lua_pcall(L, nargs, 1, 0) != LUA_OK) {
|
if (lua_pcall(L, nargs, 1, 0) != LUA_OK) {
|
||||||
llvm::Error E = llvm::make_error<llvm::StringError>(
|
llvm::Error E = llvm::make_error<llvm::StringError>(
|
||||||
llvm::formatv("{0}\n", lua_tostring(L, -1)),
|
llvm::formatv("{0}\n", lua_tostring(L, -1)),
|
||||||
llvm::inconvertibleErrorCode());
|
llvm::inconvertibleErrorCode());
|
||||||
// Pop error message from the stack.
|
// Pop error message from the stack.
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
return std::move(E);
|
return std::move(E);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boolean return from the callback
|
// Boolean return from the callback
|
||||||
bool stop = lua_toboolean(L, -1);
|
bool stop = lua_toboolean(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
return stop;
|
return stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
|
||||||
LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
|
lua_State *L = (lua_State *)baton;
|
||||||
lua_State *L = (lua_State *)baton;
|
|
||||||
|
|
||||||
lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
|
lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
|
||||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
// FIXME: There's no way to report errors back to the user
|
// FIXME: There's no way to report errors back to the user
|
||||||
lua_pushstring(L, str);
|
lua_pushstring(L, str);
|
||||||
lua_pcall(L, 1, 0, 0);
|
lua_pcall(L, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LLDBSwigLuaCloseFileHandle(lua_State *L) {
|
static int LLDBSwigLuaCloseFileHandle(lua_State * L) {
|
||||||
return luaL_error(L, "You cannot close a file handle used by lldb.");
|
return luaL_error(L, "You cannot close a file handle used by lldb.");
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -12,22 +12,22 @@
|
||||||
PythonList list(PyRefType::Borrowed, $input);
|
PythonList list(PyRefType::Borrowed, $input);
|
||||||
int size = list.GetSize();
|
int size = list.GetSize();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
$1 = (char**)malloc((size+1)*sizeof(char*));
|
$1 = (char **)malloc((size + 1) * sizeof(char *));
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>();
|
PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>();
|
||||||
if (!py_str.IsAllocated()) {
|
if (!py_str.IsAllocated()) {
|
||||||
PyErr_SetString(PyExc_TypeError,"list must contain strings");
|
PyErr_SetString(PyExc_TypeError, "list must contain strings");
|
||||||
free($1);
|
free($1);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
$1[i] = const_cast<char*>(py_str.GetString().data());
|
$1[i] = const_cast<char *>(py_str.GetString().data());
|
||||||
}
|
}
|
||||||
$1[i] = 0;
|
$1[i] = 0;
|
||||||
} else if ($input == Py_None) {
|
} else if ($input == Py_None) {
|
||||||
$1 = NULL;
|
$1 = NULL;
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError,"not a list");
|
PyErr_SetString(PyExc_TypeError, "not a list");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
PythonString s = list.GetItemAtIndex(i).AsType<PythonString>();
|
PythonString s = list.GetItemAtIndex(i).AsType<PythonString>();
|
||||||
if (!s.IsAllocated()) { $1 = 0; }
|
if (!s.IsAllocated()) {
|
||||||
|
$1 = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
$1 = (($input == Py_None) ? 1 : 0);
|
||||||
{
|
|
||||||
$1 = ( ($input == Py_None) ? 1 : 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,8 @@
|
||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
len = 0;
|
len = 0;
|
||||||
while ($1[len]) len++;
|
while ($1[len])
|
||||||
|
len++;
|
||||||
PythonList list(len);
|
PythonList list(len);
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
list.SetItemAtIndex(i, PythonString($1[i]));
|
list.SetItemAtIndex(i, PythonString($1[i]));
|
||||||
|
@ -76,7 +77,7 @@
|
||||||
%typemap(in) lldb::StateType {
|
%typemap(in) lldb::StateType {
|
||||||
PythonObject obj = Retain<PythonObject>($input);
|
PythonObject obj = Retain<PythonObject>($input);
|
||||||
unsigned long long state_type_value =
|
unsigned long long state_type_value =
|
||||||
unwrapOrSetPythonException(As<unsigned long long>(obj));
|
unwrapOrSetPythonException(As<unsigned long long>(obj));
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (state_type_value > lldb::StateType::kLastStateType) {
|
if (state_type_value > lldb::StateType::kLastStateType) {
|
||||||
|
@ -90,16 +91,16 @@
|
||||||
|
|
||||||
// typemap for a char buffer
|
// typemap for a char buffer
|
||||||
%typemap(in) (char *dst, size_t dst_len) {
|
%typemap(in) (char *dst, size_t dst_len) {
|
||||||
if (!PyInt_Check($input)) {
|
if (!PyInt_Check($input)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Expecting an integer");
|
PyErr_SetString(PyExc_ValueError, "Expecting an integer");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
$2 = PyInt_AsLong($input);
|
$2 = PyInt_AsLong($input);
|
||||||
if ($2 <= 0) {
|
if ($2 <= 0) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
$1 = (char *) malloc($2);
|
$1 = (char *)malloc($2);
|
||||||
}
|
}
|
||||||
// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated
|
// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated
|
||||||
// as char data instead of byte data.
|
// as char data instead of byte data.
|
||||||
|
@ -107,17 +108,17 @@
|
||||||
|
|
||||||
// Return the char buffer. Discarding any previous return result
|
// Return the char buffer. Discarding any previous return result
|
||||||
%typemap(argout) (char *dst, size_t dst_len) {
|
%typemap(argout) (char *dst, size_t dst_len) {
|
||||||
Py_XDECREF($result); /* Blow away any previous result */
|
Py_XDECREF($result); /* Blow away any previous result */
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
PythonString string("");
|
PythonString string("");
|
||||||
$result = string.release();
|
$result = string.release();
|
||||||
Py_INCREF($result);
|
Py_INCREF($result);
|
||||||
} else {
|
} else {
|
||||||
llvm::StringRef ref(static_cast<const char*>($1), result);
|
llvm::StringRef ref(static_cast<const char *>($1), result);
|
||||||
PythonString string(ref);
|
PythonString string(ref);
|
||||||
$result = string.release();
|
$result = string.release();
|
||||||
}
|
}
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated
|
// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated
|
||||||
// as char data instead of byte data.
|
// as char data instead of byte data.
|
||||||
|
@ -126,23 +127,23 @@
|
||||||
|
|
||||||
// typemap for handling an snprintf-like API like SBThread::GetStopDescription.
|
// typemap for handling an snprintf-like API like SBThread::GetStopDescription.
|
||||||
%typemap(in) (char *dst_or_null, size_t dst_len) {
|
%typemap(in) (char *dst_or_null, size_t dst_len) {
|
||||||
if (!PyInt_Check($input)) {
|
if (!PyInt_Check($input)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Expecting an integer");
|
PyErr_SetString(PyExc_ValueError, "Expecting an integer");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
$2 = PyInt_AsLong($input);
|
$2 = PyInt_AsLong($input);
|
||||||
if ($2 <= 0) {
|
if ($2 <= 0) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
$1 = (char *) malloc($2);
|
$1 = (char *)malloc($2);
|
||||||
}
|
}
|
||||||
%typemap(argout) (char *dst_or_null, size_t dst_len) {
|
%typemap(argout) (char *dst_or_null, size_t dst_len) {
|
||||||
Py_XDECREF($result); /* Blow away any previous result */
|
Py_XDECREF($result); /* Blow away any previous result */
|
||||||
llvm::StringRef ref($1);
|
llvm::StringRef ref($1);
|
||||||
PythonString string(ref);
|
PythonString string(ref);
|
||||||
$result = string.release();
|
$result = string.release();
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,80 +152,74 @@
|
||||||
// Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len).
|
// Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len).
|
||||||
%typemap(in) (const char *cstr, uint32_t cstr_len),
|
%typemap(in) (const char *cstr, uint32_t cstr_len),
|
||||||
(const char *src, size_t src_len) {
|
(const char *src, size_t src_len) {
|
||||||
if (PythonString::Check($input)) {
|
if (PythonString::Check($input)) {
|
||||||
PythonString str(PyRefType::Borrowed, $input);
|
PythonString str(PyRefType::Borrowed, $input);
|
||||||
$1 = (char*)str.GetString().data();
|
$1 = (char *)str.GetString().data();
|
||||||
$2 = str.GetSize();
|
$2 = str.GetSize();
|
||||||
}
|
} else if (PythonByteArray::Check($input)) {
|
||||||
else if(PythonByteArray::Check($input)) {
|
PythonByteArray bytearray(PyRefType::Borrowed, $input);
|
||||||
PythonByteArray bytearray(PyRefType::Borrowed, $input);
|
$1 = (char *)bytearray.GetBytes().data();
|
||||||
$1 = (char*)bytearray.GetBytes().data();
|
$2 = bytearray.GetSize();
|
||||||
$2 = bytearray.GetSize();
|
} else if (PythonBytes::Check($input)) {
|
||||||
}
|
PythonBytes bytes(PyRefType::Borrowed, $input);
|
||||||
else if (PythonBytes::Check($input)) {
|
$1 = (char *)bytes.GetBytes().data();
|
||||||
PythonBytes bytes(PyRefType::Borrowed, $input);
|
$2 = bytes.GetSize();
|
||||||
$1 = (char*)bytes.GetBytes().data();
|
} else {
|
||||||
$2 = bytes.GetSize();
|
PyErr_SetString(PyExc_ValueError, "Expecting a string");
|
||||||
}
|
return NULL;
|
||||||
else {
|
}
|
||||||
PyErr_SetString(PyExc_ValueError, "Expecting a string");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// For SBProcess::WriteMemory, SBTarget::GetInstructions and SBDebugger::DispatchInput.
|
// For SBProcess::WriteMemory, SBTarget::GetInstructions and SBDebugger::DispatchInput.
|
||||||
%typemap(in) (const void *buf, size_t size),
|
%typemap(in) (const void *buf, size_t size),
|
||||||
(const void *data, size_t data_len) {
|
(const void *data, size_t data_len) {
|
||||||
if (PythonString::Check($input)) {
|
if (PythonString::Check($input)) {
|
||||||
PythonString str(PyRefType::Borrowed, $input);
|
PythonString str(PyRefType::Borrowed, $input);
|
||||||
$1 = (void*)str.GetString().data();
|
$1 = (void *)str.GetString().data();
|
||||||
$2 = str.GetSize();
|
$2 = str.GetSize();
|
||||||
}
|
} else if (PythonByteArray::Check($input)) {
|
||||||
else if(PythonByteArray::Check($input)) {
|
PythonByteArray bytearray(PyRefType::Borrowed, $input);
|
||||||
PythonByteArray bytearray(PyRefType::Borrowed, $input);
|
$1 = (void *)bytearray.GetBytes().data();
|
||||||
$1 = (void*)bytearray.GetBytes().data();
|
$2 = bytearray.GetSize();
|
||||||
$2 = bytearray.GetSize();
|
} else if (PythonBytes::Check($input)) {
|
||||||
}
|
PythonBytes bytes(PyRefType::Borrowed, $input);
|
||||||
else if (PythonBytes::Check($input)) {
|
$1 = (void *)bytes.GetBytes().data();
|
||||||
PythonBytes bytes(PyRefType::Borrowed, $input);
|
$2 = bytes.GetSize();
|
||||||
$1 = (void*)bytes.GetBytes().data();
|
} else {
|
||||||
$2 = bytes.GetSize();
|
PyErr_SetString(PyExc_ValueError, "Expecting a buffer");
|
||||||
}
|
return NULL;
|
||||||
else {
|
}
|
||||||
PyErr_SetString(PyExc_ValueError, "Expecting a buffer");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// typemap for an incoming buffer
|
// typemap for an incoming buffer
|
||||||
// See also SBProcess::ReadMemory.
|
// See also SBProcess::ReadMemory.
|
||||||
%typemap(in) (void *buf, size_t size) {
|
%typemap(in) (void *buf, size_t size) {
|
||||||
if (PyInt_Check($input)) {
|
if (PyInt_Check($input)) {
|
||||||
$2 = PyInt_AsLong($input);
|
$2 = PyInt_AsLong($input);
|
||||||
} else if (PyLong_Check($input)) {
|
} else if (PyLong_Check($input)) {
|
||||||
$2 = PyLong_AsLong($input);
|
$2 = PyLong_AsLong($input);
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_ValueError, "Expecting an integer or long object");
|
PyErr_SetString(PyExc_ValueError, "Expecting an integer or long object");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ($2 <= 0) {
|
if ($2 <= 0) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
$1 = (void *) malloc($2);
|
$1 = (void *)malloc($2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the buffer. Discarding any previous return result
|
// Return the buffer. Discarding any previous return result
|
||||||
// See also SBProcess::ReadMemory.
|
// See also SBProcess::ReadMemory.
|
||||||
%typemap(argout) (void *buf, size_t size) {
|
%typemap(argout) (void *buf, size_t size) {
|
||||||
Py_XDECREF($result); /* Blow away any previous result */
|
Py_XDECREF($result); /* Blow away any previous result */
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
$result = Py_None;
|
$result = Py_None;
|
||||||
Py_INCREF($result);
|
Py_INCREF($result);
|
||||||
} else {
|
} else {
|
||||||
PythonBytes bytes(static_cast<const uint8_t*>($1), result);
|
PythonBytes bytes(static_cast<const uint8_t *>($1), result);
|
||||||
$result = bytes.release();
|
$result = bytes.release();
|
||||||
}
|
}
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
@ -250,19 +245,18 @@ template <> int32_t PyLongAsT<int32_t>(PyObject *obj) {
|
||||||
return static_cast<int32_t>(PyLong_AsLong(obj));
|
return static_cast<int32_t>(PyLong_AsLong(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T> bool SetNumberFromPyObject(T &number, PyObject *obj) {
|
||||||
bool SetNumberFromPyObject(T &number, PyObject *obj) {
|
|
||||||
if (PyInt_Check(obj))
|
if (PyInt_Check(obj))
|
||||||
number = static_cast<T>(PyInt_AsLong(obj));
|
number = static_cast<T>(PyInt_AsLong(obj));
|
||||||
else if (PyLong_Check(obj))
|
else if (PyLong_Check(obj))
|
||||||
number = PyLongAsT<T>(obj);
|
number = PyLongAsT<T>(obj);
|
||||||
else return false;
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
|
||||||
if (PyFloat_Check(obj)) {
|
if (PyFloat_Check(obj)) {
|
||||||
number = PyFloat_AsDouble(obj);
|
number = PyFloat_AsDouble(obj);
|
||||||
return true;
|
return true;
|
||||||
|
@ -287,11 +281,11 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
int size = PyList_Size($input);
|
int size = PyList_Size($input);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
$2 = size;
|
$2 = size;
|
||||||
$1 = ($1_type) malloc(size * sizeof($*1_type));
|
$1 = ($1_type)malloc(size * sizeof($*1_type));
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
PyObject *o = PyList_GetItem($input,i);
|
PyObject *o = PyList_GetItem($input, i);
|
||||||
if (!SetNumberFromPyObject($1[i], o)) {
|
if (!SetNumberFromPyObject($1[i], o)) {
|
||||||
PyErr_SetString(PyExc_TypeError,"list must contain numbers");
|
PyErr_SetString(PyExc_TypeError, "list must contain numbers");
|
||||||
free($1);
|
free($1);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -302,10 +296,10 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($input == Py_None) {
|
} else if ($input == Py_None) {
|
||||||
$1 = NULL;
|
$1 = NULL;
|
||||||
$2 = 0;
|
$2 = 0;
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError,"not a list");
|
PyErr_SetString(PyExc_TypeError, "not a list");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,43 +316,42 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
// to the more Pythonic style where a list is returned and no previous allocation
|
// to the more Pythonic style where a list is returned and no previous allocation
|
||||||
// is necessary - this will break if more than 50 versions are ever returned
|
// is necessary - this will break if more than 50 versions are ever returned
|
||||||
%typemap(typecheck) (uint32_t *versions, uint32_t num_versions) {
|
%typemap(typecheck) (uint32_t *versions, uint32_t num_versions) {
|
||||||
$1 = ($input == Py_None ? 1 : 0);
|
$1 = ($input == Py_None ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(in, numinputs=0) (uint32_t *versions) {
|
%typemap(in, numinputs=0) (uint32_t *versions) {
|
||||||
$1 = (uint32_t*)malloc(sizeof(uint32_t) * 50);
|
$1 = (uint32_t *)malloc(sizeof(uint32_t) * 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(in, numinputs=0) (uint32_t num_versions) {
|
%typemap(in, numinputs=0) (uint32_t num_versions) {
|
||||||
$1 = 50;
|
$1 = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(argout) (uint32_t *versions, uint32_t num_versions) {
|
%typemap(argout) (uint32_t *versions, uint32_t num_versions) {
|
||||||
uint32_t count = result;
|
uint32_t count = result;
|
||||||
if (count >= $2)
|
if (count >= $2)
|
||||||
count = $2;
|
count = $2;
|
||||||
PyObject* list = PyList_New(count);
|
PyObject *list = PyList_New(count);
|
||||||
for (uint32_t j = 0; j < count; j++)
|
for (uint32_t j = 0; j < count; j++) {
|
||||||
{
|
PyObject *item = PyInt_FromLong($1[j]);
|
||||||
PyObject* item = PyInt_FromLong($1[j]);
|
int ok = PyList_SetItem(list, j, item);
|
||||||
int ok = PyList_SetItem(list,j,item);
|
if (ok != 0) {
|
||||||
if (ok != 0)
|
$result = Py_None;
|
||||||
{
|
break;
|
||||||
$result = Py_None;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$result = list;
|
}
|
||||||
|
$result = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(freearg) (uint32_t *versions) {
|
%typemap(freearg) (uint32_t *versions) {
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// For Log::LogOutputCallback
|
// For Log::LogOutputCallback
|
||||||
%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
|
%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
|
||||||
if (!($input == Py_None || PyCallable_Check(reinterpret_cast<PyObject*>($input)))) {
|
if (!($input == Py_None ||
|
||||||
|
PyCallable_Check(reinterpret_cast<PyObject *>($input)))) {
|
||||||
PyErr_SetString(PyExc_TypeError, "Need a callable object or None!");
|
PyErr_SetString(PyExc_TypeError, "Need a callable object or None!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -376,7 +369,7 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
|
|
||||||
%typemap(typecheck) (lldb::LogOutputCallback log_callback, void *baton) {
|
%typemap(typecheck) (lldb::LogOutputCallback log_callback, void *baton) {
|
||||||
$1 = $input == Py_None;
|
$1 = $input == Py_None;
|
||||||
$1 = $1 || PyCallable_Check(reinterpret_cast<PyObject*>($input));
|
$1 = $1 || PyCallable_Check(reinterpret_cast<PyObject *>($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -398,7 +391,8 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
PyErr_SetString(PyExc_TypeError, "not a file");
|
PyErr_SetString(PyExc_TypeError, "not a file");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto sp = unwrapOrSetPythonException(py_file.ConvertToFileForcingUseOfScriptingIOMethods());
|
auto sp = unwrapOrSetPythonException(
|
||||||
|
py_file.ConvertToFileForcingUseOfScriptingIOMethods());
|
||||||
if (!sp)
|
if (!sp)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
$1 = sp;
|
$1 = sp;
|
||||||
|
@ -410,7 +404,8 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
PyErr_SetString(PyExc_TypeError, "not a file");
|
PyErr_SetString(PyExc_TypeError, "not a file");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto sp = unwrapOrSetPythonException(py_file.ConvertToFile(/*borrowed=*/true));
|
auto sp =
|
||||||
|
unwrapOrSetPythonException(py_file.ConvertToFile(/*borrowed=*/true));
|
||||||
if (!sp)
|
if (!sp)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
$1 = sp;
|
$1 = sp;
|
||||||
|
@ -422,7 +417,8 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
PyErr_SetString(PyExc_TypeError, "not a file");
|
PyErr_SetString(PyExc_TypeError, "not a file");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto sp = unwrapOrSetPythonException(py_file.ConvertToFileForcingUseOfScriptingIOMethods(/*borrowed=*/true));
|
auto sp = unwrapOrSetPythonException(
|
||||||
|
py_file.ConvertToFileForcingUseOfScriptingIOMethods(/*borrowed=*/true));
|
||||||
if (!sp)
|
if (!sp)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
$1 = sp;
|
$1 = sp;
|
||||||
|
@ -446,40 +442,34 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
$result = pyfile.release();
|
$result = pyfile.release();
|
||||||
}
|
}
|
||||||
if (!$result)
|
if (!$result) {
|
||||||
{
|
$result = Py_None;
|
||||||
$result = Py_None;
|
Py_INCREF(Py_None);
|
||||||
Py_INCREF(Py_None);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(in) (const char* string, int len) {
|
%typemap(in) (const char* string, int len) {
|
||||||
if ($input == Py_None)
|
if ($input == Py_None) {
|
||||||
{
|
$1 = NULL;
|
||||||
$1 = NULL;
|
$2 = 0;
|
||||||
$2 = 0;
|
} else if (PythonString::Check($input)) {
|
||||||
}
|
PythonString py_str(PyRefType::Borrowed, $input);
|
||||||
else if (PythonString::Check($input))
|
llvm::StringRef str = py_str.GetString();
|
||||||
{
|
$1 = const_cast<char *>(str.data());
|
||||||
PythonString py_str(PyRefType::Borrowed, $input);
|
$2 = str.size();
|
||||||
llvm::StringRef str = py_str.GetString();
|
// In Python 2, if $input is a PyUnicode object then this
|
||||||
$1 = const_cast<char*>(str.data());
|
// will trigger a Unicode -> String conversion, in which
|
||||||
$2 = str.size();
|
// case the `PythonString` will now own the PyString. Thus
|
||||||
// In Python 2, if $input is a PyUnicode object then this
|
// if it goes out of scope, the data will be deleted. The
|
||||||
// will trigger a Unicode -> String conversion, in which
|
// only way to avoid this is to leak the Python object in
|
||||||
// case the `PythonString` will now own the PyString. Thus
|
// that case. Note that if there was no conversion, then
|
||||||
// if it goes out of scope, the data will be deleted. The
|
// releasing the string will not leak anything, since we
|
||||||
// only way to avoid this is to leak the Python object in
|
// created this as a borrowed reference.
|
||||||
// that case. Note that if there was no conversion, then
|
py_str.release();
|
||||||
// releasing the string will not leak anything, since we
|
} else {
|
||||||
// created this as a borrowed reference.
|
PyErr_SetString(PyExc_TypeError, "not a string-like object");
|
||||||
py_str.release();
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_TypeError,"not a string-like object");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
|
// These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
|
||||||
|
@ -491,7 +481,9 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
|
|
||||||
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
|
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
|
||||||
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
|
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
|
||||||
int res; Py_ssize_t size = 0; void *buf = 0;
|
int res;
|
||||||
|
Py_ssize_t size = 0;
|
||||||
|
void *buf = 0;
|
||||||
res = PyObject_GetBuffer($input, &view.buffer, PyBUF_WRITABLE);
|
res = PyObject_GetBuffer($input, &view.buffer, PyBUF_WRITABLE);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -499,14 +491,16 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
}
|
}
|
||||||
size = view.buffer.len;
|
size = view.buffer.len;
|
||||||
buf = view.buffer.buf;
|
buf = view.buffer.buf;
|
||||||
$1 = ($1_ltype) buf;
|
$1 = ($1_ltype)buf;
|
||||||
$2 = ($2_ltype) (size/sizeof($*1_type));
|
$2 = ($2_ltype)(size / sizeof($*1_type));
|
||||||
}
|
}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%define %pybuffer_binary(TYPEMAP, SIZE)
|
%define %pybuffer_binary(TYPEMAP, SIZE)
|
||||||
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
|
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
|
||||||
int res; Py_ssize_t size = 0; const void *buf = 0;
|
int res;
|
||||||
|
Py_ssize_t size = 0;
|
||||||
|
const void *buf = 0;
|
||||||
res = PyObject_GetBuffer($input, &view.buffer, PyBUF_CONTIG_RO);
|
res = PyObject_GetBuffer($input, &view.buffer, PyBUF_CONTIG_RO);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -514,8 +508,8 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
}
|
}
|
||||||
size = view.buffer.len;
|
size = view.buffer.len;
|
||||||
buf = view.buffer.buf;
|
buf = view.buffer.buf;
|
||||||
$1 = ($1_ltype) buf;
|
$1 = ($1_ltype)buf;
|
||||||
$2 = ($2_ltype) (size / sizeof($*1_type));
|
$2 = ($2_ltype)(size / sizeof($*1_type));
|
||||||
}
|
}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue