libstdc++/5492: basic_string seems to fail to use template-defined allocator.
bkoz@gcc.gnu.org
bkoz@gcc.gnu.org
Sat Apr 20 23:59:00 GMT 2002
Synopsis: basic_string seems to fail to use template-defined allocator.
State-Changed-From-To: analyzed->feedback
State-Changed-By: bkoz
State-Changed-When: Sat Apr 20 16:55:25 2002
State-Changed-Why:
I don't think this is a bug.
Here's a testcase:
#include "post_stl.h"
#include <iostream>
#include <sstream>
#include <vector>
#include <exception>
#include <stdio.h>
using namespace std;
storage* sto;
struct A
{
pstring msg;
double num;
short pad[5];
A(const char* s, streamsize len, double d) : msg(s, len), num(d) { }
virtual
~A() { }
virtual string
getInfo()
{
ostringstream out;
out << "class type 'A'" << endl;
out << "msg object address = " << (void*)(&msg) << endl;
out << "msg data address = " << (void*)(msg.data()) << endl;
out << "msg = '" << msg.c_str() << "'" << endl;
out << "num = '" << num << "'" << endl;
return out.str();
}
};
typedef vector<A*, post_alloc<A*> > A_vector;
int main()
{
sto = new storage("stringtest.odb");
if (sto->open(storage::fixed))
{
A_vector *root = (A_vector*)sto->get_root_object();
if (root != NULL)
{
cout << "Existing database found at " << root << endl;
for (A_vector::iterator i = root->begin(); i != root->end(); i++)
{
cout << "object found at " << *i << ":" << endl;
cout << (*i)->getInfo();
}
}
else
{
root = new (*sto) A_vector;
cout << "Creating database at " << root << endl;
sto->set_root_object((object*)root);
}
cout << endl;
cout << "Add some lines. Terminate input with empty line." << endl;
while (cin.good())
{
char buf[256];
cin.getline(buf, 256);
streamsize len = cin.gcount() - 1;
if (!len)
{
cout << "done." << endl;
sto->flush();
sto->close();
return EXIT_SUCCESS;
}
else
{
A* a = new (*sto) A(buf, len, 44.5);
cout << "created new A object at " << a << endl;
cout << a->getInfo() << endl;
root->push_back(a);
}
}
}
else
{
cerr << "Failed to open storage" << endl;
return EXIT_FAILURE;
}
}
Gives:
%a.out
Creating database at 0x400005ac
Add some lines. Terminate input with empty line.
this is a test
created new A object at 0x4000060c
class type 'A'
msg object address = 0x40000610
msg data address = 0x81344dc
msg = 'this is a test'
num = '44.5'
And then re-running the binary:
%a.out
Existing database found at 0x400005ac
object found at 0x4000060c:
class type 'A'
msg object address = 0x40000610
msg data address = 0x81344dc
msg = ''
num = '44.5'
It looks like
1) find_storage in storage.h, line 248
has problems finding a block for std::string because sizeof(string) != sizeof(string) + sizeof(string::_Rep)
2) allocate, post_stl.h line 92:
ends up using malloc to get storage.
The results are obvious from the above output.
I think this is an error with the POST++ allocation strategy, or else I'm not configuring it to work correctly.
Thoughts?
-benjamin
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5492
More information about the Gcc-bugs
mailing list