cpyext: tp_doc field not reflected on Python side

Issue #2446 resolved
Wenzel Jakob
created an issue

Hi,

while porting pybind11 to PyPy, I've noticed that cpyext does not seem to propagate the tp_doc field to the __doc__ field of a newly created type. This happens even in the case where tp_doc is properly set before the PyType_Ready call and never touched afterwards.

My diagnostics for an example type print the following info about the fields just before PyType_Ready:

==================================
 ** Before call to PyType_Ready ** 
tp_name = ExamplePythonTypes
tp_base = NULL
tp_bases = NULL
ob_type = <class '__main__.ExamplePythonTypes__Meta'>
tp_flags = 133115
tp_basicsize = 56
tp_weaklistoffset = 32
tp_dictoffset = 0
tp_doc = Example 2 documentation
==================================
==================================
 ** After call to PyType_Ready ** 
tp_name = ExamplePythonTypes
tp_base = <type 'object'>
tp_bases = (<type 'object'>,)
ob_type = <class '__main__.ExamplePythonTypes__Meta'>
tp_flags = 137211
tp_basicsize = 56
tp_weaklistoffset = 32
tp_dictoffset = 0
tp_doc = Example 2 documentation
==================================

If I later inspect the docstring on the Python side, I just get an empty string:

>>>> pybind11_tests.ExamplePythonTypes.__doc__
>>>>

(however, I would have expected to get Example 2 documentation)

I assume that PyPy was supposed to make a copy of that string when PyType_Ready is called -- but just in case, the C char array also still exists (i.e. pybind11 doesn't delete it).

So I assume this is some kind of a bug.

Comments (4)

  1. Armin Rigo

    Can you come up with a test (a minimal use case would be fine)? We already have tests that show that tp_doc ends up as the type's __doc__. I guess your ExamplePythonTypes class is somehow different than in our own tests.

  2. Log in to comment