[issue20440] Use Py_REPLACE/Py_XREPLACE macros

Serhiy Storchaka report at bugs.python.org
Wed Jan 29 19:14:18 CET 2014


New submission from Serhiy Storchaka:

Proposed patches replaced idiomatic code

    Py_DECREF(ptr);
    ptr = new_value;

to "Py_REPLACE(ptr, new_value);" which is expanded to

    {
        PyObject *__tmp__ = ptr;
        ptr = new_value;
        Py_DECREF(__tmp__);
    }

(and same for Py_XDECREF -> Py_XREPLACE).

Victor proposed large patch for issue16447, but this issue was closed after fixing particular bug. Here are updated patches, which Py_REPLACE/Py_XREPLACE macros for cleaner code. They are also generated automatically by the Coccinelle tool (http://coccinelle.lip6.fr/):

spatch --in-place --sp-file py_replace.spatch --dir .

Patch for every version contains about 50 replaces in about 21-24 files.

----------
components: Extension Modules, Interpreter Core
files: py_replace.spatch
messages: 209663
nosy: benjamin.peterson, georg.brandl, haypo, larry, serhiy.storchaka, skrah
priority: normal
severity: normal
stage: patch review
status: open
title: Use Py_REPLACE/Py_XREPLACE macros
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file33800/py_replace.spatch

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


More information about the Python-bugs-list mailing list