sizeof() segfault and mutex initialization?

Stefan Olsson stefan@snon.net
Thu Feb 20 09:11:00 GMT 2003


Benjamin Kosnik wrote:

>>_S_thread_freelist_mutex = (__gthread_mutex_t*)malloc (sizeof 
>>(__gthread_mutex_t));
>>
>>It's possible to do sizeof on structs defined inside the template class, 
>>but not on for instance int or - what we really want to do - 
>>__gthread_mutex_t. This seems to be the PR7112. Any work arounds?
>>    
>>
>
>Is __gthread_mutex_t a forward declaration or well defined at this point?
>Does the size of __gthread_mutex_t change at any point? If not, do you
>need to do this inside a templatized class?
>
>7112 is fixed in mainline. If you are having problems, I suggest, as a
>first step, posting a small, self-contained test case.
>
>Again, think small.
>
I'll try :) Here's a small diff against CVS version of stl_alloc which 
adds a malloc (sizeof ()) call to one of __pool_alloc's methods:

Index: stl_alloc.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/stl_alloc.h,v
retrieving revision 1.31
diff -r1.31 stl_alloc.h
423a424,426
 >       void* foo;
 >       foo = malloc (sizeof (int));
 >

Here's the "testapplication" used:
#include <vector>

using namespace std;

int main()
{
  vector<int> v1;

  v1.push_back (1);

  return 0;
}

This causes an internal compiler error: stl_alloc.h:425: internal 
compiler error: Segmentation fault

For reference, the compiler used is:
Reading specs from 
/root/projects/alloc/local/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs
Configured with: ../gcc/configure --prefix=/root/projects/alloc/local 
--enable-threads
Thread model: posix
gcc version 3.4 20030202 (experimental)

What am I missing here?

Brgds

/Stefan

-- 
Experience is what you get when you were expecting something else.




More information about the Libstdc++ mailing list