Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
165 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// cxx_exceptions.cxx | ||
// | ||
#include <CXX/Exception.hxx> | ||
#include <CXX/Extensions.hxx> | ||
|
||
#include <map> | ||
|
||
namespace Py | ||
{ | ||
typedef void (*throw_exception_func_t)( void ); | ||
|
||
std::map<void *, throw_exception_func_t> py_exc_type_to_exc_func; | ||
|
||
void addPythonException( ExtensionExceptionType &py_exc_type, throw_exception_func_t func ) | ||
{ | ||
py_exc_type_to_exc_func.insert( std::make_pair( py_exc_type.ptr(), func ) ); | ||
} | ||
|
||
void addPythonException( PyObject *py_exc_type, throw_exception_func_t func ) | ||
{ | ||
py_exc_type_to_exc_func.insert( std::make_pair( py_exc_type, func ) ); | ||
} | ||
|
||
void ifPyErrorThrowCxxException() | ||
{ | ||
if( PyErr_Occurred() ) | ||
{ | ||
PyObject *ptype, *pvalue, *ptrace; | ||
PyErr_Fetch( &ptype, &pvalue, &ptrace ); | ||
PyErr_Restore( ptype, pvalue, ptrace ); | ||
|
||
Object q( ptype ); | ||
|
||
std::map<void *, throw_exception_func_t>::iterator func = py_exc_type_to_exc_func.find( ptype ); | ||
if( func != py_exc_type_to_exc_func.end() ) | ||
{ | ||
#ifdef PYCXX_DEBUG | ||
std::cout << "ifPyErrorThrowCxxException found throwFunc: " << q << std::endl; | ||
#endif | ||
(func->second)(); | ||
} | ||
else | ||
{ | ||
#ifdef PYCXX_DEBUG | ||
std::cout << "ifPyErrorThrowCxxException no throwFunc: " << q << std::endl; | ||
#endif | ||
throw Exception(); | ||
} | ||
} | ||
} | ||
|
||
void initExceptions() | ||
{ | ||
static bool init_done = false; | ||
if( init_done ) | ||
{ | ||
return; | ||
} | ||
|
||
#define PYCXX_STANDARD_EXCEPTION( eclass, bclass ) \ | ||
addPythonException( eclass::exceptionType(), eclass::throwFunc ); | ||
|
||
#include <CXX/Python3/cxx_standard_exceptions.hxx> | ||
|
||
#undef PYCXX_STANDARD_EXCEPTION | ||
|
||
init_done = true; | ||
} | ||
|
||
|
||
} // end of namespace Py |
Oops, something went wrong.