lua-users home
lua-l archive

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


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
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.

Hello!

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. :)

Thanks,
--Adam
--
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3