Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df4518c

Browse files
Issue #22453: Removed non-documented macro PyObject_REPR().
1 parent 3aa979e commit df4518c

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

Doc/whatsnew/3.5.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,7 @@ Changes in the C API
441441

442442
* The :c:type:`PyMemAllocator` structure was renamed to
443443
:c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
444+
445+
* Removed non-documented macro :c:macro:`PyObject_REPR` which leaked references.
446+
Use format character ``%R`` in :c:func:`PyUnicode_FromFormat`-like functions
447+
to format the :func:`repr` of the object.

Include/object.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,6 @@ PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *);
575575
PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
576576
PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
577577

578-
/* Helper for passing objects to printf and the like */
579-
#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
580-
581578
/* Flag bits for printing: */
582579
#define Py_PRINT_RAW 1 /* No string quotes etc. */
583580

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,8 @@ Build
12561256
C API
12571257
-----
12581258

1259+
- Issue #22453: Removed non-documented macro PyObject_REPR().
1260+
12591261
- Issue #18395: Rename ``_Py_char2wchar()`` to :c:func:`Py_DecodeLocale`,
12601262
rename ``_Py_wchar2char()`` to :c:func:`Py_EncodeLocale`, and document
12611263
these functions.

Python/compile.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,12 +1414,12 @@ get_ref_type(struct compiler *c, PyObject *name)
14141414
PyOS_snprintf(buf, sizeof(buf),
14151415
"unknown scope for %.100s in %.100s(%s)\n"
14161416
"symbols: %s\nlocals: %s\nglobals: %s",
1417-
PyBytes_AS_STRING(name),
1418-
PyBytes_AS_STRING(c->u->u_name),
1419-
PyObject_REPR(c->u->u_ste->ste_id),
1420-
PyObject_REPR(c->u->u_ste->ste_symbols),
1421-
PyObject_REPR(c->u->u_varnames),
1422-
PyObject_REPR(c->u->u_names)
1417+
PyUnicode_AsUTF8(name),
1418+
PyUnicode_AsUTF8(c->u->u_name),
1419+
PyUnicode_AsUTF8(PyObject_Repr(c->u->u_ste->ste_id)),
1420+
PyUnicode_AsUTF8(PyObject_Repr(c->u->u_ste->ste_symbols)),
1421+
PyUnicode_AsUTF8(PyObject_Repr(c->u->u_varnames)),
1422+
PyUnicode_AsUTF8(PyObject_Repr(c->u->u_names))
14231423
);
14241424
Py_FatalError(buf);
14251425
}
@@ -1476,11 +1476,11 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, Py_ssize_t args, PyO
14761476
fprintf(stderr,
14771477
"lookup %s in %s %d %d\n"
14781478
"freevars of %s: %s\n",
1479-
PyObject_REPR(name),
1480-
PyBytes_AS_STRING(c->u->u_name),
1479+
PyUnicode_AsUTF8(PyObject_Repr(name)),
1480+
PyUnicode_AsUTF8(c->u->u_name),
14811481
reftype, arg,
1482-
_PyUnicode_AsString(co->co_name),
1483-
PyObject_REPR(co->co_freevars));
1482+
PyUnicode_AsUTF8(co->co_name),
1483+
PyUnicode_AsUTF8(PyObject_Repr(co->co_freevars)));
14841484
Py_FatalError("compiler_make_closure()");
14851485
}
14861486
ADDOP_I(c, LOAD_CLOSURE, arg);

0 commit comments

Comments
 (0)