[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fltk, oct files, and windows

From: John W. Eaton
Subject: Re: fltk, oct files, and windows
Date: Tue, 4 Oct 2005 13:26:47 -0400

On  3-Oct-2005, James R. Phillips wrote:

| I have been unable to produce a working version of 2.1.71 using gcc 3.4.4 on
| cygwin.

I tried debugging the problem with Octave vs. gcc 3.4.x on Cygwin and
was unable to find a solution.  But I did find that compliling a
completely static versoin of Octave avoided the bug.  I would bet that
the problem described by the message below is the source of the
trouble for Octave on Cygwin with gcc 3.4.x.


------- start of forwarded message -------
From: Pavel Tsekov <address@hidden>
To: address@hidden
Subject: ATTN: g++ maintainer: Using string instances to pass arguments to  dlls
Date: Tue, 4 Oct 2005 18:03:22 +0300

Content-Type: TEXT/PLAIN; charset=US-ASCII


I noticed the following problem while porting an internal C++ application
from linux to Cygwin. If a std::string instance created in one module
(exe or dll) is passed to another say as an argument of a function call,
the program crashes or hangs. I did debug for a while and it turned
out that it is not the program itself that causes the crash - the cause
lies in the std::string implementation, the fact that libstdc++ is
provided as a static archive and that it is compiled without

What happens is that each module which links agains libstdc++ get its very
personal copy of the class member _S_empty_rep_storage. Now since
_GLIBCXX_FULLY_DYNAMIC_STRING is not defined an empty string instance i.e.
one that is created by the default constructor of std::string gets a
pointer to _S_empty_rep_storage i.e. the actual allocation of memory is
delayed until memory is really needed. If _GLIBCXX_FULLY_DYNAMIC_STRING is
defined each string instance would get a pointer to a newly heap
allocated block of memory instead . Now look at the ouput of gdb and nm
used on the attached testcase:

address@hidden ~/src/testcase/tc
$ nm dll.dll | grep _S_empty_rep_storage
1000c030 d .data$_ZNSs4_Rep20_S_empty_rep_storageE
1000c030 D __ZNSs4_Rep20_S_empty_rep_storageE

address@hidden ~/src/testcase/tc
$ nm main.exe | grep _S_empty_rep_storage
00442120 d .data$_ZNSs4_Rep20_S_empty_rep_storageE
00442120 D __ZNSs4_Rep20_S_empty_rep_storageE

Breakpoint 1, main (argc=1, argv=0x10042980) at
9       {
(gdb) n
10        string s, s1;
12        export1 (s);
(gdb) print s
$1 = {static npos = 4294967295, _M_dataplus = {<allocator<char>> =
{<new_allocator<char>> = {<No data fields>}, <No data fields>},
    _M_p = 0x44212c ""}}
(gdb) print s1
$2 = {static npos = 4294967295, _M_dataplus = {<allocator<char>> =
{<new_allocator<char>> = {<No data fields>}, <No data fields>},
    _M_p = 0x44212c ""}}

Here the two strings share _S_empty_rep_storage.

(gdb) step
export1 (address@hidden) at
7         string s1;
(gdb) n
9         s1.push_back ('A');
(gdb) n
10        s.push_back ('A');
(gdb) print s
$3 = (string &) @0x22eea0: {static npos = 4294967295,
  _M_dataplus = {<allocator<char>> = {<new_allocator<char>> = {<No data
fields>}, <No data fields>}, _M_p = 0x44212c ""}}
(gdb) print s1
$4 = {static npos = 4294967295, _M_dataplus = {<allocator<char>> =
{<new_allocator<char>> = {<No data fields>}, <No data fields>},
    _M_p = 0x10042aec "A"}}

Here s1 points to the dll local _S_empty_rep_storage.

The _M_p member of _M_dataplus is pointing to different copies of
_S_empty_rep_storage - one stored in the executable which calls the dll
and another one in the dll itself.

Now the second push_back() call in export1 () will end up calling
_M_mutate() to actually allocate storage. _M_mutate() will call
_M_rep()->_M_dispose() which will end up free()-ing the memory reserved
for _S_empty_rep_storage in the main exe. There is a check to prevent free()-ing

          if (__builtin_expect(this != &_S_empty_rep(), false))

... but it doesn't work well in the case when a string instance created
in one module is passed to another and libstdc++ is statically linked
because of the fact that each module has its own copy

Can we get this fixed ?

Content-Type: APPLICATION/octet-stream; name="dllstr.tar.bz2"
Content-Transfer-Encoding: BASE64
Content-ID: <address@hidden>
Content-Disposition: attachment; filename="dllstr.tar.bz2"


Content-Type: text/plain; charset=us-ascii

Unsubscribe info:
Problem reports:
------- end of forwarded message -------

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]