[issue29165] Use forward compatible macro in example code for creating new type

2017-02-21 Thread INADA Naoki

INADA Naoki added the comment:

> And it seems to me that Doc/includes/shoddy.c in Python 3 is not correct.

I created another pull request PR 215.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29165] Use forward compatible macro in example code for creating new type

2017-02-21 Thread INADA Naoki

Changes by INADA Naoki :


--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29165] Use forward compatible macro in example code for creating new type

2017-02-21 Thread INADA Naoki

INADA Naoki added the comment:


New changeset 9436bbd87b7eed18dec4c32f25b88452fe282e1c by GitHub in branch 
'2.7':
bpo-29165: doc: make extending/newtypes more Python 3 friendly (GH-211)
https://github.com/python/cpython/commit/9436bbd87b7eed18dec4c32f25b88452fe282e1c


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29165] Use forward compatible macro in example code for creating new type

2017-02-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Ah, now I see.

I think sample C files in Doc/includes/ should be updated too. And it seems to 
me that Doc/includes/shoddy.c in Python 3 is not correct.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29165] Use forward compatible macro in example code for creating new type

2017-02-21 Thread INADA Naoki

INADA Naoki added the comment:

> but the code with PyObject_HEAD_INIT() doesn't look incompatible with Python 
> 3.

It's incompatible actually.

https://github.com/python/cpython/blob/2.7/Include/object.h

/* PyObject_HEAD defines the initial segment of every PyObject. */

#define PyObject_HEAD_INIT(type)\
_PyObject_EXTRA_INIT\
1, type,


https://github.com/python/cpython/blob/3.5/Include/object.h

#define PyObject_HEAD_INIT(type)\
{ _PyObject_EXTRA_INIT  \
1, type },


I noticed PyVarObject_HEAD_INIT is compatible, and simplified an extension I 
maintain.
https://github.com/PyMySQL/mysqlclient-python/commit/2feb5ed6850a3905edf0333e0cd11ea6218f0f4f


This small doc change helps people who writing Python 2's extension module now, 
and port it to Python 3 later.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29165] Use forward compatible macro in example code for creating new type

2017-02-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

PyVarObject_HEAD_INIT() is more used in Python 3 code, but the code with 
PyObject_HEAD_INIT() doesn't look incompatible with Python 3. I don't see a 
need of this change.

PyObject_HEAD_INIT() also is used in .c files in Doc/includes/.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29165] Use forward compatible macro in example code for creating new type

2017-02-20 Thread INADA Naoki

Changes by INADA Naoki :


--
pull_requests: +179

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29165] Use forward compatible macro in example code for creating new type

2017-01-04 Thread INADA Naoki

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com