This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Checked casts in CNI


Anthony Green wrote:

I'm slowly debugging Azureus.

The most recent problem I hit was some CNI code in
natPlainDatagramSocketImplPosix.cc that was casting a Boolean into a
InetAddress.  I have a rough patch for this now, but I wonder what other
bugs like this exist.

I think it would be useful to have a new CNI casting macro that would
call isAddressableFrom() and throw ClassCastExceptions.

So, instead of

addr = (::java::net::InetAddress *) value;

you would write:

addr = _Jv_CheckedCast (::java::net::InetAddress, value);

or something like that. What do you think?



I think this is a good idea, although it would be even nicer if we could make it use the C++-style casting syntax. For example:


addr = java_cast<::java::net::InetAddress> (value);

Note that we already have _Jv_CheckCast() which looks just like what you posted above, except it returns a void * pointer and not the actual cast type.

Bryce


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]