This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2008年07月03日 17:54 by stutzbach, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg69213 - (view) | Author: Daniel Stutzbach (stutzbach) (Python committer) | Date: 2008年07月03日 17:54 | |
I'm writing a C extension module and discovered that Py_CLEAR() causes a
crash if the programmer happened to name their variable "tmp". The
Py_CLEAR() macro internally uses the name "tmp" in a new scope, hiding
the callers "tmp", and calling Py_DECREF() on an essentially random bit
of memory.
I suggest changing Py_CLEAR() to use something a little less common than
"tmp". Perhaps "_py_tmp".
For easy reference, here's how Py_CLEAR() is defined now:
#define Py_CLEAR(op) \
do { \
if (op) { \
PyObject *tmp = (PyObject *)(op); \
(op) = NULL; \
Py_DECREF(tmp); \
} \
} while (0)
|
|||
| msg69498 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2008年07月10日 10:11 | |
A better option may be to append _tmp to the passed in token:
#define Py_CLEAR(op) \
do { \
if (op) { \
PyObject *op##_tmp = (PyObject *)(op); \
(op) = NULL; \
Py_DECREF(op##_tmp); \
} \
} while (0)
|
|||
| msg69500 - (view) | Author: Daniel Stutzbach (stutzbach) (Python committer) | Date: 2008年07月10日 12:24 | |
Appending _tmp is a good idea, but it won't work when the parameter isn't a simple symbol. For example, there's a line in cPickle.c like this: Py_CLEAR(*p). |
|||
| msg69621 - (view) | Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) | Date: 2008年07月13日 20:43 | |
Committed the fix r64927. Thanks. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:36 | admin | set | github: 47524 |
| 2008年07月13日 20:43:46 | alexandre.vassalotti | set | status: open -> closed resolution: fixed messages: + msg69621 nosy: + alexandre.vassalotti |
| 2008年07月10日 12:24:55 | stutzbach | set | messages: + msg69500 |
| 2008年07月10日 10:11:07 | ncoghlan | set | nosy:
+ ncoghlan messages: + msg69498 |
| 2008年07月03日 17:54:08 | stutzbach | create | |