segfault using SWIG converted code for tcl

徘徊边缘 提交于 2020-01-03 03:13:10

问题


I'm having a segmentation fault with my program.

In fact I write a library in C++ and convert it for tcl using SWIG.

The segfault occurs here:

return Tcl_NewIntObj(static_cast< int >(value));

where value=0

the gdb back trace shows:

(gdb) bt
#0  0x000054b6 in ?? ()
#1  0xb6650d5d in SWIG_From_long (value=0) at mntdisplay_wrap.cc:1712
#2  SWIG_From_int (value=0) at mntdisplay_wrap.cc:1722
#3  Testguimnt_Init (interp=0x9714e28) at mntdisplay_wrap.cc:3774
#4  0xb76748fe in Tcl_LoadObjCmd () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#5  0xb75d02af in TclNREvalObjv () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#6  0xb75d0859 in Tcl_EvalObjv () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#7  0xb75d0d99 in TclEvalEx () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#8  0xb7670045 in Tcl_FSEvalFileEx () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#9  0xb767645f in Tcl_MainEx () from /opt/ActiveTcl-8.6/lib/libtcl8.6.so
#10 0x0804885c in main ()

In the wrapper: line 1712:

SWIGINTERNINLINE Tcl_Obj* 
SWIG_From_long  (long value)
{
  if (((long) INT_MIN <= value) && (value <= (long) INT_MAX)) {
    return Tcl_NewIntObj(static_cast< int >(value));  //1712
  } else {
    return Tcl_NewLongObj(value);
  }
}

1722:

SWIGINTERNINLINE Tcl_Obj *
SWIG_From_int  (int value)
{    
  return SWIG_From_long  (value); //1722
}

3774:

SWIG_Tcl_SetConstantObj(interp, "MESSAGE_NEW", SWIG_From_int(static_cast< int >(MESSAGE_NEW)));

where MESSAGE_NEW is defined in a enum and is 0.

Please, if you have any idea, please help me. Thank you!

EDIT:

I found the cause of the problem: it's an linking error.

I created a new thread for this issue:

C++: linked library disappears and gives segfault during execution


回答1:


I found the problem.

Please see my other post: C++: linked library disappears and gives segfault during execution

There was an undefined symbol of my library. I defined it and problem solved!

The confusion was, my program crashed in the middle of tcl wrapper functions (where my undefined symbol was not involved at all). I don't really know why but that's it..

Hope it will help others!



来源:https://stackoverflow.com/questions/18375668/segfault-using-swig-converted-code-for-tcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!