/////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2001-2011, Industrial Light & Magic, a division of Lucas // Digital Ltd. LLC // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Industrial Light & Magic nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include using namespace boost::python; using namespace IEX_NAMESPACE; namespace PyIex { namespace { static void translateBaseExc(const IEX_NAMESPACE::BaseExc &exc) { PyErr_SetObject(baseExcTranslator().typeObject(&exc),ExcTranslator::convert(exc)); } void registerBaseExc() { using namespace boost::python; std::string name = "BaseExc"; std::string module = "iex"; std::string baseName = "RuntimeError"; std::string baseModule = "__builtin__"; // if module != baseModule, the type object isn't used object exc_class = createExceptionProxy(name, module, baseName, baseModule, 0); scope().attr(name.c_str()) = exc_class; setBaseExcTranslator(new TypeTranslator(name, module, exc_class.ptr())); // to python to_python_converter >(); // from python converter::registry::push_back(&ExcTranslator::convertible, &ExcTranslator::construct,type_id()); // exception translation for BaseExc and subtypes register_exception_translator(&translateBaseExc); } void testCxxExceptions (int i) { // // This function is only for testing. // It exercises the PY_TRY / PY_CATCH macros // and the C++ to Python exception translation. // switch (i) { case 1: throw int (1); case 2: throw std::invalid_argument ("2"); case 3: throw IEX_NAMESPACE::BaseExc ("3"); case 4: throw IEX_NAMESPACE::ArgExc ("4"); default: ; } } std::string testBaseExcString(const BaseExc &exc) { return exc.what(); } std::string testArgExcString(const ArgExc &exc) { return exc.what(); } BaseExc testMakeBaseExc(const std::string &s) { return BaseExc(s); } ArgExc testMakeArgExc(const std::string &s) { return ArgExc(s); } } // namespace } // namespace PyIex using namespace PyIex; BOOST_PYTHON_MODULE(iex) { using namespace IEX_NAMESPACE; def("testCxxExceptions", &testCxxExceptions); def("testBaseExcString", &testBaseExcString); def("testArgExcString", &testArgExcString); def("testMakeBaseExc", &testMakeBaseExc); def("testMakeArgExc", &testMakeArgExc); registerBaseExc(); registerExc("ArgExc","iex"); registerExc("LogicExc","iex"); registerExc("InputExc","iex"); registerExc("IoExc","iex"); registerExc("MathExc","iex"); registerExc("NoImplExc","iex"); registerExc("NullExc","iex"); registerExc("TypeExc","iex"); registerExc("ErrnoExc","iex"); registerExc("EpermExc","iex"); registerExc("EnoentExc","iex"); registerExc("EsrchExc","iex"); registerExc("EintrExc","iex"); registerExc("EioExc","iex"); registerExc("EnxioExc","iex"); registerExc("E2bigExc","iex"); registerExc("EnoexecExc","iex"); registerExc("EbadfExc","iex"); registerExc("EchildExc","iex"); registerExc("EagainExc","iex"); registerExc("EnomemExc","iex"); registerExc("EaccesExc","iex"); registerExc("EfaultExc","iex"); registerExc("EnotblkExc","iex"); registerExc("EbusyExc","iex"); registerExc("EexistExc","iex"); registerExc("ExdevExc","iex"); registerExc("EnodevExc","iex"); registerExc("EnotdirExc","iex"); registerExc("EisdirExc","iex"); registerExc("EinvalExc","iex"); registerExc("EnfileExc","iex"); registerExc("EmfileExc","iex"); registerExc("EnottyExc","iex"); registerExc("EtxtbsyExc","iex"); registerExc("EfbigExc","iex"); registerExc("EnospcExc","iex"); registerExc("EspipeExc","iex"); registerExc("ErofsExc","iex"); registerExc("EmlinkExc","iex"); registerExc("EpipeExc","iex"); registerExc("EdomExc","iex"); registerExc("ErangeExc","iex"); registerExc("EnomsgExc","iex"); registerExc("EidrmExc","iex"); registerExc("EchrngExc","iex"); registerExc("El2nsyncExc","iex"); registerExc("El3hltExc","iex"); registerExc("El3rstExc","iex"); registerExc("ElnrngExc","iex"); registerExc("EunatchExc","iex"); registerExc("EnocsiExc","iex"); registerExc("El2hltExc","iex"); registerExc("EdeadlkExc","iex"); registerExc("EnolckExc","iex"); registerExc("EbadeExc","iex"); registerExc("EbadrExc","iex"); registerExc("ExfullExc","iex"); registerExc("EnoanoExc","iex"); registerExc("EbadrqcExc","iex"); registerExc("EbadsltExc","iex"); registerExc("EdeadlockExc","iex"); registerExc("EbfontExc","iex"); registerExc("EnostrExc","iex"); registerExc("EnodataExc","iex"); registerExc("EtimeExc","iex"); registerExc("EnosrExc","iex"); registerExc("EnonetExc","iex"); registerExc("EnopkgExc","iex"); registerExc("EremoteExc","iex"); registerExc("EnolinkExc","iex"); registerExc("EadvExc","iex"); registerExc("EsrmntExc","iex"); registerExc("EcommExc","iex"); registerExc("EprotoExc","iex"); registerExc("EmultihopExc","iex"); registerExc("EbadmsgExc","iex"); registerExc("EnametoolongExc","iex"); registerExc("EoverflowExc","iex"); registerExc("EnotuniqExc","iex"); registerExc("EbadfdExc","iex"); registerExc("EremchgExc","iex"); registerExc("ElibaccExc","iex"); registerExc("ElibbadExc","iex"); registerExc("ElibscnExc","iex"); registerExc("ElibmaxExc","iex"); registerExc("ElibexecExc","iex"); registerExc("EilseqExc","iex"); registerExc("EnosysExc","iex"); registerExc("EloopExc","iex"); registerExc("ErestartExc","iex"); registerExc("EstrpipeExc","iex"); registerExc("EnotemptyExc","iex"); registerExc("EusersExc","iex"); registerExc("EnotsockExc","iex"); registerExc("EdestaddrreqExc","iex"); registerExc("EmsgsizeExc","iex"); registerExc("EprototypeExc","iex"); registerExc("EnoprotooptExc","iex"); registerExc("EprotonosupportExc","iex"); registerExc("EsocktnosupportExc","iex"); registerExc("EopnotsuppExc","iex"); registerExc("EpfnosupportExc","iex"); registerExc("EafnosupportExc","iex"); registerExc("EaddrinuseExc","iex"); registerExc("EaddrnotavailExc","iex"); registerExc("EnetdownExc","iex"); registerExc("EnetunreachExc","iex"); registerExc("EnetresetExc","iex"); registerExc("EconnabortedExc","iex"); registerExc("EconnresetExc","iex"); registerExc("EnobufsExc","iex"); registerExc("EisconnExc","iex"); registerExc("EnotconnExc","iex"); registerExc("EshutdownExc","iex"); registerExc("EtoomanyrefsExc","iex"); registerExc("EtimedoutExc","iex"); registerExc("EconnrefusedExc","iex"); registerExc("EhostdownExc","iex"); registerExc("EhostunreachExc","iex"); registerExc("EalreadyExc","iex"); registerExc("EinprogressExc","iex"); registerExc("EstaleExc","iex"); registerExc("EioresidExc","iex"); registerExc("EucleanExc","iex"); registerExc("EnotnamExc","iex"); registerExc("EnavailExc","iex"); registerExc("EisnamExc","iex"); registerExc("EremoteioExc","iex"); registerExc("EinitExc","iex"); registerExc("EremdevExc","iex"); registerExc("EcanceledExc","iex"); registerExc("EnolimfileExc","iex"); registerExc("EproclimExc","iex"); registerExc("EdisjointExc","iex"); registerExc("EnologinExc","iex"); registerExc("EloginlimExc","iex"); registerExc("EgrouploopExc","iex"); registerExc("EnoattachExc","iex"); registerExc("EnotsupExc","iex"); registerExc("EnoattrExc","iex"); registerExc("EdircorruptedExc","iex"); registerExc("EdquotExc","iex"); registerExc("EnfsremoteExc","iex"); registerExc("EcontrollerExc","iex"); registerExc("EnotcontrollerExc","iex"); registerExc("EenqueuedExc","iex"); registerExc("EnotenqueuedExc","iex"); registerExc("EjoinedExc","iex"); registerExc("EnotjoinedExc","iex"); registerExc("EnoprocExc","iex"); registerExc("EmustrunExc","iex"); registerExc("EnotstoppedExc","iex"); registerExc("EclockcpuExc","iex"); registerExc("EinvalstateExc","iex"); registerExc("EnoexistExc","iex"); registerExc("EendofminorExc","iex"); registerExc("EbufsizeExc","iex"); registerExc("EemptyExc","iex"); registerExc("EnointrgroupExc","iex"); registerExc("EinvalmodeExc","iex"); registerExc("EcantextentExc","iex"); registerExc("EinvaltimeExc","iex"); registerExc("EdestroyedExc","iex"); }