【问题标题】:Strange import error in Emscripten cross-compiled CPythonEmscripten 交叉编译的 CPython 中出现奇怪的导入错误
【发布时间】:2016-01-23 08:05:09
【问题描述】:

我正在将 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

错误是从Objects/abstract.c 中的PySequence_GetItem 生成的,但我不明白执行是如何到达那里的。如果我在导致错误的行之前执行import posix,则import posix 语句成功完成,我可以调用posix 模块中的函数。因此,该错误与from &lt;module&gt; import * 行有关。 PySequence_GetItemfrom &lt;module&gt; import * 语句有什么关系,错误的原因是什么?

如果你想重现问题,我released the code on GitHub

【问题讨论】:

    标签: python cpython emscripten


    【解决方案1】:

    在调查出了什么问题时,我关闭了优化(编译并与-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

    【讨论】:

      猜你喜欢
      • 2013-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 2021-07-21
      • 2013-04-26
      • 1970-01-01
      相关资源
      最近更新 更多