MAC OSX 上, client.crypt 库会导致 LUA 的标准输入IO卡住。
Gowa2017 opened this issue · 1 comments
Gowa2017 commented
复现代码:
package.cpath = "luaclib/?.so"
local socket = require "client.socket"
local crypt = require "client.crypt"
local input = io.read()
print(input)
if _VERSION ~= "Lua 5.4" then
error "Use lua 5.4"
end
链接和执行脚本时,使用的 LUA 都是 3rd/lua
下面编译的LUA版本。
OSX 版本:13.3.1
编译指令:
make luaclib/client.so
cc -g -O2 -Wall -I3rd/lua -fPIC --shared lualib-src/lua-clientsocket.c lualib-src/lua-crypt.c lualib-src/lsha1.c -o luaclib/client.so -lpthread
编译器:
cc -v
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
请问是我环境问题或是 CRYPT有一些操作会屏蔽输入?
补充,使用LLDB来看,似乎是开了两个线程,LUa-clientsocket 也在读标准输入:
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x00007ff80e3f0882 libsystem_kernel.dylib`__psynch_mutexwait + 10
* frame #1: 0x00007ff80e42ab14 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_wait + 76
frame #2: 0x00007ff80e428921 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_slow + 214
frame #3: 0x00007ff80e2e5820 libsystem_c.dylib`flockfile + 31
frame #4: 0x00007ff80e3303ce libsystem_c.dylib`clearerr + 14
frame #5: 0x000000010002b4db lua`g_read(L=0x0000000100808e08, f=0x00007ff851b07680, first=1) at liolib.c:569:3 [opt]
frame #6: 0x000000010000d657 lua`precallC(L=0x0000000100808e08, func=0x0000000100104320, nresults=1, f=<unavailable>) at ldo.c:529:7 [opt]
frame #7: 0x000000010000d875 lua`luaD_precall(L=0x0000000100808e08, func=0x0000000100104320, nresults=1) at ldo.c:0 [opt]
frame #8: 0x0000000100022bf9 lua`luaV_execute(L=0x0000000100808e08, ci=0x0000600001700200) at lvm.c:1686:22 [opt]
frame #9: 0x000000010000da14 lua`luaD_callnoyield [inlined] ccall(L=0x0000000100808e08, func=0x00000001001042e0, nResults=-1, inc=65537) at ldo.c:637:5 [opt]
frame #10: 0x000000010000d9d2 lua`luaD_callnoyield(L=0x0000000100808e08, func=<unavailable>, nResults=-1) at ldo.c:655:3 [opt]
frame #11: 0x00000001000053ce lua`f_call(L=<unavailable>, ud=<unavailable>) at lapi.c:1040:3 [opt] [artificial]
frame #12: 0x000000010000c998 lua`luaD_rawrunprotected(L=0x0000000100808e08, f=(lua`f_call at lapi.c:1038), ud=0x00007ff7bfefe608) at ldo.c:144:3 [opt]
frame #13: 0x000000010000df90 lua`luaD_pcall(L=<unavailable>, func=<unavailable>, u=<unavailable>, old_top=80, ef=<unavailable>) at ldo.c:953:12 [opt]
frame #14: 0x0000000100005393 lua`lua_pcallk(L=0x0000000100808e08, nargs=0, nresults=-1, errfunc=3, ctx=<unavailable>, k=<unavailable>) at lapi.c:1066:14 [opt]
frame #15: 0x0000000100002595 lua`docall(L=0x0000000100808e08, narg=0, nres=-1) at lua.c:160:12 [opt]
frame #16: 0x0000000100001dfa lua`pmain at lua.c:256:14 [opt]
frame #17: 0x0000000100001d02 lua`pmain(L=0x0000000100808e08) at lua.c:645:9 [opt]
frame #18: 0x000000010000d657 lua`precallC(L=0x0000000100808e08, func=0x00000001001042a0, nresults=1, f=<unavailable>) at ldo.c:529:7 [opt]
frame #19: 0x000000010000d875 lua`luaD_precall(L=0x0000000100808e08, func=0x00000001001042a0, nresults=1) at ldo.c:0 [opt]
frame #20: 0x000000010000d9fe lua`luaD_callnoyield [inlined] ccall(L=0x0000000100808e08, func=0x00000001001042a0, nResults=1, inc=65537) at ldo.c:635:13 [opt]
frame #21: 0x000000010000d9d2 lua`luaD_callnoyield(L=0x0000000100808e08, func=<unavailable>, nResults=1) at ldo.c:655:3 [opt]
frame #22: 0x00000001000053ce lua`f_call(L=<unavailable>, ud=<unavailable>) at lapi.c:1040:3 [opt] [artificial]
frame #23: 0x000000010000c998 lua`luaD_rawrunprotected(L=0x0000000100808e08, f=(lua`f_call at lapi.c:1038), ud=0x00007ff7bfefe8b8) at ldo.c:144:3 [opt]
frame #24: 0x000000010000df90 lua`luaD_pcall(L=<unavailable>, func=<unavailable>, u=<unavailable>, old_top=16, ef=<unavailable>) at ldo.c:953:12 [opt]
frame #25: 0x0000000100005393 lua`lua_pcallk(L=0x0000000100808e08, nargs=2, nresults=1, errfunc=0, ctx=<unavailable>, k=<unavailable>) at lapi.c:1066:14 [opt]
frame #26: 0x000000010000176e lua`main(argc=2, argv=0x00007ff7bfefebc0) at lua.c:673:12 [opt]
frame #27: 0x00007ff80e0d341f dyld`start + 1903
thread #2
frame #0: 0x00007ff80e3efe62 libsystem_kernel.dylib`__read_nocancel + 10
frame #1: 0x00007ff80e2e1d19 libsystem_c.dylib`_sread + 16
frame #2: 0x00007ff80e2e1cc8 libsystem_c.dylib`__srefill1 + 24
frame #3: 0x00007ff80e2f564b libsystem_c.dylib`fgets + 98
frame #4: 0x00000001000dc061 client.so`readline_stdin(arg=0x0000000101008238) at lua-clientsocket.c:145:7 [opt]
frame #5: 0x00007ff80e42d1d3 libsystem_pthread.dylib`_pthread_start + 125
frame #6: 0x00007ff80e428bd3 libsystem_pthread.dylib`thread_start + 15
Gowa2017 commented
使用 socket 来读取输入就行了。解决。