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