[omniORB] string intialization
Dominic Chorafakis XE41 ext. 9049
chorafad@access.bel.alcatel.be
Thu, 18 Jun 1998 12:09:42 +0200
Hi,
I have a question about the implementation of the
class String_member.
If I define: typedef sequence?string> MySeq;
and in a client I do:
{
MySeq s;
s.length(1);
s[0] = "Hello";
...
}
the compiler (GNU) interpretes "Hello" as a char *
(not const char *).
As a result, the String_member assignment operator
in CORBA.h
line 213 is invoked:
inline String_member? operator= (char *s) {
if (_ptr) {
string_free(_ptr);
_ptr = 0;
}
_ptr = s;
return *this;
}
When the variable "MySeq s" goes out of scope,
the destructor of String_member
invokes string_free to deallocate _ptr , which
should not be done.
The problem is solved by doing s[0] = (const char
*)"Hello", which actually
allocates a buffer for _ptr and copies the string.
Is it intentional that the above assignment
operator just copies the pointer ? If so,
should the class String_member not call
string_free ONLY if it has allocated _ptr
by a call to string_alloc ?
Sorry if this topic is already covered in the
mailing archive but I have some
problems searching it.
Thanks in advance.
Regards,
Dominic Chorafakis