This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

Re: Fw: Returned message: Re: g++ -vs Java boolean


>>>>> "Mark" == Mark Mitchell <mark@codesourcery.com> writes:

Tom> That makes sense, since there is no way to tell that jboolean is
Tom> a "Java" type.

Mark> Right.  One thing we could do is turn off the error.  If these
Mark> things are really typedefs, then the compilers probably going to
Mark> lose track of the types at some point anyhow; we don't really
Mark> distinguish typedefs from their equivalents in the compiler.

I don't think we want to turn off the error.

In fact I think we added the error precisely because it helped us find
real bugs.

If you have a Java object with a native method, you could write your
C++ implementation like this:

	void my_java_object::method (int arg) { ... }

That is a bug.  The C++ "int" and the Java "int" mangle the same way
but are not the same type.  This program will link but will not run
correctly on all platforms.

Maybe the bug is that we are mangling the same way.  I don't know.
Changing the mangling is a pain, I'd bet.

Mark> Except this: mangle `extern "Java"' names differently.  What if
Mark> an extern Java name had `int' mangled as the appropriately sized
Mark> Java type, whether that was `jint', `jshort', or whatever on the
Mark> platform you're on?  (If, for example, `int' is 16-bits, then
Mark> `int' would be mangled as `jshort'.)  Furthermore, you can check
Mark> that all parameters/return types from Java functions are either
Mark> Java classes, or are of a scalar type that has a Java
Mark> "equivalent".

Mark> Then, you provide a header full of typedefs.  You write ordinary
Mark> C++.  It actually makes no difference whether you say `int' or
Mark> `jint' in your code, if they're the same size, but you can use
Mark> `jint' for clarity of coding.  Until the new ABI comes along,
Mark> `jboolean' is just `char', or maybe the weird typedef __mode__
Mark> thing, if that works.

Mark> How about that for a proposal?

I'm afraid I don't understand it.

Java has requirements on type size.  For instance in Java an "int"
must be 32 bits.

When implementing a Java native method in C++ there must be a single
name which can be used independent of platform to represent this
type.  Currently this is "jint".

Are you saying that we would continue to use "jint" but somehow change
its mangling to match the like-sized C++ type (which could be short,
on some weird system, say)?  What about when there are two matching
C++ types (sizeof(int)==sizeof(long))?

Also, this approach still falls to the bug up at the top, right?  If
sizeof(int)==sizeof(jint) I won't see the bug.


At this point I don't understand why we mangle int and jint the same
way.  What does this gain us?  It makes the demangler simpler.  Is
there anything else?

Tom


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