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

Skip to content

Commit 8b87a0b

Browse files
committed
Use %ld and casts to long for refcount printing, in absense of a universally
available %zd format character. Mark with an XXX comment so we can fix this, later.
1 parent 572a9f3 commit 8b87a0b

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

Objects/floatobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,9 +1326,13 @@ PyFloat_Fini(void)
13261326
p->ob_refcnt != 0) {
13271327
char buf[100];
13281328
PyFloat_AsString(buf, p);
1329+
/* XXX(twouters) cast refcount to
1330+
long until %zd is universally
1331+
available
1332+
*/
13291333
fprintf(stderr,
1330-
"# <float at %p, refcnt=%d, val=%s>\n",
1331-
p, p->ob_refcnt, buf);
1334+
"# <float at %p, refcnt=%ld, val=%s>\n",
1335+
p, (long)p->ob_refcnt, buf);
13321336
}
13331337
}
13341338
list = list->next;

Objects/intobject.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,9 +1220,14 @@ PyInt_Fini(void)
12201220
i < N_INTOBJECTS;
12211221
i++, p++) {
12221222
if (PyInt_CheckExact(p) && p->ob_refcnt != 0)
1223+
/* XXX(twouters) cast refcount to
1224+
long until %zd is universally
1225+
available
1226+
*/
12231227
fprintf(stderr,
1224-
"# <int at %p, refcnt=%d, val=%ld>\n",
1225-
p, p->ob_refcnt, p->ob_ival);
1228+
"# <int at %p, refcnt=%ld, val=%ld>\n",
1229+
p, (long)p->ob_refcnt,
1230+
p->ob_ival);
12261231
}
12271232
list = list->next;
12281233
}

Objects/object.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ _Py_NegativeRefcount(const char *fname, int lineno, PyObject *op)
138138
{
139139
char buf[300];
140140

141+
/* XXX(twouters) cast refcount to long until %zd is universally
142+
available */
141143
PyOS_snprintf(buf, sizeof(buf),
142-
"%s:%i object at %p has negative ref count %i",
143-
fname, lineno, op, op->ob_refcnt);
144+
"%s:%i object at %p has negative ref count %ld",
145+
fname, lineno, op, (long)op->ob_refcnt);
144146
Py_FatalError(buf);
145147
}
146148

@@ -233,8 +235,10 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
233235
}
234236
else {
235237
if (op->ob_refcnt <= 0)
236-
fprintf(fp, "<refcnt %u at %p>",
237-
op->ob_refcnt, op);
238+
/* XXX(twouters) cast refcount to long until %zd is
239+
universally available */
240+
fprintf(fp, "<refcnt %ld at %p>",
241+
(long)op->ob_refcnt, op);
238242
else if (op->ob_type->tp_print == NULL) {
239243
PyObject *s;
240244
if (flags & Py_PRINT_RAW)
@@ -277,12 +281,14 @@ void _PyObject_Dump(PyObject* op)
277281
else {
278282
fprintf(stderr, "object : ");
279283
(void)PyObject_Print(op, stderr, 0);
284+
/* XXX(twouters) cast refcount to long until %zd is
285+
universally available */
280286
fprintf(stderr, "\n"
281287
"type : %s\n"
282-
"refcount: %d\n"
288+
"refcount: %ld\n"
283289
"address : %p\n",
284290
op->ob_type==NULL ? "NULL" : op->ob_type->tp_name,
285-
op->ob_refcnt,
291+
(long)op->ob_refcnt,
286292
op);
287293
}
288294
}
@@ -1893,7 +1899,9 @@ _Py_PrintReferences(FILE *fp)
18931899
PyObject *op;
18941900
fprintf(fp, "Remaining objects:\n");
18951901
for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) {
1896-
fprintf(fp, "%p [%d] ", op, op->ob_refcnt);
1902+
/* XXX(twouters) cast refcount to long until %zd is
1903+
universally available */
1904+
fprintf(fp, "%p [%ld] ", op, (long)op->ob_refcnt);
18971905
if (PyObject_Print(op, fp, 0) != 0)
18981906
PyErr_Clear();
18991907
putc('\n', fp);
@@ -1909,7 +1917,9 @@ _Py_PrintReferenceAddresses(FILE *fp)
19091917
PyObject *op;
19101918
fprintf(fp, "Remaining object addresses:\n");
19111919
for (op = refchain._ob_next; op != &refchain; op = op->_ob_next)
1912-
fprintf(fp, "%p [%d] %s\n", op, op->ob_refcnt,
1920+
/* XXX(twouters) cast refcount to long until %zd is
1921+
universally available */
1922+
fprintf(fp, "%p [%ld] %s\n", op, (long)op->ob_refcnt,
19131923
op->ob_type->tp_name);
19141924
}
19151925

0 commit comments

Comments
 (0)