Quoting Richard Fish <[EMAIL PROTECTED]>:
> Aaron Optimizer Digulla wrote:
> > Isn't it possible to install a "destroy" callback which deletes the
> > python object (so when the Gtk object is deleted, the Python object
> > is notified) ?
>
> Hmm, interesting idea. It seems like it should be possible to create a
> 1:1 mapping using the following rules.
>
> - When a Python object is created, it get's added to an internally
> maintained dictionary that maps the Gtk object to it's Python object.
> This increments the reference count of the Python object.
Why is this neccessary ? Isn't is sufficient to believe that all
python objects will be referenced as long as the Gtk object
exists ? For example, when I add a button to a window, the Python
Button object must be added to the Python Window object (in order
to be able to find it again).
> - When a python object needs to be returned to the user, it is fetched
> from the dictionary, rather than returning a newly created object.
>
> - When a Gtk object is destroyed, the corresponding Python object is
> deleted from the object dictionary, thus decrementing the reference
> count, possibly deleting the python object.
:-/ Why are you sure that the python object *can* be deleted when the
Gtk object is ? Eg. what happens if the Gtk object should be destroyed
but the Python object is still refd somewhere else ? Or the other
way round: What happens when I del the python object but the Gtk object
is still used somewhere in Gtk ?
> > Then it should be possible to make the Python objects the "base" and
> > store the Gtk object in a field in the Python object and use Python
> > ways to do things.
>
> This is presently how things are done. The problem comes when you
> interface to a Gtk function that returns a Gtk object, you have to find
> the corresponding Python object to return to the python code. In
> theory, it sounds simple. In practice, it's very easy to cause memory
> leaks or segfaults. Neither occurs if you dynamically create the python
> object to wrap the returned gtk object.
That's true. But I see no harm in storing the Python object in Gtk's
data field. There must just be a strict order who rules. Either Gtk
tells Python what to do or the other way round. Currently, it's Gtk
and that means that it's not possible to use the full power of Python.
--
Aaron "Optimizer" Digulla Team AMIGA AROS Head of Development
Author of XDME, ResTrackLib, CInt. <http://www.aros.org/>
"(to) optimize: Make a program faster by improving the algorithms rather than
by buying a faster machine." <[EMAIL PROTECTED]>
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]