logo       

Re: warnings when using directors with multiple throw specifiers: msg#00205

programming.swig

Subject: Re: warnings when using directors with multiple throw specifiers

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:
FYI, I discovered the SWIG_TypeCheck, TypeCast etc. etc. methods. It seems I should be using these so I'm going to try to do so. I was unable to find any documentation on these methods however. Are these safe to use and if so is there anywhere that describes their proper use? I only discovered them when I was looking to see what SWIG_ConvertPtr was doing.

http://www.swig.org/Doc1.3/Typemaps.html#n42 has a basic explination, but nothing about TypeCheck and TypeCast

I have made some modifications to the type system, and have a little better documentation available here...
http://www.cs.wisc.edu/~lenz/swig.html

When reading that site, just remember that the current SWIG type system does not have a swig_module_info structure and that the swig_type_info and swig_cast_info structures are actually one big structure that gets used for two different purposes.

The TypeCheck and TypeCast functions are mainly to deal with the problem of multiple inheritance. Each type in the type system stores a linked list of types which are eqivelent to it. TypeCheck will walk along this linked list, checking if the two types are equivelent.

If TypeCheck finds a match, then TypeCast should be called. TypeCast should be called with the return value from TypeCheck. TypeCast deals with the problem of multiple inheritance, that is, it makes sure the pointer is pointing at the base of the object.

John


_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise