Assertion failure in object_rep::add_dependency()

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Assertion failure in object_rep::add_dependency()

Szymon Gatner
Hey,

I reported this issue some time ago already but at the time I didn't have time to investigate and prepare minimal example of assertion failure I was experiencing. Thing is, I also didn't notice any unexpected behavior after commenting assertion out. This time I am prepared tho:

extern "C"
{
  #include <lualib.h>
};
#include <luabind/luabind.hpp>

using namespace luabind;

namespace
{
  class Widget
  {
  public:

    Widget(const char* msg = "no msg", Widget* parent = 0) : msg_(msg), parent_(parent)
    {

    }

    virtual void foo()
    {
      std::cout << "Widget::foo()";
    }

    std::string msg_;
    Widget* parent_;
  };

  class WidgetWrap : public Widget, public luabind::wrap_base
  {
  public:

    WidgetWrap(const char* msg, Widget* parent) : Widget(msg, parent) {}

    void foo() override
    {
      call<void>("foo");
    }

    static void defaultFoo(Widget* base)
    {
      base->Widget::foo();
    }
  };
}

void main()
{
  const char* code =  
    "class 'MyWidget' (Widget) \n"
    "function MyWidget:__init(msg, parent) \n"
    "  Widget.__init(self, msg, parent) \n"
    "  if parent ~= nil then \n"
    "    self.parent.num = 0 \n"
    "  end \n"
    "end \n"
    "function MyWidget:foo() \n"
    "  self.parent.num = self.parent.num + 1 \n"
    "end \n"
    "parent = MyWidget(\"parent\") \n"
    "child = MyWidget(\"child\", parent) \n";

  lua_State* L = luaL_newstate();
  luaL_openlibs(L);
  open(L);

  module(L)
  [
    class_<Widget, WidgetWrap>("Widget")
    .def(constructor<const char*, Widget*>())
    .def_readonly("parent", &Widget::parent_)
    .def("Foo", &Widget::foo, &WidgetWrap::defaultFoo)
  ];

  luaL_dostring(L, code);

  object G = globals(L);

  Widget* child = object_cast<Widget*>(G["child"]);

  for (int i = 0; i < 48; ++i)
  {
    child->foo();
  }
}

This code triggers assertion failure in:

void object_rep::add_dependency(lua_State* L, int index);

calling foo() on a widget from the script causes the child to access its parent. This seems to keep adding parent dependency every time the parent is accessed.

I am using  Ryan Pavlik's fork.

Regards,
Szymon Gatner


------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user