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

Skip to content

Commit 943382c

Browse files
committed
Removed WITH_CYCLE_GC #ifdef-ery. Holes:
+ I'm not sure what to do about configure.in. Left it alone. + Ditto pyexpat.c. Fred or Martin will know what to do.
1 parent 12f4f35 commit 943382c

12 files changed

Lines changed: 22 additions & 106 deletions

File tree

Include/Python.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
#include "patchlevel.h"
2424
#include "pyconfig.h"
2525

26+
/* Cyclic gc is always enabled, starting with release 2.3a1. Supply the
27+
* old symbol for the benefit of extension modules written before then
28+
* that may be conditionalizing on it. The core doesn't use it anymore.
29+
*/
30+
#ifndef WITH_CYCLE_GC
31+
#define WITH_CYCLE_GC 1
32+
#endif
33+
2634
#ifdef HAVE_LIMITS_H
2735
#include <limits.h>
2836
#endif

Include/object.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,7 @@ given type object has a specified feature.
441441
#define Py_TPFLAGS_READYING (1L<<13)
442442

443443
/* Objects support garbage collection (see objimp.h) */
444-
#ifdef WITH_CYCLE_GC
445444
#define Py_TPFLAGS_HAVE_GC (1L<<14)
446-
#else
447-
#define Py_TPFLAGS_HAVE_GC 0
448-
#endif
449445

450446
#define Py_TPFLAGS_DEFAULT ( \
451447
Py_TPFLAGS_HAVE_GETCHARBUFFER | \

Include/objimpl.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ extern DL_IMPORT(PyVarObject *) _PyObject_NewVar(PyTypeObject *, int);
226226
/*
227227
* Garbage Collection Support
228228
* ==========================
229-
*
230-
* Some of the functions and macros below are always defined; when
231-
* WITH_CYCLE_GC is undefined, they simply don't do anything different
232-
* than their non-GC counterparts.
233229
*/
234230

235231
/* Test if a type has a GC head */
@@ -246,8 +242,6 @@ extern DL_IMPORT(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, int);
246242
/* for source compatibility with 2.2 */
247243
#define _PyObject_GC_Del PyObject_GC_Del
248244

