lua-users home
lua-l archive

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


> -----Original Message-----
> From: Adam D. Moss [mailto:adam@gimp.org]
> Sent: Saturday, November 27, 2004 5:09 PM
> To: Lua list
> Subject: Re: luasocket crash on win32
> I'm statically linking, but if you mean that you have an .exe
> which should demonstrate the problem, then I can try it on my
> win98 box and see if the problem is something specific to my
> code (or, as you say, something which is fixed by your post-beta2
> LuaSocket version).

I'll bet that static linking is your problem.  We has this exact problem on Windows with Lua communicating with an extension DLL.  The problem is that you are probably statically compiling your app (and Lua) to the static c runtime library.  But the DLL probably uses the dynamic library.  The issue is that when you statically link to the C runtime library you can't allocate a string in the exe and then free it in the DLL or vise-versa.

Solutions:

1.  Compile your app and Lua DLL with linking to the DLL version of the CRT.

or

2.  Rewrite the memory allocation functions in the static Lua library to use HeapAlloc, HeapReAlloc and HeapFree in lmem.c.  Then link this version of the Lua library in with both your application and the luasocket library.  Both libraries muct be using this static version of the library for it to work.  We implemented this method and it has worked great with Lua 5.0 for over a year now in production apps.

Hope that helps.  This is an evil problem to root out and hopefully this will save you some time.

- Brett Kapilik