[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: luasocket crash on win32
- From: "Adam D. Moss" <adam@...>
- Date: Mon, 29 Nov 2004 16:37:03 +0000
Brett Kapilik wrote:
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
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.
1. Compile your app and Lua DLL with linking to the DLL version of the CRT.
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.
Thanks for the tips.
However, while it does seem that win32 development is even more
disgusting than I ever imagined, I either don't understand your
explanation or I don't think it applies to my situation. :)
The app itself isn't statically linked to the CRT.
When I say 'static' I mean that Lua and LuaSocket are being
compiled into 'ar' libraries instead of DLLs. They're not getting
linked with the static CRT -- they're not getting linked with anything
until the final .exe link whereupon they get linked with the
application and whatever the normal .lib harness for loading
the C runtime is.
I could kinda understand that simultaneously employing a static
and dynamic CRT would cause trouble, but I'm not doing that. If
I have misunderstood then please let me know. :)
Adam D. Moss . ,,^^ firstname.lastname@example.org http://www.foxbox.org/ co:3