我正在将CPython移植到Emscripten,并且它已成功构建。但是,当我尝试通过Node.js运行python.asm.js时,Py_InitializeEx(0)
调用中出现了一个非常奇怪的错误:
Traceback (most recent call last):
File "/lib/python2.7/site.py", line 62, in <module>
import os
File "/lib/python2.7/os.py", line 44, in <module>
from posix import *
TypeError: 'NotImplementedType' object does not support indexing
错误是从PySequence_GetItem
中的Objects/abstract.c
生成的,但我不明白执行是如何实现的。如果我在导致错误的行之前import posix
,import posix
语句成功完成,我可以在posix模块中调用函数。因此,错误与from <module> import *
行有关。 PySequence_GetItem
如何与from <module> import *
语句相关,以及错误原因可能是什么?
如果您想重现此问题,我released the code on GitHub
答案 0 :(得分:0)
在调查出现问题的同时,我关闭了优化(编译并与-O0
链接)。生成的JS可执行文件也失败了,但出现了不同的错误:
Invalid function pointer '495' called with signature 'iii'. Perhaps this is
an invalid value (e.g. caused by calling a virtual method on a NULL pointer)?
Or calling a function with an incorrect type, which will fail? (it is worth
building your source files with -Werror (warnings are errors), as warnings can
indicate undefined behavior which can cause this)
This pointer might make sense in another type signature:
ii: _dict_keys iiii: 0 i: undefined iiiii: 0 viii: 0 vii: 0 vi: 0 v: 0
495
495
我查看了Emscripten的settings.js以了解与函数指针相关的选项,并找到了解决问题的EMULATE_FUNCTION_POINTER_CASTS
。