mirror of
https://github.com/cemu-project/idapython.git
synced 2024-12-28 18:51:53 +01:00
fix for the $PATH issue on OSX by setting proper home path (thanks to igorsk)
This commit is contained in:
parent
15a72289f7
commit
c1d87c0c7c
33
python.cpp
33
python.cpp
@ -23,6 +23,9 @@
|
|||||||
#ifdef __LINUX__
|
#ifdef __LINUX__
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __MAC__
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
#endif
|
||||||
#include <ida.hpp>
|
#include <ida.hpp>
|
||||||
#include <idp.hpp>
|
#include <idp.hpp>
|
||||||
#include <ieee.h>
|
#include <ieee.h>
|
||||||
@ -1034,19 +1037,19 @@ bool idaapi IDAPYthon_cli_complete_line(
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
PyObject *py_ret = PyObject_CallFunction(py_complete, "sisi", prefix, n, line, x);
|
PyObject *py_ret = PyObject_CallFunction(py_complete, "sisi", prefix, n, line, x);
|
||||||
|
|
||||||
Py_DECREF(py_complete);
|
Py_DECREF(py_complete);
|
||||||
|
|
||||||
// Swallow the error
|
// Swallow the error
|
||||||
PyW_GetError(completion);
|
PyW_GetError(completion);
|
||||||
|
|
||||||
bool ok = py_ret != NULL && PyString_Check(py_ret) != 0;
|
bool ok = py_ret != NULL && PyString_Check(py_ret) != 0;
|
||||||
|
|
||||||
if ( ok )
|
if ( ok )
|
||||||
*completion = PyString_AS_STRING(py_ret);
|
*completion = PyString_AS_STRING(py_ret);
|
||||||
|
|
||||||
Py_XDECREF(py_ret);
|
Py_XDECREF(py_ret);
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1208,6 +1211,28 @@ bool IDAPython_Init(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __MAC__
|
||||||
|
// We should set python home to the module's path, otherwise it can pick up stray modules from $PATH
|
||||||
|
NSModule pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
|
||||||
|
// Use dylib functions to find out where the framework was loaded from
|
||||||
|
const char *buf = (char *)NSLibraryNameForModule(pythonModule);
|
||||||
|
if ( buf != NULL )
|
||||||
|
{
|
||||||
|
// The path will be something like:
|
||||||
|
// /System/Library/Frameworks/Python.framework/Versions/2.5/Python
|
||||||
|
// We need to strip the last part
|
||||||
|
// use static buffer because Py_SetPythonHome() just stores a pointer
|
||||||
|
static char pyhomepath[MAXSTR];
|
||||||
|
qstrncpy(pyhomepath, buf, MAXSTR);
|
||||||
|
char * lastslash = strrchr(pyhomepath, '/');
|
||||||
|
if ( lastslash != NULL )
|
||||||
|
{
|
||||||
|
*lastslash = 0;
|
||||||
|
Py_SetPythonHome(pyhomepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Start the interpreter
|
// Start the interpreter
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
if ( !Py_IsInitialized() )
|
if ( !Py_IsInitialized() )
|
||||||
|
Loading…
Reference in New Issue
Block a user