249-
#ifdef WITH_CYCLE_GC
250-
251245
/* GC information is stored BEFORE the object structure. */
252246
typedef union _gc_head {
253247
struct {
@@ -305,19 +299,6 @@ extern DL_IMPORT(void) PyObject_GC_Del(void *);
305299
( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
306300

307301

308-
#else /* !WITH_CYCLE_GC */
309-
310-
#define _PyObject_GC_Malloc PyObject_Malloc
311-
#define PyObject_GC_New PyObject_New
312-
#define PyObject_GC_NewVar PyObject_NewVar
313-
#define PyObject_GC_Del PyObject_Del
314-
#define _PyObject_GC_TRACK(op)
315-
#define _PyObject_GC_UNTRACK(op)
316-
#define PyObject_GC_Track(op)
317-
#define PyObject_GC_UnTrack(op)
318-
319-
#endif
320-
321302
/* This is here for the sake of backwards compatibility. Extensions that
322303
* use the old GC API will still compile but the objects will not be
323304
* tracked by the GC. */

Misc/NEWS

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ Extension modules
170170

171171
Library
172172

173+
- binascii.crc32() and the zipfile module had problems on some 64-bit
174+
platforms. These have been fixed. On a platform with 8-byte C longs,
175+
crc32() now returns a signed-extended 4-byte result, so that its value
176+
as a Python int is equal to the value computed a 32-bit platform.
177+
173178
- xml.dom.minidom.toxml and toprettyxml now take an optional encoding
174179
argument.
175180

@@ -289,6 +294,15 @@ Tools/Demos
289294

290295
Build
291296

297+
- Compiling out the cyclic garbage collector is no longer an option.
298+
The old symbol WITH_CYCLE_GC is now ignored, and Python.h arranges
299+
that it's always defined (for the benefit of any extension modules
300+
that may be conditionalizing on it). A bonus is that any extension
301+
type participating in cyclic gc can choose to participate in the
302+
Py_TRASHCAN mechanism now too; in the absence of cyclic gc, this used
303+
to require editing the core to teach the trashcan mechanism about the
304+
new type.
305+
292306
- Accoring to Annex F of the current C standard,
293307

294308
The Standard C macro HUGE_VAL and its float and long double analogs,

Modules/config.c.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ struct _inittab _PyImport_Inittab[] = {
4040
{"sys", NULL},
4141
{"exceptions", NULL},
4242

43-
#ifdef WITH_CYCLE_GC
4443
/* This lives in gcmodule.c */
4544
{"gc", initgc},
46-
#endif
4745

4846
/* Sentinel */
4947
{0, 0}

Modules/gcmodule.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
#include "Python.h"
2222

23-
#ifdef WITH_CYCLE_GC
24-
2523
/* Get an object's GC head */
2624
#define AS_GC(o) ((PyGC_Head *)(o)-1)
2725

@@ -941,8 +939,6 @@ void _PyGC_Dump(PyGC_Head *g)
941939
_PyObject_Dump(FROM_GC(g));
942940
}
943941

944-
#endif /* WITH_CYCLE_GC */
945-
946942
/* extension modules might be compiled with GC support so these
947943
functions must always be available */
948944

@@ -967,10 +963,8 @@ _PyObject_GC_Track(PyObject *op)
967963
void
968964
PyObject_GC_UnTrack(void *op)
969965
{
970-
#ifdef WITH_CYCLE_GC
971966
if (IS_TRACKED(op))
972967
_PyObject_GC_UNTRACK(op);
973-
#endif
974968
}
975969

976970
/* for binary compatibility with 2.2 */
@@ -984,7 +978,6 @@ PyObject *
984978
_PyObject_GC_Malloc(size_t basicsize)
985979
{
986980
PyObject *op;
987-
#ifdef WITH_CYCLE_GC
988981
PyGC_Head *g = PyObject_MALLOC(sizeof(PyGC_Head) + basicsize);
989982
if (g == NULL)
990983
return PyErr_NoMemory();
@@ -1000,12 +993,6 @@ _PyObject_GC_Malloc(size_t basicsize)
1000993
collecting = 0;
1001994
}
1002995
op = FROM_GC(g);
1003-
#else
1004-
op = PyObject_MALLOC(basicsize);
1005-
if (op == NULL)
1006-
return PyErr_NoMemory();
1007-
1008-
#endif
1009996
return op;
1010997
}
1011998

@@ -1032,35 +1019,25 @@ PyVarObject *
10321019
_PyObject_GC_Resize(PyVarObject *op, int nitems)
10331020
{
10341021
const size_t basicsize = _PyObject_VAR_SIZE(op->ob_type, nitems);
1035-
#ifdef WITH_CYCLE_GC
10361022
PyGC_Head *g = AS_GC(op);
10371023
g = PyObject_REALLOC(g, sizeof(PyGC_Head) + basicsize);
10381024
if (g == NULL)
10391025
return (PyVarObject *)PyErr_NoMemory();
10401026
op = (PyVarObject *) FROM_GC(g);
1041-
#else
1042-
op = PyObject_REALLOC(op, basicsize);
1043-
if (op == NULL)
1044-
return (PyVarObject *)PyErr_NoMemory();
1045-
#endif
10461027
op->ob_size = nitems;
10471028
return op;
10481029
}
10491030

10501031
void
10511032
PyObject_GC_Del(void *op)
10521033
{
1053-
#ifdef WITH_CYCLE_GC
10541034
PyGC_Head *g = AS_GC(op);
10551035
if (IS_TRACKED(op))
10561036
gc_list_remove(g);
10571037
if (generations[0].count > 0) {
10581038
generations[0].count--;
10591039
}
10601040
PyObject_FREE(g);
1061-
#else
1062-
PyObject_FREE(op);
1063-
#endif
10641041
}
10651042

10661043
/* for binary compatibility with 2.2 */

Objects/classobject.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,6 @@ instance_dealloc(register PyInstanceObject *inst)
678678
/* compensate for increment in _Py_ForgetReference */
679679
inst->ob_type->tp_frees--;
680680
#endif
681-
#ifndef WITH_CYCLE_GC
682-
inst->ob_type = NULL;
683-
#endif
684681
#endif
685682
Py_DECREF(inst->in_class);
686683
Py_XDECREF(inst->in_dict);

Objects/object.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,29 +2080,8 @@ PyObject * _PyTrash_delete_later = NULL;
20802080
void
20812081
_PyTrash_deposit_object(PyObject *op)
20822082
{
2083-
#ifndef WITH_CYCLE_GC
2084-
int typecode;
2085-
2086-
if (PyTuple_Check(op))
2087-
typecode = Py_TRASHCAN_TUPLE;
2088-
else if (PyList_Check(op))
2089-
typecode = Py_TRASHCAN_LIST;
2090-
else if (PyDict_Check(op))
2091-
typecode = Py_TRASHCAN_DICT;
2092-
else if (PyFrame_Check(op))
2093-
typecode = Py_TRASHCAN_FRAME;
2094-
else if (PyTraceBack_Check(op))
2095-
typecode = Py_TRASHCAN_TRACEBACK;
2096-
else /* We have a bug here -- those are the only types in GC */ {
2097-
Py_FatalError("Type not supported in GC -- internal bug");
2098-
return; /* pacify compiler -- execution never here */
2099-
}
2100-
op->ob_refcnt = typecode;
2101-
op->ob_type = (PyTypeObject*)_PyTrash_delete_later;
2102-
#else
21032083
assert (_Py_AS_GC(op)->gc.gc_next == NULL);
21042084
_Py_AS_GC(op)->gc.gc_prev = (PyGC_Head *)_PyTrash_delete_later;
2105-
#endif
21062085
_PyTrash_delete_later = op;
21072086
}
21082087

@@ -2112,30 +2091,8 @@ _PyTrash_destroy_chain(void)
21122091
while (_PyTrash_delete_later) {
21132092
PyObject *shredder = _PyTrash_delete_later;
21142093

2115-
#ifndef WITH_CYCLE_GC
2116-
_PyTrash_delete_later = (PyObject*) shredder->ob_type;
2117-
2118-
switch (shredder->ob_refcnt) {
2119-
case Py_TRASHCAN_TUPLE:
2120-
shredder->ob_type = &PyTuple_Type;
2121-
break;
2122-
case Py_TRASHCAN_LIST:
2123-
shredder->ob_type = &PyList_Type;
2124-
break;
2125-
case Py_TRASHCAN_DICT:
2126-
shredder->ob_type = &PyDict_Type;
2127-
break;
2128-
case Py_TRASHCAN_FRAME:
2129-
shredder->ob_type = &PyFrame_Type;
2130-
break;
2131-
case Py_TRASHCAN_TRACEBACK:
2132-
shredder->ob_type = &PyTraceBack_Type;
2133-
break;
2134-
}
2135-
#else
21362094
_PyTrash_delete_later =
21372095
(PyObject*) _Py_AS_GC(shredder)->gc.gc_prev;
2138-
#endif
21392096

21402097
_Py_NewReference(shredder);
21412098

PC/config.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ extern void initaudioop(void);
1212
extern void initbinascii(void);
1313
extern void initcmath(void);
1414
extern void initerrno(void);
15-
#ifdef WITH_CYCLE_GC
1615
extern void initgc(void);
17-
#endif
1816
#ifndef MS_WIN64
1917
extern void initimageop(void);
2018
#endif
@@ -63,9 +61,7 @@ struct _inittab _PyImport_Inittab[] = {
6361
{"binascii", initbinascii},
6462
{"cmath", initcmath},
6563
{"errno", initerrno},
66-
#ifdef WITH_CYCLE_GC
6764
{"gc", initgc},
68-
#endif
6965
#ifndef MS_WIN64
7066
{"imageop", initimageop},
7167
#endif

PC/pyconfig.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,6 @@ typedef int pid_t;
499499
#define HAVE_USABLE_WCHAR_T
500500
#endif
501501

502-
/* Define if you want cycle garbage collection */
503-
#define WITH_CYCLE_GC 1
504-
505502
/* Use Python's own small-block memory-allocator. */
506503
#define WITH_PYMALLOC 1
507504

0 commit comments

Comments
 (0)