Skip to content

Some stuff for Windows#12

Open
ggcrunchy wants to merge 4 commits into
askyrme:masterfrom
ggcrunchy:master
Open

Some stuff for Windows#12
ggcrunchy wants to merge 4 commits into
askyrme:masterfrom
ggcrunchy:master

Conversation

@ggcrunchy

Copy link
Copy Markdown

Hi!

I've started making plugins for the Corona SDK and decided it might be fun to have a go at doing luaproc. I'm on Windows, so I've approached it from that angle.

I ran into a couple issues. As far as I can tell, this must be the pthreads library in use: pthreads-win32. Unfortunately, the pthread_t type seems to be a struct, throwing off the lua_pushlightuserdata() calls.

_MSC_VER is probably not the appropriate define; it's tied more to that library, but I didn't find any key constants in my admittedly brief search. The Lockless library, on the other hand, seems light userdata-friendly.

That's in lpsched.c; in luaproc.c, Visual Studio doesn't seem to like the static luaproc mainlp; line unless I move the struct beforehand, so I moved the two non-proc structs up with that in mind. Maybe there's a way to allow this, but I don't know it.

After doing the above, plus a couple Corona-specific export details, the test script ran fine.

Anyhow, I just wanted to bring these details to your attention; do with them as you wish.

Trying this again, now just editing lines by hand, so the whole thing doesn't get reformatted.
Moved around structs to appease MSVC.
@blasti

blasti commented Aug 10, 2016

Copy link
Copy Markdown

Hi!
I tried to compile your version of luaproc with mingw32 via

gcc -c -D_MSC_VER -I%include% *.c
gcc -shared -o luaproc.dll *.o -lpthread -L%lib% -llua

It created a luaproc.dll, and i could run the test file.
However, as soon as i put os.exit() at the end of the file, i get

The application requested the runtime to terminate it in an unusual way .

Any ideas?

@ggcrunchy

Copy link
Copy Markdown
Author

Well, since it is running actual threads, maybe it's complaining because they're not done? Do you have any better luck doing a luaproc.wait() before your exit call?

@blasti

blasti commented Aug 10, 2016

Copy link
Copy Markdown

Does not help. It even crashes when i just execute

local luaproc = require "luaproc"
os.exit()

@ggcrunchy

ggcrunchy commented Aug 10, 2016

Copy link
Copy Markdown
Author

Hmm, weird.

What are you using to run the Lua files?

The DLL registers a __gc that will do an implicit wait on lua_close(), but if that's done through a C++ destructor or __attribute__((destructor)) or something like it, maybe it would blow up. Kind of a wild guess, though. 😄

Does any of this suggest anything: Similar problem?

@ignacio

ignacio commented Aug 10, 2016

Copy link
Copy Markdown

I had similar problems in the past:
DhavalKapil/elasticsearch-lua#7

The culprit was lunitx: https://github.com/dcurrie/lunit/blob/master/lua/lunitx/atexit.lua
When running with Lua 5.1 or LuaJIT, the DLL got unloaded before the code in the __gc was executed, resulting in a crash. Maybe this is a similar issue?

@blasti

blasti commented Aug 10, 2016

Copy link
Copy Markdown

@ggcrunchy i compiled Lua with mingw/msys using the provided makefile.
after than i compiled luaproc, and executed above examples with lua.exe.
so there is no c++ involved here, and also the intepreter and luaproc lib are linked against the same
lua51.dll

@blasti

blasti commented Aug 10, 2016

Copy link
Copy Markdown

it also crashes when i use the lua interpreter interactively

@blasti

blasti commented Aug 11, 2016

Copy link
Copy Markdown

Ok, here is some fix:

The bug seems to be related to the "libgcc_s_dw2-1.dll crashes on exit" bug, which is floating around some while.
It seems that the DWARF version of mingw (and also mingw32 as whole) is broken. I installed the recent SEH version of the mingw fork mingw-w64. In addition I used the version with posix threads.

Recompiled Lua and luaproc, now it works like this: If I put
os.exit()
at the end of the test file, nothing is shown, and the program just exits, no crash. In the previous case hello world from luaproc
was shown, but after that, it crashed.
When I put os.execute "sleep 1"; os.exit()
at the end, the message is shown and the program quits normally.
In the previous case, adding os.execute "sleep 1" does not help, it will still crash.
When I omit os.execute "sleep 1"; os.exit(), above message is shown, and the program exits also without crash (this is the same in the previous case).

So in the end I have the following results:

Compiled with dwarf mingw32:

  • test file shoes message, does not crash
  • test file with exit shows message, crashes
  • testfile with sleep and exit shows message, crashes

Compiled with seh posix threads mingw-w64:

  • test file shows message, does not crash
  • test file with exit does not show message, does not crash
  • testfile with sleep and exit shows message, does not crash

At least it does not crash, but I dont understand why in the second case the message is not shown.

@ggcrunchy

Copy link
Copy Markdown
Author

@blasti Good to hear you've solved it. The newer issue (not specific to luaproc) might simply be a matter of buffering; if so, you could try something like io.output():setvbuf("no") at the beginning of your program.

@blasti

blasti commented Aug 11, 2016

Copy link
Copy Markdown

@ggcrunchy using io.output():setvbuf("no") seems not to help. but anyway, it is a minor issue, it does not happen if you use luaproc.wait() before os.exit()

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants