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

Skip to content

Commit 4281cef

Browse files
committed
Use Py_ssize_t for _Py_RefTotal.
I tried to handle Win64 properly, but please review.
1 parent 9589ee2 commit 4281cef

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

Include/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ environment the global variable trick is not safe.)
568568
* #ifdefs (we used to do that -- it was impenetrable).
569569
*/
570570
#ifdef Py_REF_DEBUG
571-
PyAPI_DATA(long) _Py_RefTotal;
571+
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
572572
PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
573573
int lineno, PyObject *op);
574574
#define _Py_INC_REFTOTAL _Py_RefTotal++

Python/pythonrun.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
#include "windows.h"
3030
#endif
3131

32+
#ifndef Py_REF_DEBUG
33+
# define PRINT_TOTAL_REFS()
34+
#else /* Py_REF_DEBUG */
35+
# if defined(MS_WIN64)
36+
# define PRINT_TOTAL_REFS() fprintf(stderr, "[%zd refs]\n", _Py_RefTotal);
37+
# else /* ! MS_WIN64 */
38+
# define PRINT_TOTAL_REFS() fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
39+
# endif /* MS_WIN64 */
40+
#endif
41+
3242
extern char *Py_GetPath(void);
3343

3444
extern grammar _PyParser_Grammar; /* From graminit.c */
@@ -382,9 +392,7 @@ Py_Finalize(void)
382392
dump_counts();
383393
#endif
384394

385-
#ifdef Py_REF_DEBUG
386-
fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
387-
#endif
395+
PRINT_TOTAL_REFS()
388396

389397
#ifdef Py_TRACE_REFS
390398
/* Display all objects still alive -- this can invoke arbitrary
@@ -674,9 +682,7 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flag
674682
}
675683
for (;;) {
676684
ret = PyRun_InteractiveOneFlags(fp, filename, flags);
677-
#ifdef Py_REF_DEBUG
678-
fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
679-
#endif
685+
PRINT_TOTAL_REFS()
680686
if (ret == E_EOF)
681687
return 0;
682688
/*

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ sys_getrefcount(PyObject *self, PyObject *arg)
604604
static PyObject *
605605
sys_gettotalrefcount(PyObject *self)
606606
{
607-
return PyInt_FromLong(_Py_RefTotal);
607+
return PyInt_FromSsize_t(_Py_RefTotal);
608608
}
609609

610610
#endif /* Py_TRACE_REFS */

0 commit comments

Comments
 (0)