Tcl Source Code

View Ticket
Login
Ticket UUID: 2960227
Title: problem with my command
Type: Bug Version: None
Submitter: wiede Created on: 2010-02-27 15:03:38
Subsystem: 35. TclOO Package Assigned To: dkf
Priority: 7 High Severity: Minor
Status: Closed Last Modified: 2014-12-18 13:58:47
Resolution: Wont Fix Closed By: dkf
    Closed on: 2014-12-18 13:58:47
Description:
Using the "my" command of an object when the object's class is created with createWithNamespace option shows that the "my" command uses the wrong namespace when created with the object. Use of createWithNamespace object for the object too fails with complaining that the namespace cannot be created, as it already exists. My quick hack was to add a flag to AllocObject and to the Class structure. the class structure has a flag use_declarer_ns, which is set to1 if the createWithNamespace option is used and the object on creation uses classPtr->thisPtr->selfCls->use_declarer_ns when calling AllocObject. I am not sure, if that's a suitable solution, but at least my example works with it. The example is in the attached file. Be aware that also the FRQ for the -use_declarer_ns option is necessary for that example to work.
User Comments: dkf added on 2014-12-18 13:58:47:

Ah! I understand now.

TclOO will always create the namespace for the instance of the object; it needs to have the right deletion callback configured at the C level for object destruction to work. Without that callback, there's a gigantic memory leak. Because of that basic constraint, that namespace needs to not exist prior to the call to the createWithNamespace method.

I don't plan to allow two instances to have the same instance namespace. That would enormously complicate the cleanup code, which is already pretty tricky...


dkf added on 2010-03-02 21:02:51:
I'm not quite sure where to store the information about what the subject of the "instance-my" command is.

wiede added on 2010-03-01 20:55:38:
Having had a deeper look at the wanted behaviour, I have found out, that what I need is a command similar to the [my] command in every class namespace of the object's classes. I have added a ::oo::define itclthis part for providing that, which does provide what I need and with that the wanted functionality is available. So it is up to you Donal, if that is a bug or not, at least I have a solution for the problem.

wiede added on 2010-02-28 16:12:34:
The problem is, that calling an objects method, which has the use_declarer_ns flag set, this method is executed in the classes namespace. In that namespace there is no [my] command available, as that is in the object's namespace. I don't know how to call another method within that object from the executed method.
It is correct, that on the C-level I could implement a similar command, which is available in the classes namespace.

An example output is in the 2nd attachment.

wiede added on 2010-02-28 16:07:27:

File Added - 364782: t9.log

dkf added on 2010-02-28 13:45:19:
BTW, what is that example script supposed to actually output? :-)

(At a guess you're complaining about the fact that [my] isn't a global command? If so, tough. Lots of other code depends on the fact that every object has its own [my], and that each of them knows which particular object is being talked about. For one thing, it is at the heart of how to do callbacks from traces, binding scripts, etc.)

dkf added on 2010-02-28 13:40:12:
I don't understand the nature of this bug. The [my] command just uses the object's private namespace because all method invocations do that. That's what standard methods are defined to do. (A different method type could do something else; the choice of which namespace to make current is part of the method implementation and not the core method system, as can be seen from the way that forwarded methods are handled.) Because it is vital that we hang some bits and pieces of state off the namespace - it's a fundamental design decision which permeates everything - we *have* to create a namespace during object creation; using an existing namespace isn't going to work.

Right now, I suspect that a custom method type might be all that you're looking for.

wiede added on 2010-02-27 22:03:39:

File Added - 364686: t9.tcl

Attachments: