lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


OK, as mentioned in another post, I did get that problem solved.  However, now I have another very weird thing going on...

In my DLL (one that is being loaded by my app through Ignacio Castaño's loadmodule) I have code to export my c functions to Lua like so:

const luaL_reg tab_funcs[] = {
		{"SayHi", testlib_sayhi},
		{"SayHi2", testlib_sayhi2},
		{"SayHi3", testlib_sayhi3},
		{"SayHey", testlib_sayhey},
		{"SayBye", testlib_saybye},
		{"GetName", testlib_getname},
		{"ShowSplash", testlib_showsplash},
		{NULL, NULL}
	};


int lua_testlibopen (lua_State *L) {
	
	
	luaL_openlib(L, "Test", tab_funcs, 0);
	return 0;
}

And generally this is OK.  However, here is the wierd part: if I have 1, 3 or 7 functions, my app crashes in the c runtime libraries here (DBGHEAP.C - I am working in Debug mode...):

void __cdecl _free_dbg_lk( ... etc ...

Again, it is stemming from the loadmodule file, here is the call stack:

_free_dbg_lk(void * 0x02ab1670, int 1) line 1011 + 48 bytes
_free_dbg(void * 0x02ab1670, int 1) line 970 + 13 bytes
free(void * 0x02ab1670) line 926 + 11 bytes
luaM_realloc(lua_State * 0x015e1b40, void * 0x02ab1670, unsigned long 320, unsigned long 0) line 69 + 9 bytes
resize(lua_State * 0x015e1b40, Table * 0x02ab1b20, int 0, int 4) line 284 + 29 bytes
rehash(lua_State * 0x015e1b40, Table * 0x02ab1b20) line 291 + 33 bytes
newkey(lua_State * 0x015e1b40, Table * 0x02ab1b20, const lua_TObject * 0x015d92e0) line 384 + 13 bytes
luaH_set(lua_State * 0x015e1b40, Table * 0x02ab1b20, const lua_TObject * 0x015d92e0) line 467 + 17 bytes
lua_rawset(lua_State * 0x015e1b40, int -3) line 576 + 38 bytes
ll_loadlib(lua_State * 0x015e1b40) line 193 + 11 bytes
... and so on...

If I have 2, 4, 5, 6 functions that are exported, there are no crashes.  I have tried many combinations, I know that it has nothing to do with:

- Function names
- Function length/content
- Which functions are registered with Lua

I can mix and match the functions, change their names, do Debug or Release builds of the DLL, but can't find any pattern besides the number of functions.  From tracing the call stack it would seem that the problem occurs when Lua tries to re-allocate more space as it adds functions to a table.  This happens during the call to luaL_openlib.

Any ideas/theories?

- Brett Kapilik
- brett@indigorose.com

> -----Original Message-----
> From: Ignacio Castaño [mailto:castanyo@yahoo.es]
> Sent: Thursday, March 06, 2003 2:09 PM
> To: Multiple recipients of list
> Subject: Re: Lua 5.0 beta/loadmodule question
> 
> 
> Brett Kapilik wrote:
> > Again, let me re-iterate that I never have any problems if 
> I don't call
> "module.load" from loadmodule.c.  If I do call it, the loaded 
> module works
> as expected but then I get the crash at the end.  Any 
> additional insights
> would be fantastic.
> 
> Hi Brett,
> 
> which modules are you using?
> do the modules create any userdatas? do those userdatas have 
> a gc method?
> 
> could you verify that the module is not being unloaded before 
> calling the gc
> method of your objects?
> 
> 
> 
> Ignacio Castaño
> castanyo@yahoo.es
> 
> 
> ___________________________________________________
> Yahoo! Móviles
> Personaliza tu móvil con tu logo y melodía favorito 
> en http://moviles.yahoo.es
> 
>