[docs] [issue10773] "Building C and C++ Extensions on Windows" documentation shows 2.x way of initializing module

Thorsten Behrens report at bugs.python.org
Sun Dec 26 18:27:44 CET 2010


New submission from Thorsten Behrens <sbehrens at gmx.li>:

The documentation titled "Building C and C++ Extensions on Windows" at http://docs.python.org/py3k/extending/windows.html shows a Python 2.x way of handling static type object initializers, to whit:

>>
If your module creates a new type, you may have trouble with this line:

PyVarObject_HEAD_INIT(&PyType_Type, 0)

Static type object initializers in extension modules may cause compiles to fail with an error message like “initializer not a constant”. This shows up when building DLL under MSVC. Change it to:

PyVarObject_HEAD_INIT(NULL, 0)

and add the following to the module initialization function:

MyObject_Type.ob_type = &PyType_Type;

>>

That last line will not function in Python 3.x. However, PyType_Ready will fill in the ob_type field if it is empty, if I understand PyType_Ready correctly. Therefore, the last few lines of this documentation snippet can become:

>>
and add the following to the module initialization function:

if (PyType_Ready(&MyObject_Type) < 0)
    return NULL;
>>

----------
assignee: docs at python
components: Documentation
messages: 124667
nosy: docs at python, thorsten.behrens
priority: normal
severity: normal
status: open
title: "Building C and C++ Extensions on Windows" documentation shows 2.x way of initializing module
versions: Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10773>
_______________________________________


More information about the docs mailing list