This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: C++ and Java CNI: Check Java references
- To: per at bothner dot com
- Subject: Re: C++ and Java CNI: Check Java references
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Tue, 24 Apr 2001 11:16:01 -0700
- Cc: aph at cambridge dot redhat dot com, java at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <m28zkrza8h.fsf@kelso.bothner.com>
>>>>> "Per" == Per Bothner <per@bothner.com> writes:
Per> from the source. However, explicit null-pointer checking
Per> seems to stretch the boundary of appropriate magic re-writes.
FWIW, I agree with Per. I would prefer not to see this patch
installed.
Instead, I would suggest that CNI programmers use C++ features, i.e.,
smart pointers, to do the job.
For example:
template <typename T>
class JavaPointer {
T& operator* () {
if (!p) throw NullException;
return *p;
}
private:
T* p;
};
(Obviously, this needs fleshing out.)
It's possible to write conversion operators (see auto_ptr) so that
pretty much all of the C++ pointer semantics come through this way.
Then, the maintenance requirement boils down to simply remembering to
use JavaPointer everywhere. That's a lot easier than remembering to
add all the checks by hand.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com