[英]How to fix this stack overflow in this tkinter/exec()/cffi combination?
我有一個通過exec()
執行的Python驅動的DSL。 該DSL包括通過CFFI進行的本機功能調用。
調用僅2個C深度的本機函數時,我正在堆棧溢出(所以,您使它變得不安全了!)崩潰,每個C函數的堆棧上只分配了少量uint16_t
。 Python應用程序是一個tkinter
GUI調用由計時器(在DSL master.after(1000, self.tick)
事件,這可能需要堆疊本身的良好的部分。
這里沒有遞歸調用。
OS X 10.12.3,Python 3.6.0rc1(v3.6.0rc1:29a273eee9a5,2016年12月6日,16:24:13),CFFI 1.9.1
我知道resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
,但是它需要超級用戶特權。 我相信這是沒有必要的,因為只為兩個函數調用保留一個堆棧是不正常的。
CFFI或exec()是否可以限制被調用方的堆棧大小?
從DSL調用的功能:
ffi_builder.cdef('''
//...
int FooNode_SetProperty(struct FooNode *pThis, const char *szPropertyName, int nValue);
''')
def set_channel(node, channel):
node.SetProperty(b'channel', channel)
exec
調用代碼:
self._globals = {
'__builtins__': __builtins__,
# https://docs.python.org/3/library/functions.html#eval "If the globals dictionary is present and lacks
# ‘__builtins__’, the current globals are copied into globals before expression is parsed."
'run': {
'duration': 60 * MICROS,
'success': None
},
'set_channel': set_channel,
'turn_off': turn_off,
'turn_on': turn_on,
'finish': finish,
# 6 more functions here
}
exec(event_text, self._globals, {})
蘋果報告:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
[35633] stack overflow
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00000001003bfdd6 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fffe03dc787 pthread_kill + 90
2 libsystem_c.dylib 0x00007fffe02564bb __abort + 140
3 libsystem_c.dylib 0x00007fffe0256d7e __stack_chk_fail + 205
4 libmush_real.dylib 0x0000000104c4d714 send_counters_report_request + 532
(該線程實際上到此結束,Apple報告中沒有其他內容)
設法與調試器連接。
當前調用之后沒有內容的堆棧通常是通過指向堆棧變量的指針來覆蓋堆棧的信號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.