lqt
lqt copied to clipboard
Malloc error on OS X
I built lqt successfully on macosx 10.6 but lua crashes as soon as I load the qtgui library with the following error:
lua(39856,0x7fff70745ca0) malloc: *** error for object 0x1057590a0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap
I found that if I stop the garbage collector (collectgarbage'stop') first I can run successfully all the training examples, but lua still crashes on exit. I will try to find more info about what might cause this crash. I also found that I am not the only one with this problem: http://lua-list.2524044.n2.nabble.com/lqt-on-OS-X-td4992034.html#a6415247 has it as well.
Best regards
Charles
EDIT: the problem is not only qtgui, as the test 'virt_test.lua' also crashes in the same way, even though it only uses qtcore. Please tell me if there is anything I can do to help solve this issue.
EDIT #2: I just tried the old lqt version from repo.or.cz, and it works! Well, as long as I use the lua interpreter included with it, as soon as I use mine (which is the same 5.1.4 version), it crashes on exit with the same error. I'd really like to understand what is going on...
Hi, unfortunatelly I cannot get hold of a Mac, so I cannot reproduce and test the bug. Could you try compiling lqt using:
cmake -DCMAKE_BUILD_TYPE=Debug /path/to/lqt
make
to generate debug libraries, and then running:
$ gdb --args lua virt_test.lua
gdb) break malloc_error_break
gdb) run
... it will crash here ...
gdb) bt full
and post the full backtrace?
Hello,
I recompiled lqt and lua with the flag -DCMAKE_BUILD_TYPE=Debug and run gdb on the tests virt_test.lua, t1.lua, and t1.lua where I added collectgarbage'stop' at the beginning. Here are the 3 logs, if you need anything else please don't hesitate to ask.
MacBook-Pro:build cdubout$ gdb --args ~/Downloads/lua-5.1.4/debug/lua ../test/virt_test.lua
GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:52:12 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ...
.. done
(gdb) break malloc_error_break
Breakpoint 1 at 0x51eb851ea9d779
(gdb) run
Starting program: /Users/cdubout/Downloads/lua-5.1.4/debug/lua ../test/virt_test.lua
event overload called ChildAdded
lua(4851,0x7fff70745ca0) malloc: *** error for object 0x1003c9f60: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Breakpoint 1, 0x00007fff83740779 in malloc_error_break ()
(gdb) bt full
#0 0x00007fff83740779 in malloc_error_break ()
No symbol table info available.
#1 0x00007fff8366a6a3 in free ()
No symbol table info available.
#2 0x000000010000adee in l_alloc (ud=0x0, ptr=0x1003c9f60, osize=40, nsize=0) at /Users/cdubout/Downloads/lua-5.1.4/src/lauxlib.c:631
No locals.
#3 0x0000000100022ae6 in luaM_realloc_ (L=0x100100080, block=0x1003c9f60, osize=40, nsize=0) at /Users/cdubout/Downloads/lua-5.1.4/src/lmem.c:79
g = (global_State ) 0x100100138
#4 0x0000000100029081 in luaH_free (L=0x100100080, t=0x1001d74c0) at /Users/cdubout/Downloads/lua-5.1.4/src/ltable.c:376
No locals.
#5 0x000000010001fd8f in freeobj (L=0x100100080, o=0x1001d74c0) at /Users/cdubout/Downloads/lua-5.1.4/src/lgc.c:383
No locals.
#6 0x000000010001feeb in sweeplist (L=0x100100080, p=0x1001d75a0, count=30) at /Users/cdubout/Downloads/lua-5.1.4/src/lgc.c:424
curr = (GCObject *) 0x1001d74c0
g = (global_State *) 0x100100138
deadmask = 33
#7 0x000000010002077c in singlestep (L=0x100100080) at /Users/cdubout/Downloads/lua-5.1.4/src/lgc.c:583
old = 1355978
g = (global_State *) 0x100100138
#8 0x0000000100020a38 in luaC_fullgc (L=0x100100080) at /Users/cdubout/Downloads/lua-5.1.4/src/lgc.c:656
g = (global_State *) 0x100100138
#9 0x0000000100017856 in lua_gc (L=0x100100080, what=2, data=0) at /Users/cdubout/Downloads/lua-5.1.4/src/lapi.c:914
res = 0
g = (global_State *) 0x100100138
#10 0x0000000100002750 in docall (L=0x100100080, narg=0, clear=0) at /Users/cdubout/Downloads/lua-5.1.4/src/lua.c:106
status = 2
base = 2
#11 0x0000000100002f51 in handle_script (L=0x100100080, argv=0x7fff5fbff7e0, n=1) at /Users/cdubout/Downloads/lua-5.1.4/src/lua.c:250
status = 0
fname = 0x7fff5fbff92f "../test/virt_test.lua"
narg = 0
#12 0x0000000100003462 in pmain (L=0x100100080) at /Users/cdubout/Downloads/lua-5.1.4/src/lua.c:362
s = (struct Smain *) 0x7fff5fbff790
argv = (char *) 0x7fff5fbff7e0
script = 1
has_i = 0
has_v = 0
has_e = 0
#13 0x000000010001d3f4 in luaD_precall (L=0x100100080, func=0x100100440, nresults=0) at /Users/cdubout/Downloads/lua-5.1.4/src/ldo.c:319
ci = (CallInfo *) 0x100100318
n = 1
cl = (LClosure *) 0x1001008f0
funcr = 16
#14 0x000000010001d68c in luaD_call (L=0x100100080, func=0x100100440, nResults=0) at /Users/cdubout/Downloads/lua-5.1.4/src/ldo.c:376
No locals.
#15 0x000000010001764c in f_Ccall (L=0x100100080, ud=0x7fff5fbff750) at /Users/cdubout/Downloads/lua-5.1.4/src/lapi.c:846
c = (struct CCallS *) 0x7fff5fbff750
cl = (Closure *) 0x1001008f0
#16 0x000000010001c641 in luaD_rawrunprotected (L=0x100100080, f=0x100017571 <f_Ccall>, ud=0x7fff5fbff750) at /Users/cdubout/Downloads/lua-5.1.4/src/ldo.c:116
lj = {
previous = 0x0,
b = {0, 0, 1606416048, 32767, 1606415856, 32767, 0, 0, 0, 0, 0, 0, 0, 0, 116256, 1, 534, 0, 8064, 895, 0, 0, 1606416016, 32767, 1606436739, 32767, 0, 0, 0, 0, 1606416224, 32767, -2089368850, 32767, 1048704, 1, 13028},
status = 0
}
#17 0x000000010001daad in luaD_pcall (L=0x100100080, func=0x100017571 <f_Ccall>, u=0x7fff5fbff750, old_top=16, ef=0) at /Users/cdubout/Downloads/lua-5.1.4/src/ldo.c:463
status = 16711680
oldnCcalls = 0
old_ci = 0
old_allowhooks = 1 '\001'
old_errfunc = 0
#18 0x00000001000176a8 in lua_cpcall (L=0x100100080, func=0x1000032e4
MacBook-Pro:build cdubout$ gdb --args ~/Downloads/lua-5.1.4/debug/lua ../test/t1.lua
GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:52:12 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ...
.. done
(gdb) break malloc_error_break
Breakpoint 1 at 0x51eb851ea9d779
(gdb) run
Starting program: /Users/cdubout/Downloads/lua-5.1.4/debug/lua ../test/t1.lua
lua(4999,0x7fff70745ca0) malloc: *** error for object 0x1003c9f60: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Breakpoint 1, 0x00007fff83740779 in malloc_error_break ()
(gdb) bt full
#0 0x00007fff83740779 in malloc_error_break ()
No symbol table info available.
#1 0x00007fff8366a6a3 in free ()
No symbol table info available.
#2 0x000000010000adee in l_alloc (ud=0x0, ptr=0x1003c9f60, osize=40, nsize=0) at /Users/cdubout/Downloads/lua-5.1.4/src/lauxlib.c:631
No locals.
#3 0x00000001057bb8dc in luaM_realloc_ ()
No symbol table info available.
#4 0x00000001057bfec9 in luaH_free ()
No symbol table info available.
#5 0x00000001057b98bc in sweeplist ()
No symbol table info available.
#6 0x00000001057b9bc2 in singlestep ()
No symbol table info available.
#7 0x00000001057ba188 in luaC_step ()
No symbol table info available.
#8 0x00000001057b2f45 in lua_pushcclosure ()
No symbol table info available.
#9 0x00000001057c4df8 in luaL_openlib ()
No symbol table info available.
#10 0x000000010579d78e in lqtL_createclass (L=0x100100080, name=0x1057f03dc "QImage_", mt=0x105a4e8c0, getters=0x0, setters=0x0, bases=0x105a4ed00) at /Users/cdubout/Downloads/mkottman-lqt-c9e3686/common/lqt_common.cpp:351
len = 7
new_name = 0x10016a0e0 "QImage"
bi = (
MacBook-Pro:build cdubout$ gdb --args ~/Downloads/lua-5.1.4/debug/lua ../test/t1_no_gc.lua GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:52:12 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ... .. done (gdb) break malloc_error_break Breakpoint 1 at 0x51eb851ea9d779 (gdb) run Starting program: /Users/cdubout/Downloads/lua-5.1.4/debug/lua ../test/t1_no_gc.lua Hello World! lua(5019,0x7fff70745ca0) malloc: *** error for object 0x1058590a0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Breakpoint 1, 0x00007fff83740779 in malloc_error_break () (gdb) bt full #0 0x00007fff83740779 in malloc_error_break () No symbol table info available. #1 0x00007fff8366a6a3 in free () No symbol table info available. #2 0x000000010000adee in l_alloc (ud=0x0, ptr=0x1058590a0, osize=40, nsize=0) at /Users/cdubout/Downloads/lua-5.1.4/src/lauxlib.c:631 No locals. #3 0x0000000100022ae6 in luaM_realloc_ (L=0x100100080, block=0x1058590a0, osize=40, nsize=0) at /Users/cdubout/Downloads/lua-5.1.4/src/lmem.c:79 g = (global_State *) 0x100100138 #4 0x0000000100029081 in luaH_free (L=0x100100080, t=0x105058040) at /Users/cdubout/Downloads/lua-5.1.4/src/ltable.c:376 No locals. #5 0x000000010001fd8f in freeobj (L=0x100100080, o=0x105058040) at /Users/cdubout/Downloads/lua-5.1.4/src/lgc.c:383 No locals. #6 0x000000010001feeb in sweeplist (L=0x100100080, p=0x100100160, count=18446744073709551611) at /Users/cdubout/Downloads/lua-5.1.4/src/lgc.c:424 curr = (GCObject *) 0x105058040 g = (global_State *) 0x100100138 deadmask = 64 #7 0x0000000100020241 in luaC_freeall (L=0x100100080) at /Users/cdubout/Downloads/lua-5.1.4/src/lgc.c:487 g = (global_State *) 0x100100138 i = 0 #8 0x0000000100027707 in close_state (L=0x100100080) at /Users/cdubout/Downloads/lua-5.1.4/src/lstate.c:108 g = (global_State *) 0x100100138 #9 0x0000000100027c42 in lua_close (L=0x100100080) at /Users/cdubout/Downloads/lua-5.1.4/src/lstate.c:212 No locals. #10 0x0000000100003563 in main (argc=2, argv=0x7fff5fbff7f0) at /Users/cdubout/Downloads/lua-5.1.4/src/lua.c:389 status = 0 s = { argc = 2, argv = 0x7fff5fbff7f0, status = 0 } L = (lua_State *) 0x100100080
On May 29, 2011, at 11:49 PM, mkottman wrote:
Hi, unfortunatelly I cannot get hold of a Mac, so I cannot reproduce and test the bug. Could you try compiling lqt using:
cmake -DCMAKE_BUILD_TYPE=Debug /path/to/lqt make
to generate debug libraries, and then running:
$ gdb --args lua virt_test.lua gdb) break malloc_error_break gdb) run ... it will crash here ... gdb) bt full
and post the full backtrace?
Reply to this email directly or view it on GitHub: https://github.com/mkottman/lqt/issues/6#comment_1258856
Unfortunately, I do not (yet) see the reason for such behavior. I am trying to get hold of a Mac machine with Xcode to find the bug.
If the version from repo.or.cz, then it could mean that there are two different allocators/libraries being used. The original version of Lqt compiled a version of Lua that was distributed with the source. I changed this, compiling using the system Lua libraries instead.
I am not familiar with Mac OS dynamic libraries enough to be confident, but could you try running ldd
(or it's equivalent) on the generated qtcore library, and on the system Lua library?
Ok here it is for the version from repo.or.cz (dynamically linking to the embedded Lua):
MacBook-Pro:lib cdubout$ otool -L libqtcore.dylib libqtcore.dylib: /Users/cdubout/Desktop/tmp/lqt/build/lib/libqtcore.dylib (compatibility version 0.0.0, current version 0.0.0) /opt/local/lib/libQtOpenGL.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtScript.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtSvg.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtWebKit.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtGui.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtXml.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtXmlPatterns.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtNetwork.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtCore.4.dylib (compatibility version 4.7.0, current version 4.7.2) /Users/cdubout/Desktop/tmp/lqt/build/lib/liblua.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libedit.2.dylib (compatibility version 2.0.0, current version 2.11.0) /opt/local/lib/gcc44/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.13.0) /opt/local/lib/gcc44/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10) MacBook-Pro:lib cdubout$ otool -L liblua.dylib liblua.dylib: /Users/cdubout/Desktop/tmp/lqt/build/lib/liblua.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libedit.2.dylib (compatibility version 2.0.0, current version 2.11.0) /opt/local/lib/gcc44/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
And for your version:
MacBook-Pro:lib cdubout$ otool -L qtcore.dylib qtcore.dylib: /Users/cdubout/Downloads/mkottman-lqt-c9e3686/build/lib/qtcore.dylib (compatibility version 0.0.0, current version 0.0.0) /opt/local/lib/libQtOpenGL.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtScript.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtSvg.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtWebKit.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtGui.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtXml.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtSql.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtXmlPatterns.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtNetwork.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/libQtCore.4.dylib (compatibility version 4.7.0, current version 4.7.2) /opt/local/lib/gcc44/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.13.0) /opt/local/lib/gcc44/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
The difference seem to be that your version links statically to lua. So I then built the repo.or.cz version statically linking to my system Lua (by adding -DSYSTEM_LUA=1) and it now crashes as well. So it seems to only work if Lua is linked to dynamically, any idea why it would be so?
On Jun 1, 2011, at 10:51 PM, mkottman wrote:
Unfortunately, I do not (yet) see the reason for such behavior. I am trying to get hold of a Mac machine with Xcode to find the bug.
If the version from repo.or.cz, then it could mean that there are two different allocators/libraries being used. The original version of Lqt compiled a version of Lua that was distributed with the source. I changed this, compiling using the system Lua libraries instead.
I am not familiar with Mac OS dynamic libraries enough to be confident, but could you try running
ldd
(or it's equivalent) on the generated qtcore library, and on the system Lua library?Reply to this email directly or view it on GitHub: https://github.com/mkottman/lqt/issues/6#comment_1277072
It seems that this issue is not Lqt specific, but an issue with Lua + Mac OS X + dynamic libraries. It happens in other projects on Mac OS X too. This patch in MacPorts seems to fix the problem, could you somehow try it out?
Yes as I already observed dynamically linking to Lua seems to solve the problem. How can I specify to cmake that I want to dynamically link to another Lua?
On Jun 2, 2011, at 9:39 PM, mkottman wrote:
It seems that this issue is not Lqt specific, but an issue with Lua + Mac OS X + dynamic libraries. It happens in other projects on Mac OS X too. This patch in MacPorts seems to fix the problem, could you somehow try it out?
Reply to this email directly or view it on GitHub: https://github.com/mkottman/lqt/issues/6#comment_1284028
Ok, I finally managed to get access to Mac OS X and try it out.
Unfortunatelly, I couldn't make it run with stock Lua using make macosx
. The generated .dylib is 64-bit, however, I have been running into this issue when compiling in Qt.
In order to resolve the issue, I had to force both Lua and Lqt to be 32-bit. First, I cloned this Lua repo which includes CMakeLists for Lua. I ran the following:
git clone git://github.com/LuaDist/lua.git
cd lua
mkdir b && cd b
cmake -DCMAKE_OSX_ARCHITECTURES=i386 ..
cmake --build . --target install
This compiles Lua as a Mach-O executable i386
and installs it in /usr/local/, which the lqt CMakeLists then finds automatically. I also updated it to use .so modules instead of .dylibs, which caused problems. Now, you do not have to change the package.cpath
. Here is the process:
git clone git://github.com/mkottman/lqt.git
cd lqt
mkdir b && cd b
cmake -DCMAKE_OSX_ARCHITECTURES=i386 ..
cmake --build . # or use make -jN
Please respond if this process works for you.
I'm getting this malloc error also. I note the problem above with 64-bit. I did read that you can get around by downloading the "Cocoa", 64-bit version of Qt.
I've done this - and I'd like to try your fix for the malloc - but I'm not really clear what to do. The example code above seems to just build each at 32-bit ?
Yes, it only builds 32-bit libraries, even though I also installed Qt "Cocoa" 64-bit libraries. Unfortunately, I have not (yet) found a way to build 64-bit modules using Qt. Any suggestions are welcome.
it seemed to build ok for me ? I've got a bunch of .so files in build/lib --- and I've copied them to /usr/local/lib/lua/5.1/
still get the malloc error though
Have you compiled BOTH Lua from LuaDist and the latest Lqt using the provided steps?
everything's currently in 64bit land. The library built fine without this issue ( http://vvladd.wordpress.com/2010/09/20/mac-os-x-cmake-qt-architecture-issues/ )
it seemed to me that this issue was different from the malloc error ? or am i mistaken
On Fri, Jul 1, 2011 at 9:39 AM, mkottman < [email protected]>wrote:
Have you compiled BOTH Lua from LuaDist and the latest Lqt using the provided steps?
Reply to this email directly or view it on GitHub: https://github.com/mkottman/lqt/issues/6#issuecomment-1481491
This is the article that led me to compiling Lua and Lqt in 32-bit only mode. I do not have enough Mac OS X experience (almost zero) to completely comprehend the issue. For me, the proposed method worked. If it does not work for you, I do not know what could be the issue. Unfortunately, I'll have to leave this open until someone else shows up and solves this.
If like me you want to use lqt on Snow Leopard but still need Lua in 64-bit mode (e.g. some 64-bit Luarocks extensions, etc...), you may want to install Lua as a x86_64/i386 fat file binary.
This is what you get with a standard build on Snow Leopard:
$ lipo -info /usr/local/lib/liblua.a Non-fat file: /opt/local/lib/liblua.a is architecture: x86_64
Now either install Lua with Macports:
sudo port install lua +universal
$ lipo -info /opt/local/lib/liblua.a Architectures in the fat file: liblua.a are: i386 x86_64
Or change the following lines in your Makefile in the lua-5.1.4 distribution src/ folder:
MYCFLAGS= -arch i386 -arch x86_64 MYLDFLAGS= -arch i386 -arch x86_64
macosx: $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX -arch i386 -arch x86_64" MYLIBS="-arch i386 -arch x86_64 -lreadline"
liblua.dylib: $(CORE_O) $(LIB_O) $(CC) -arch i386 -arch x86_64 -dynamiclib -o $@ $^ $(LIBS)
(end of Makefile)
Then:
make macosx
make install
$ lipo -info /usr/local/lib/liblua.a Architectures in the fat file: liblua.a are: i386 x86_64
$ file /usr/local/lib/liblua.a liblua.a: Mach-O universal binary with 2 architectures liblua.a (for architecture i386): current ar archive random library liblua.a (for architecture x86_64): current ar archive random library
Now after running export LUA_CPATH=$PWD/lqt/build/lib/?.so, use the arch command when invoking Lua: arch -i386 /usr/local/bin/lua ../lqt/test/webview.lua or the other examples. (The '-i386' switch makes a universal binary run in Intel 32-bit mode. '-x86_64' makes it run in Intel 64-bit mode. -ppc and -ppc64 is for PPC architectures.)