[Lazarus] SEGFAULT: difference between pointer and dynarray?

xrfang xrfang at gmail.com
Fri Dec 28 16:50:38 CET 2012


Hi All,

I encountered a strange problem with lua integration.  Following is the problematic part (full source attached):

type
  TluaLReg = array of luaL_Reg;
var
  LUA: Plua_State;
  lib : array of luaL_Reg;
  //lib : PluaL_Reg;
  i: Integer;
implementation
//omitted, see attached source...
initialization
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;
luaL_newlib(LUA, lib);      <--Access Violation Here
lua_setglobal(LUA, 'data');
finalization
lua_close(LUA);
end.
                              
The above code caused access violation, unless I use the commented blue code to replace the red code.  I wonder what's the difference between PluaL_Reg and array of luaL_Reg??  What's more strange is that the same code is OK after I copied it to a separate console mode application.  In the attached archive, there are both the problematic project and the OK project.

In LUA manual about luaL_newlib(), it said, the 2nd parameter (lib) must be an array not pointer to an array.   I am confused what happened here and further more, what's the underlying structure of a normal array in FP (If I am correct, dynamic array is same as pointer, at least that's what I learned in Delphi).

My environment is 64 bit Linux 3.5.0 (Mint 14).

Thanks a lot.

Sincerely,
Shannon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20121228/079be122/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: luaintf.tar.gz
Type: application/x-compressed-tar
Size: 30720 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20121228/079be122/attachment-0002.bin>


More information about the Lazarus mailing list