Found a bug with return_stl_iterator

Jiao Hang <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
When a function returning a container is registered with policy
return_stl_iterator, the return value is converted to an iterator function.
The iterator function has an upvalue, which is an userdata which stores the
infomation of begin() and end().
The iterator is defined in iterator_policy.hpp.

But when the userdata is garbage collected, the userdata is passed to the
destroy function as a parameter, not an upvalue. Here's the original code:
    static int destroy(lua_State* L)
    {
        iterator* self = static_cast<iterator*>(
            lua_touserdata(L, lua_upvalueindex(1)));
        self->~iterator();
        return 0;
    }
this code will crash when the C++ iterator actually needs to deconstruct,
which is the case with std::list in VC 2008.
I think it should be:
    static int destroy(lua_State* L)
    {
        iterator* self = static_cast<iterator*>(
            lua_touserdata(L, -1));
        self->~iterator();
        return 0;
    }
This will fix the crash. But without going deeper in luabind, I'm not sure
if there exist some side-effects.
I'm using luabind 0.8.1. I didn't try with 0.9 RC1, but the code didn't
change.
If this is the case, please fix it in the next version.
Thanks!

Yours
Jesse Hardy

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.