[Gc] Crash on startup when using delete on Win32

Boehm, Hans hans.boehm at hp.com
Wed Aug 30 11:20:49 PDT 2006


Unfortunately, I won't have time to look at this for at least another
week or so.

As a wild guess, I would speculate that this is an Intel compiler
specific issue related to ::new replacement, in which case I'm also not
well-positioned to help.  ::new replacement has always been a sore spot
since there doesn't seem to be any really portable way to do it.

Note that the C++ header file does some things differently if it detects
the Microsoft compiler.  I have no idea whether _MSC_VER is defined in
your environment, and whether those are the right things to do.  I would
look at the GC_malloc, GC_malloc_uncollectable, and GC_free calls that
are actually generated, and see if they make sense.  If they do not, I'd
appreciate the gc_cpp.h patch to fix that.

If I'm wrong, and this also fails with a recent Microsoft compiler, I
should be able to look at it once I find some time.

Hans

> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com 
> [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of Jiawen Chen
> Sent: Monday, August 28, 2006 5:14 PM
> To: gc at napali.hpl.hp.com
> Subject: [Gc] Crash on startup when using delete on Win32
> 
> Hello,
> 
> 	I recently compiled gc 6.8 on Windows, 32-bit, using 
> Visual Studio 2005 and the Intel C++ Compiler, version 
> 9.1.022.  I used the following -D flags:
> 
> _DEBUG
> SILENT
> GC_BUILD
> WIN32
> _WINDOWS
> ALL_INTERIOR_POINTERS
> __STDC__
> GC_WIN32_THREADS
> GC_OPERATOR_NEW_ARRAY
> 
> 	The gc works marvelously in pure C.  However I would 
> like to use it with C++.  It crashes horribly when I have 
> delete[] anywhere in the code.  I used the following (I was 
> benchmarking collected vs uncollected):
> 
> #include <cstdio>
> #include <ctime>
> #include "gc/gc_cpp.h"
> 
> void uncollected()
> {
> 	int nIters = 100000;
> 
> 	for( int i = 0; i < nIters; ++i )
> 	{
> 		printf( "i = %d\n", i );
> 		int* arr = new ( NoGC ) int[ 100 ]; // I also 
> tried ::new
> 		printf( "i = %d, after new\n", i );
> 		delete[] arr; // I also tried delete without the []
> 	}
> }
> 
> int main()
> {
> 	GC_INIT();
> 	printf( "Hello world!\n" );
> 	uncollected();
> }
> 
> It prints "i = 0", then "i = 0, after new" and then dies.  
> This happens with or without GC_INIT().  It doesn't crash if 
> I remove the delete[]. 
> It also worked fine when I used new ( UseGC ) without delete[]s.
> 
> It seem to die in obj_map.c, according to the debugger:
> 
> /* Add a heap block map for objects of size sz to obj_map.	*/
> /* Return FALSE on failure.					*/
> GC_bool GC_add_map_entry(sz)
> word sz;
> {
>      register unsigned obj_start;
>      register unsigned displ;
>      register map_entry_type * new_map;
>      word map_entry;
> 
>      if (sz > MAXOBJSZ) sz = 0;
>      if (GC_obj_map[sz] != 0) {
>          return(TRUE);
>      }
> 
> ////////////////////////////////////////////////////
> // the arrow of the debugger points at the next line 
> ////////////////////////////////////////////////////
> 
>      new_map = (map_entry_type *)GC_scratch_alloc(MAP_SIZE);
> 
> 
> 
> ////////////////////////////////////////////////////
> 
> Any ideas?
> 
> Many thanks,
> 
> Jiawen Chen
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> 



More information about the Gc mailing list