[Kde-bindings] Smoke call policy question

Dongxu Ma dongxu.ma at gmail.com
Fri Oct 27 08:57:59 UTC 2006


Hi Richard, Ashley and all,

I got a similar scenario in QT4 tutorial:
#######################

    MyWidget::MyWidget(QWidget *parent)
        : QWidget(parent)
    {
        setFixedSize(200, 120);

        QPushButton *quit = new QPushButton("Quit", this);
        quit->setGeometry(62, 40, 75, 30);
        quit->setFont(QFont("Times", 18, QFont::Bold));

        connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
    }

#######################

'quit' is a heap variable but will be implicitly deleted by parent widget.
If one does so in scripting language, for instance in perl, the refcounting
mechanism will destroy 'quit' since it is out of scope once returning from
new.

A possible solution for this case: once called with an explicit parent
widget, I
can increase the refcount of 'quit' to 2. Thus even the stash is out of
scope, the
underlying cpp instance will not be deleted.

This is the case adding stuff into another, while the reverse mentioned in
boost
document is more complex. It is very hard to determine, say 'Bar *Foo(...)
', the
returned object is a part of other or a new heap variable. I got such
situation
during porting TagLib to Perl. I have to:
1). got a part of other / an object reference: allocate a new heap copy.
this
        solution has not only performance disadvantage, but also it cannot
'export'
        such internal struct of an object to edit;
     another possible solution is making the stash behave much more like a
QT
        guard pointer;
2). got a heap object: do as usual;

The prerequisite is I know what kind of stuff will be returned exactly.
It will be nice one can get such information from output of smoke.
Any idea?

Cheers, Dongxu
__END__
http://search.cpan.org/~dongxu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20061027/3f902912/attachment.html>


More information about the Kde-bindings mailing list