【问题标题】:PyFile_Type replaced by ..?PyFile_Type 替换为 ..?
【发布时间】:2026-01-03 10:25:01
【问题描述】:

我很想为 Python 3.2 编译 Yenc。我注意到 gcc 抱怨了一个未声明的函数 PyString_Type,所以我根据 the documentation 将其替换为 PyBytes_Type

然而,gcc 也抱怨了一个名为PyFile_Type 的未声明函数。我google了一下,发现:

Python 3.x replaces the PyFile_Type extension type 
with an abstract interface and specific implementation types. 
Unfortunately it doesn't make any of this directly available 
with a C level api.

source

我绝不是 C 程序员,这让我无法解决这个问题。我该怎么做才能解决这个问题?

编辑:output of compilation_yenc.c

谢谢!

【问题讨论】:

    标签: c cpython python-3.2


    【解决方案1】:

    简单地说,PyFile_Type 已被 Python 3 中甚至完全不相似的东西所取代,您必须自己修改代码或等待维护者这样做。如果您不是 C 程序员,则可能必须是后者。 The documentation 指出,Python 3 现在不是包装 FILE*,而是包装低级 I/O,在这种情况下是文件描述符和 read()/write()。

    【讨论】:

    • 我不认为它 (python-yenc) 还活着,所以我将在 this 之后自己摆弄 C。感谢您的回答!
    【解决方案2】:

    您可以尝试使用 PyFileIO_Type,但是您必须先声明它。 (原文位于 Python 源码中的 _iomodule.h 中):

    extern PyTypeObject PyFileIO_Type;
    

    【讨论】: