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@python
components: Documentation
messages: 284709
nosy: docs@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue29165>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to