diff -cr Python-malloc/Include/mymalloc.h Python-gc/Include/mymalloc.h *** Python-malloc/Include/mymalloc.h Sat Feb 5 09:11:36 2000 --- Python-gc/Include/mymalloc.h Sat Feb 5 09:11:54 2000 *************** *** 87,92 **** --- 87,110 ---- #define _PyMem_EXTRA 0 #endif + #ifdef WITH_GC + + #include + #define PyMem_MALLOC(n) GC_MALLOC(n) + #define PyMem_REALLOC(p, n) GC_REALLOC(p, n) + #define PyMem_NEW(type, n) \ + ( (type *) GC_MALLOC(_PyMem_EXTRA + (n) * sizeof(type)) ) + #define PyMem_RESIZE(p, type, n) \ + if ((p) == NULL) \ + (p) = (type *) GC_MALLOC(_PyMem_EXTRA + (n) * sizeof(type)); \ + else \ + (p) = (type *) GC_REALLOC((ANY *)(p), \ + _PyMem_EXTRA + (n) * sizeof(type)) + #define PyMem_DEL(p) GC_FREE((ANY *)p) + #define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p) + + #else /* ! WITH_GC */ + #define PyMem_MALLOC(n) malloc(n) #define PyMem_REALLOC(p, n) realloc(p, n) #define PyMem_NEW(type, n) \ *************** *** 99,104 **** --- 117,124 ---- _PyMem_EXTRA + (n) * sizeof(type)) #define PyMem_DEL(p) free((ANY *)p) #define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p) + + #endif /* WITH_GC */ /* Two sets of function wrappers around malloc and friends; useful if you need to be sure that you are using the same memory allocator as diff -cr Python-malloc/Modules/_tkinter.c Python-gc/Modules/_tkinter.c *** Python-malloc/Modules/_tkinter.c Sat Feb 5 09:11:36 2000 --- Python-gc/Modules/_tkinter.c Sat Feb 5 09:11:54 2000 *************** *** 1268,1274 **** --- 1268,1281 ---- return NULL; } + #ifdef WITH_GC + /* If we use GC_malloc then the gc thinks that there are no more + * references to the callback and collects it */ + data = (PythonCmd_ClientData*) + GC_malloc_uncollectable(sizeof(PythonCmd_ClientData)); + #else data = PyMem_NEW(PythonCmd_ClientData, 1); + #endif if (!data) return NULL; Py_XINCREF(self); *************** *** 1334,1340 **** --- 1341,1354 ---- int id; { FileHandler_ClientData *p; + #ifdef WITH_GC + /* If we use GC_malloc then the gc thinks that there are no more + * references to the callback and collects it */ + p = (FileHandler_ClientData*) + GC_malloc_uncollectable(sizeof(FileHandler_ClientData)); + #else p = PyMem_NEW(FileHandler_ClientData, 1); + #endif if (p != NULL) { Py_XINCREF(func); Py_XINCREF(file); diff -cr Python-malloc/Objects/object.c Python-gc/Objects/object.c *** Python-malloc/Objects/object.c Sat Feb 5 09:11:36 2000 --- Python-gc/Objects/object.c Sat Feb 5 09:11:54 2000 *************** *** 108,113 **** --- 108,124 ---- } #endif + /* + #ifdef WITH_GC + static void + _PyObject_Finalizer(GC_PTR *op, GC_PTR *client_data) + { + destructor dealloc = ((PyObject*)op)->ob_type->tp_dealloc; + (*dealloc)(op); + } + #endif + */ + #ifndef MS_COREDLL PyObject * _PyObject_New(tp) *************** *** 124,129 **** --- 135,145 ---- #endif if (op == NULL) return PyErr_NoMemory(); + /* + #ifdef WITH_GC + GC_register_finalizer(op, _PyObject_Finalizer, 0, 0, 0); + #endif + */ op->ob_type = tp; _Py_NewReference(op); return op; *************** *** 148,153 **** --- 164,174 ---- #endif if (op == NULL) return (PyVarObject *)PyErr_NoMemory(); + /* + #ifdef WITH_GC + GC_register_finalizer(op, _PyObject_Finalizer, 0, 0, 0); + #endif + */ op->ob_type = tp; op->ob_size = size; _Py_NewReference((PyObject *)op); diff -cr Python-malloc/acconfig.h Python-gc/acconfig.h *** Python-malloc/acconfig.h Sat Feb 5 09:11:36 2000 --- Python-gc/acconfig.h Sat Feb 5 09:11:54 2000 *************** *** 126,131 **** --- 126,134 ---- /* Define if you want to compile in rudimentary thread support */ #undef WITH_THREAD + /* Define if you want to use the garbage collector */ + #undef WITH_GC + /* Define if you want to produce an OpenStep/Rhapsody framework (shared library plus accessory files). */ #undef WITH_NEXT_FRAMEWORK diff -cr Python-malloc/config.h.in Python-gc/config.h.in *** Python-malloc/config.h.in Sat Feb 5 09:11:36 2000 --- Python-gc/config.h.in Sat Feb 5 09:11:54 2000 *************** *** 181,186 **** --- 181,189 ---- /* Define if you want to compile in rudimentary thread support */ #undef WITH_THREAD + /* Define if you want to use the garbage collector */ + #undef WITH_GC + /* Define if you want to produce an OpenStep/Rhapsody framework (shared library plus accessory files). */ #undef WITH_NEXT_FRAMEWORK diff -cr Python-malloc/configure.in Python-gc/configure.in *** Python-malloc/configure.in Sat Feb 5 09:11:36 2000 --- Python-gc/configure.in Sat Feb 5 09:11:54 2000 *************** *** 687,692 **** --- 687,704 ---- AC_SUBST(DLINCLDIR) DLINCLDIR=/ + AC_MSG_CHECKING(for --with-gc) + AC_SUBST(LDLAST) + AC_ARG_WITH(gc, + [--with-gc use the Boehm-Demers-Weiser garbage collector], + [AC_MSG_RESULT($withval) + AC_DEFINE(WITH_GC) + LIBS="$LIBS -lgc" + if test "${with_gc+set}" != set; then + with_gc="$withval"; + fi], + AC_MSG_RESULT(no)) + AC_MSG_CHECKING(for --with-sgi-dl) AC_ARG_WITH(sgi-dl, [--with-sgi-dl=DIRECTORY IRIX 4 dynamic linking], [ AC_MSG_RESULT($withval)