|
Re: warnings when using directors with multiple throw specifiers: msg#00205programming.swig
Yeah, I actually wrote a new implementation of the director:except feature that I am much happier with. This looks to me like it might be the right way to do it. It also seems to me that there should be no reason swig can't generate this code as i would expect this to be the default behavior based on the throw specifiers. Let me know what you think. I still don't know what to do about the dangling references I was referring to previously however. Sorry about so much mail on this, I'm learning python, the python C API, and swig all at once. :( But I think I'm getting the hang of it now :) Anyway here is the new method I put together. If it is one of the the types I am expecting, it will pull the C++ exception out and throw a copy of it, dereference the objects, then rethrow to my library. If it is any other exception, it will print out the stack and shut down python. Here is the method. Let me know what you think and if you believe it would be possible/desirable to have swig generate something like this. And if anyone knows what to do about the dangling references, let me know. %feature("director:except") { if( $error != NULL ) { PyObject *ptype, *pvalue, *ptraceback; PyErr_Fetch( &ptype, &pvalue, &ptraceback ); void *result; try { if( SWIG_ConvertPtr(pvalue, &result, SWIGTYPE_p_FIX__DoNotSend, 0 ) != -1 ) { throw *((DoNotSend*)result); } else if( SWIG_ConvertPtr(pvalue, &result, SWIGTYPE_p_FIX__FieldNotFound, 0 ) != -1 ) { throw *((FieldNotFound*)result); } else if( SWIG_ConvertPtr(pvalue, &result, SWIGTYPE_p_FIX__IncorrectDataFormat, 0 ) != -1 ) { throw *((IncorrectDataFormat*)result); } else if( SWIG_ConvertPtr(pvalue, &result, SWIGTYPE_p_FIX__IncorrectTagValue, 0 ) != -1 ) { throw *((IncorrectTagValue*)result); } else if( SWIG_ConvertPtr(pvalue, &result, SWIGTYPE_p_FIX__RejectLogon, 0 ) != -1 ) { throw *((RejectLogon*)result); } else if( SWIG_ConvertPtr(pvalue, &result, SWIGTYPE_p_FIX__UnsupportedMessageType, 0 ) != -1 ) { throw *((UnsupportedMessageType*)result); } else { PyErr_Restore( ptype, pvalue, ptraceback ); PyErr_Print(); Py_Exit(1); } } catch( ... ) { Py_XDECREF( ptype ); Py_XDECREF( pvalue ); Py_XDECREF( ptraceback ); throw; } } } On May 30, 2004, at 3:47 PM, John Lenz wrote: On 2004.05.30 14:44, Oren Miller wrote: _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: warnings when using directors with multiple throw specifiers: 00205, John Lenz |
|---|---|
| Next by Date: | Reseting swigCMemOwn inside a method: 00205, camelo |
| Previous by Thread: | Re: warnings when using directors with multiple throw specifiersi: 00205, John Lenz |
| Next by Thread: | Re: warnings when using directors with multiple throw specifiers: 00205, Marcelo Matus |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |