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

Skip to content

Commit 7b216c5

Browse files
committed
Make PyGC_Collect() use Py_ssize_t.
1 parent 84632ee commit 7b216c5

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

Include/objimpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
229229
*/
230230

231231
/* C equivalent of gc.collect(). */
232-
PyAPI_FUNC(long) PyGC_Collect(void);
232+
PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);
233233

234234
/* Test if a type has a GC head */
235235
#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)

Modules/gcmodule.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ gc_list_merge(PyGC_Head *from, PyGC_Head *to)
196196
gc_list_init(from);
197197
}
198198

199-
static long
199+
static Py_ssize_t
200200
gc_list_size(PyGC_Head *list)
201201
{
202202
PyGC_Head *gc;
203-
long n = 0;
203+
Py_ssize_t n = 0;
204204
for (gc = list->gc.gc_next; gc != list; gc = gc->gc.gc_next) {
205205
n++;
206206
}
@@ -719,12 +719,12 @@ delete_garbage(PyGC_Head *collectable, PyGC_Head *old)
719719

720720
/* This is the main function. Read this to understand how the
721721
* collection process works. */
722-
static long
722+
static Py_ssize_t
723723
collect(int generation)
724724
{
725725
int i;
726-
long m = 0; /* # objects collected */
727-
long n = 0; /* # unreachable objects that couldn't be collected */
726+
Py_ssize_t m = 0; /* # objects collected */
727+
Py_ssize_t n = 0; /* # unreachable objects that couldn't be collected */
728728
PyGC_Head *young; /* the generation we are examining */
729729
PyGC_Head *old; /* next older generation */
730730
PyGC_Head unreachable; /* non-problematic unreachable trash */
@@ -856,11 +856,11 @@ collect(int generation)
856856
return n+m;
857857
}
858858

859-
static long
859+
static Py_ssize_t
860860
collect_generations(void)
861861
{
862862
int i;
863-
long n = 0;
863+
Py_ssize_t n = 0;
864864

865865
/* Find the oldest generation (higest numbered) where the count
866866
* exceeds the threshold. Objects in the that generation and
@@ -919,7 +919,7 @@ PyDoc_STRVAR(gc_collect__doc__,
919919
static PyObject *
920920
gc_collect(PyObject *self, PyObject *noargs)
921921
{
922-
long n;
922+
Py_ssize_t n;
923923

924924
if (collecting)
925925
n = 0; /* already collecting, don't do anything */
@@ -929,7 +929,7 @@ gc_collect(PyObject *self, PyObject *noargs)
929929
collecting = 0;
930930
}
931931

932-
return Py_BuildValue("l", n);
932+
return PyInt_FromSsize_t(n);
933933
}
934934

935935
PyDoc_STRVAR(gc_set_debug__doc__,
@@ -1181,10 +1181,10 @@ initgc(void)
11811181
}
11821182

11831183
/* API to invoke gc.collect() from C */
1184-
long
1184+
Py_ssize_t
11851185
PyGC_Collect(void)
11861186
{
1187-
long n;
1187+
Py_ssize_t n;
11881188

11891189
if (collecting)
11901190
n = 0; /* already collecting, don't do anything */

0 commit comments

Comments
 (0)