Jiang Wu said:
> TclBlend does not follow the normal Tcl_Obj reference counting usage.
In Tc
> lBlend, a Java TclObject is used as the handle to the underlining
Tcl_Obj:
>
> TclObject
> CObject
> Tcl_Obj
>
> Both Tcl_Obj and TclObject have reference counting. However, when
increment
> ing or decrementing the reference count on the TclObject, this
incrementing
> or decrementing is proxied into the native Tcl_Obj. This doesn't seem
corre
> ct.
The reason this is done has to do with the semantics of object sharing in
the C library. The C code allows direct mutation of the object in cases
where the refcount == 1 to avoid an extraneous copy. If the java code
didn't reflect the true refcount, then objects that are shared only on the
Java side might see incorrect mutation as a result.
> In addition, when a new TclObject is created to wrap around a Tcl_Obj,
the r
> eference count of the TclObject is 0, but implicitly, the reference
count of
> Tcl_Obj is incremented by 1. This doesn't seem right either.
I think you are correct here. The existence of a TclObject should only
constitute a reference if its reference count is positive.
> I think we should fix the TclBlend reference counting behavior:
>
> 1. do not implicitly increment native Tcl_Obj reference count when
creating
> a new TclObject that wraps around a Tcl_Obj
> 2. when incrementing or decrementing reference count on TclObject, also
prox
> y the action into the native Tcl_Obj
> 3. when TclBlend code wants to keep a Tcl_Obj for the long term, the
code mu
> st increment the reference count
> 4. the GC thread should do nothing regarding to the native Tcl_Obj
> 5. put an assert into the TclObject.finalize() to catch cases when the
refer
> ence count is not decremented to 0
> 6. do not pass Tcl_Obj to other threads, this is not supported by Tcl
anyway
>
> With this fix, I dont' think there is a need to make the GC free
Tcl_Obj.
I think the algorithm you have described should work. It is important to
pass the increment/decrement calls through to the C code, but avoiding the
implicit increment sounds like the right way to handle the issue.
--Scott
----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe: send mail to [EMAIL PROTECTED]
with the word SUBSCRIBE as the subject.
To unsubscribe: send mail to [EMAIL PROTECTED]
with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'.
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com