[New-bugs-announce] [issue29165] Use forward compatible macro in example code for creating new type

INADA Naoki report at bugs.python.org
Thu Jan 5 01:47:59 EST 2017


New submission from INADA Naoki:

https://docs.python.org/2.7/extending/newtypes.html#the-basics uses PyObject_HEAD_INIT for type object header.

static PyTypeObject noddy_NoddyType = {
    PyObject_HEAD_INIT(NULL)
    0,                         /*ob_size*/

This code isn't compatible with Python 3.  In Python 3, PyVarObject_HEAD_INIT is used instead.
https://docs.python.org/3.6/extending/newtypes.html#the-basics

static PyTypeObject noddy_NoddyType = {
    PyVarObject_HEAD_INIT(NULL, 0)

This code is compatible with Python 2.


This example code can be copy and pasted when creating new extension.
If people start writing Python 2 extension, and forward port it to Python 3,
this small incompatibility cause compile error.

Let's use more forward compatible and short code for example.

----------
assignee: docs at python
components: Documentation
messages: 284709
nosy: docs at python, inada.naoki
priority: normal
severity: normal
status: open
title: Use forward compatible macro in example code for creating new type
type: enhancement
versions: Python 2.7

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


More information about the New-bugs-announce mailing list