diff options
Diffstat (limited to 'py/modules/IcePy/Slice.cpp')
-rw-r--r-- | py/modules/IcePy/Slice.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/py/modules/IcePy/Slice.cpp b/py/modules/IcePy/Slice.cpp index 3d8862182fd..9adccc5e4c3 100644 --- a/py/modules/IcePy/Slice.cpp +++ b/py/modules/IcePy/Slice.cpp @@ -14,6 +14,7 @@ #include <Util.h> #include <Slice/Preprocessor.h> #include <Slice/PythonUtil.h> +#include <Slice/Util.h> #include <IceUtil/Options.h> // @@ -199,3 +200,60 @@ IcePy_loadSlice(PyObject* /*self*/, PyObject* args) Py_INCREF(Py_None); return Py_None; } + +extern "C" +PyObject* +IcePy_compile(PyObject* /*self*/, PyObject* args) +{ + PyObject* list = 0; + if(!PyArg_ParseTuple(args, STRCAST("O!"), &PyList_Type, &list)) + { + return 0; + } + + vector<string> argSeq; + if(list) + { + if(!listToStringSeq(list, argSeq)) + { + return 0; + } + } + + char** argv = new char*[argSeq.size()]; + for(size_t i = 0; i < argSeq.size(); ++i) + { + argv[i] = const_cast<char*>(argSeq[i].c_str()); + } + + int rc; + try + { + rc = Slice::Python::compile(static_cast<int>(argSeq.size()), argv); + } + catch(const std::exception& ex) + { + getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + rc = EXIT_FAILURE; + } + catch(const std::string& msg) + { + getErrorStream() << argv[0] << ": error:" << msg << endl; + rc = EXIT_FAILURE; + } + catch(const char* msg) + { + getErrorStream() << argv[0] << ": error:" << msg << endl; + rc = EXIT_FAILURE; + } + catch(...) + { + getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + rc = EXIT_FAILURE; + } + + delete[] argv; + + // PyInt_FromLong doesn't exist in python 3. + return PyLong_FromLong(rc); +} |