Found a bug with return_stl_iterator

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Found a bug with return_stl_iterator

Jiao Hang
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Found a bug with return_stl_iterator

Daniel Wallin
Jiao Hang wrote:
[...]
> If this is the case, please fix it in the next version.

I forgot to reply to this, but your patch was applied here:

http://github.com/luabind/luabind/commit/17a85a7657d94b256748cef45911c227a2c20afe

and is part of 0.9.

Thanks,
--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user