This is the mail archive of the java-patches@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: Patch: super.clone() and CloneNotSupportedException


Hi Per,

>> I thought about this, but I don't know enough about gcj internals to
>> understand whether this works or not. For someone like me who doesn't
>> know too much about gcj, x looks like an object reference, so the above
>> code would be incorrect because you'd be creating a shallow copy of x
>> instead of a deep copy.
>
>Yes and no.  This only copies the reference "shallowly", but sometimes 
>that is the correct thing in a clone.

Again, my wording was poor. I understand that what you want varies
from case to case, bue I was only interested in the case whose
solution wasn't immediately apparent to me: that of having the copied
A.x not have a RawData reference which refers to the same RawData instance
which the x of the original instance refers to. So that you could subsequently
change the RawData of the copied A.x without affecting the original instance's
RawData instance. (To clarify: I am <i>not</i> talking about what the RawData
actually points to.)

But again, since modifying the contents of the RawData instance involves
native code, I haven't researched RawData enough to understand what it is or
discuss it intelligently.

For example, I don't see how the following code could possibly be correct
(gnu/gcj/xlib/natWMSizeHints.cc):

----------------------------------8<-----------------------------------
void gnu::gcj::xlib::WMSizeHints::init(WMSizeHints* copyFrom)
{
  XSizeHints* hints = XAllocSizeHints();
  if (hints == 0)
    {
      jstring errorMessage = JvNewStringLatin1("XAllocSizeHints failed");
      throw new java::lang::OutOfMemoryError(errorMessage);
    }

  if (copyFrom != 0)
    {
      XSizeHints* from = (XSizeHints*) copyFrom->structure;
      (*hints) = (*from);
    } 
  else
    {
      // Is this necessary?
      hints->flags = 0;
    }
  structure = reinterpret_cast<gnu::gcj::RawData*>(hints);
}

void gnu::gcj::xlib::WMSizeHints::finalize()
{
  delete structure;
}
----------------------------------8<-----------------------------------

In the finalize() method above, I don't see how "delete structure"
could be correct without first casting it to an (XSizeHints*).

I'll read up on RawData more. When I launched into this discussion,
I wasn't expecting to have to discuss it intelligently.

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/





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