[Python-checkins] cpython (3.4): Issue #22453: Warn against the use of leaking macro PyObject_REPR().
serhiy.storchaka
python-checkins at python.org
Tue Nov 18 23:17:27 CET 2014
https://hg.python.org/cpython/rev/342a619cdafb
changeset: 93505:342a619cdafb
branch: 3.4
parent: 93501:ab3e8aab7119
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Nov 19 00:08:38 2014 +0200
summary:
Issue #22453: Warn against the use of leaking macro PyObject_REPR().
files:
Include/object.h | 8 ++++++--
Python/compile.c | 20 ++++++++++----------
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/Include/object.h b/Include/object.h
--- a/Include/object.h
+++ b/Include/object.h
@@ -572,8 +572,12 @@
PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
-/* Helper for passing objects to printf and the like */
-#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
+#ifndef Py_LIMITED_API
+/* Helper for passing objects to printf and the like.
+ Leaks refcounts. Don't use it!
+*/
+#define PyObject_REPR(obj) PyUnicode_AsUTF8(PyObject_Repr(obj))
+#endif
/* Flag bits for printing: */
#define Py_PRINT_RAW 1 /* No string quotes etc. */
diff --git a/Python/compile.c b/Python/compile.c
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1412,12 +1412,12 @@
PyOS_snprintf(buf, sizeof(buf),
"unknown scope for %.100s in %.100s(%s)\n"
"symbols: %s\nlocals: %s\nglobals: %s",
- PyBytes_AS_STRING(name),
- PyBytes_AS_STRING(c->u->u_name),
- PyObject_REPR(c->u->u_ste->ste_id),
- PyObject_REPR(c->u->u_ste->ste_symbols),
- PyObject_REPR(c->u->u_varnames),
- PyObject_REPR(c->u->u_names)
+ PyUnicode_AsUTF8(name),
+ PyUnicode_AsUTF8(c->u->u_name),
+ PyUnicode_AsUTF8(PyObject_Repr(c->u->u_ste->ste_id)),
+ PyUnicode_AsUTF8(PyObject_Repr(c->u->u_ste->ste_symbols)),
+ PyUnicode_AsUTF8(PyObject_Repr(c->u->u_varnames)),
+ PyUnicode_AsUTF8(PyObject_Repr(c->u->u_names))
);
Py_FatalError(buf);
}
@@ -1474,11 +1474,11 @@
fprintf(stderr,
"lookup %s in %s %d %d\n"
"freevars of %s: %s\n",
- PyObject_REPR(name),
- PyBytes_AS_STRING(c->u->u_name),
+ PyUnicode_AsUTF8(PyObject_Repr(name)),
+ PyUnicode_AsUTF8(c->u->u_name),
reftype, arg,
- _PyUnicode_AsString(co->co_name),
- PyObject_REPR(co->co_freevars));
+ PyUnicode_AsUTF8(co->co_name),
+ PyUnicode_AsUTF8(PyObject_Repr(co->co_freevars)));
Py_FatalError("compiler_make_closure()");
}
ADDOP_I(c, LOAD_CLOSURE, arg);
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list