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]

Re: C++ and Java CNI: Check Java references


>>>>> "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


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