Hi leledumbo,<div><br></div><div>I have a few questions:</div><div><br></div><div>1) what's the difference between open array and dynamic array? Is "array of Integer" open or dynamic?</div><div><br></div><div>2) How to report a bug, and I believe this maybe a bug in the fpc compiler?</div><div><br></div><div>Thanks</div><div><br>
在 日, 12月 30, 2012 at 12:30 下午,leledumbo <leledumbo_cool@yahoo.co.id> 写道:<br>
<blockquote type="cite">Sorry, I think I was too fast in reading the unit. After reading slowly, the
<br>APIs actually uses open array, not dynamic array. In this case @lib should
<br>be the same as @lib[0], but here's something interesting: I tried your code
<br>(converted as program):
<br>
<br>uses
<br> lua52;
<br>type
<br> TluaLReg = array of luaL_Reg;
<br>var
<br> LUA: Plua_State;
<br> lib : array of luaL_Reg;
<br> //lib : PluaL_Reg;
<br> i: Integer;
<br>
<br>function l_dat_upd(LUA: Plua_State): LongInt; cdecl;
<br>begin
<br>end;
<br>
<br>function l_dat_clr(LUA: Plua_State): LongInt; cdecl;
<br>begin
<br>end;
<br>
<br>begin
<br>LUA := luaL_newstate();
<br>luaL_openlibs(LUA);
<br>SetLength(lib, 2);
<br>//SetLength(TluaLReg(lib), 2);
<br>lib[0].name := 'update';
<br>lib[0].func := @l_dat_upd;
<br>lib[1].name := 'clear';
<br>lib[1].func := @l_dat_clr;
<br>writeln('actual = $'+HexStr(ptruint(@lib),8));
<br>luaL_newlib(LUA, lib);
<br>lua_setglobal(LUA, 'data');
<br>lua_close(LUA);
<br>end.
<br>
<br>inserting some writelns in lua52 unit near problematic functions and running
<br>in gdb results in:
<br>
<br>luaL_newlib oa = $BFFFEE30
<br>luaL_setfuncs oa = $BFFFECC0
<br>
<br>Program received signal SIGSEGV, Segmentation fault.
<br>0xb7e386d2 in ?? () from /lib/i386-linux-gnu/libc.so.6
<br>(gdb) bt
<br>#0 0xb7e386d2 in ?? () from /lib/i386-linux-gnu/libc.so.6
<br>#1 0xb7fa2d12 in ?? () from /usr/lib/i386-linux-gnu/liblua5.2.so.0
<br>#2 0xb7f95f09 in lua_setfield () from
<br>/usr/lib/i386-linux-gnu/liblua5.2.so.0
<br>#3 0xb7fa9a9a in luaL_setfuncs () from
<br>/usr/lib/i386-linux-gnu/liblua5.2.so.0
<br>#4 0x08066821 in LUAL_SETFUNCS (L=0x8071008, LR=..., highLR=1, NUP=0) at
<br>lua52.pas:835
<br>#5 0x080669e4 in LUAL_NEWLIB (L=0x8071008, LR=..., highLR=1) at
<br>lua52.pas:859
<br>#6 0x0804a3ea in main () at test.pas:31
<br>
<br>As you can see, the pointer changes when you pass an open array into another
<br>function expecting open array, even when static array is used (I've tried
<br>that one too). So, somebody with enough compiler knowledge should analyze
<br>this. Maybe you should create a bug report.
<br>
<br>
<br>
<br>--
<br>View this message in context: <a href="http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-SEGFAULT-difference-between-pointer-and-dynarray-tp4028296p4028316.html">http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-SEGFAULT-difference-between-pointer-and-dynarray-tp4028296p4028316.html</a>
<br>Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.
<br>
<br>--
<br>_______________________________________________
<br>Lazarus mailing list
<br>Lazarus@lists.lazarus.freepascal.org
<br><a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a>
<br></blockquote><br></div>