Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Macro Py_CLEAR references argument two times. #98724

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@hochl

Description

@hochl

Bug report

The macroPy_CLEAR(op) references the argumentop two times. If the macro is called with an expression it will be evaluated two times, for examplePy_CLEAR(p++).

Your environment

x86_64

  • CPython versions tested on:
    Python 3.7m
  • Operating system and architecture:
    Debian Stable

I suggest a fix similar to this (old version commented out with #if 0):

#if 0#define Py_CLEAR(op)                            \    do {                                        \        PyObject *_py_tmp = (PyObject *)(op);   \        if (_py_tmp != NULL) {                  \            (op) = NULL;                        \            Py_DECREF(_py_tmp);                 \        }                                       \    } while (0)#else#define Py_CLEAR(op)                                         \    do {                                                     \        PyObject **_py_tmp = (PyObject **)&(op);             \        if (*_py_tmp != NULL) {                              \            PyObject *_py_tmp2 = *_py_tmp;                   \            (*_py_tmp) = NULL;                               \            Py_DECREF(_py_tmp2);                             \        }                                                    \    } while (0)#endif

I am not sure if this has happened anywhere, but I see a possible problem here. I think the compiler will optimize out the additional temporary variable in most cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp