Discussion:
[omniORB] function and sequence
Ronald Andrae
2008-01-30 20:15:34 UTC
Permalink
Hello,

I have function, which returns a variable array (sequence).

My IDL:

typedef sequence<string> Feld;

interface Student{
Feld getEmails();
};

My implementation:

class Student_impl : public POA_Student
{
public:

Feld * getEmails() {
Feld_var temp = new Feld;
temp->length(3);
temp[0] = "***@uni.de";
temp[1] = "***@uni.de";
temp[2] = "***@uni.de";
return temp;
}
};

There is a problem with the types Feld and Feld_var. Have anyone an
idea, how i can fix this problem, so that I can use the array at the
client side?

Thanks
renny.koshy at rubixinfotech.com ()
2008-01-30 20:39:56 UTC
Permalink
I believe you should be doing a CORBA::string_dup() on each string you are
storing into a CORBA 'data structure'... I personally find CORBA's memory
management semantics a bit strange sometimes..

temp[0] = CORBA::string_dup("***@uni.de");
temp[1] = CORBA::string_dup("***@uni.de");
temp[2] = CORBA::string_dup("***@uni.de");


Renny Koshy




Ronald Andrae
<***@studser
v.uni-leipzig.de> To
Sent by: omniorb-***@omniorb-support.com
omniorb-list-boun cc
***@omniorb-suppo
rt.com Subject
[omniORB] function and sequence

01/30/2008 09:15
AM







Hello,

I have function, which returns a variable array (sequence).

My IDL:

typedef sequence<string> Feld;

interface Student{
Feld getEmails();
};

My implementation:

class Student_impl : public POA_Student
{
public:

Feld * getEmails() {
Feld_var temp = new Feld;
temp->length(3);
temp[0] = "***@uni.de";
temp[1] = "***@uni.de";
temp[2] = "***@uni.de";
return temp;
}
};

There is a problem with the types Feld and Feld_var. Have anyone an
idea, how i can fix this problem, so that I can use the array at the
client side?

Thanks
Ronald Andrae
2008-01-30 20:43:54 UTC
Permalink
Hello,

thanks for your help. But my problem is that the typ Feld_var can not be
convert to Feld*.

Thanks.
Post by renny.koshy at rubixinfotech.com ()
I believe you should be doing a CORBA::string_dup() on each string you are
storing into a CORBA 'data structure'... I personally find CORBA's memory
management semantics a bit strange sometimes..
Renny Koshy
Ronald Andrae
v.uni-leipzig.de> To
omniorb-list-boun cc
rt.com Subject
[omniORB] function and sequence
01/30/2008 09:15
AM
Hello,
I have function, which returns a variable array (sequence).
typedef sequence<string> Feld;
interface Student{
Feld getEmails();
};
class Student_impl : public POA_Student
{
Feld * getEmails() {
Feld_var temp = new Feld;
temp->length(3);
return temp;
}
};
There is a problem with the types Feld and Feld_var. Have anyone an
idea, how i can fix this problem, so that I can use the array at the
client side?
Thanks
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
evgeni.rojkov at durr.com ()
2008-01-30 21:11:37 UTC
Permalink
Here are 2 improvement suggestions.
Regards, Evgeni

// 1.
// temp[0] = "***@uni.de";
temp[0] = CORBA::string_dup("***@uni.de");

// 2.
//return temp;
return temp._retn();


-----Urspr?ngliche Nachricht-----
Von: omniorb-list-***@omniorb-support.com
[mailto:omniorb-list-***@omniorb-support.com] Im Auftrag von Ronald Andrae
Gesendet: Mittwoch, 30. Januar 2008 15:16
An: omniorb-***@omniorb-support.com
Betreff: [omniORB] function and sequence


Hello,

I have function, which returns a variable array (sequence).

My IDL:

typedef sequence<string> Feld;

interface Student{
Feld getEmails();
};

My implementation:

class Student_impl : public POA_Student
{
public:

Feld * getEmails() {
Feld_var temp = new Feld;
temp->length(3);
temp[0] = "***@uni.de";
temp[1] = "***@uni.de";
temp[2] = "***@uni.de";
return temp;
}
};

There is a problem with the types Feld and Feld_var. Have anyone an
idea, how i can fix this problem, so that I can use the array at the
client side?

Thanks
Ronald Andrae
2008-01-30 21:49:09 UTC
Permalink
Hello,

thanks, you have fixed my problem. :-)
Post by evgeni.rojkov at durr.com ()
Here are 2 improvement suggestions.
Regards, Evgeni
// 1.
// 2.
//return temp;
return temp._retn();
-----Urspr?ngliche Nachricht-----
Gesendet: Mittwoch, 30. Januar 2008 15:16
Betreff: [omniORB] function and sequence
Hello,
I have function, which returns a variable array (sequence).
typedef sequence<string> Feld;
interface Student{
Feld getEmails();
};
class Student_impl : public POA_Student
{
Feld * getEmails() {
Feld_var temp = new Feld;
temp->length(3);
return temp;
}
};
There is a problem with the types Feld and Feld_var. Have anyone an
idea, how i can fix this problem, so that I can use the array at the
client side?
Thanks
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
DA SILVA Antonio
2008-01-30 22:33:49 UTC
Permalink
Hi Ronald,

You can use also for the strings :
temp[0] = ( const char * )"***@uni.de";

Evgni, what about reference counting
with the "_retn( )"?

Antonio.
Post by Ronald Andrae
Hello,
thanks, you have fixed my problem. :-)
Post by evgeni.rojkov at durr.com ()
Here are 2 improvement suggestions.
Regards, Evgeni
// 1.
// 2.
//return temp;
return temp._retn();
-----Urspr?ngliche Nachricht-----
Gesendet: Mittwoch, 30. Januar 2008 15:16
Betreff: [omniORB] function and sequence
Hello,
I have function, which returns a variable array (sequence).
typedef sequence<string> Feld;
interface Student{
Feld getEmails();
};
class Student_impl : public POA_Student
{
Feld * getEmails() {
Feld_var temp = new Feld;
temp->length(3);
return temp;
}
};
There is a problem with the types Feld and Feld_var. Have anyone an
idea, how i can fix this problem, so that I can use the array at the
client side?
Thanks
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
evgeni.rojkov at durr.com ()
2008-01-31 19:13:20 UTC
Permalink
Yes, both operator=(const char*) and CORBA::string_dup() will work correctly
here. I would prefer CORBA::string_dup() to avoid disaster if "const" is missing
and just "char*" used.
Evgeni, what about reference counting
with the "_retn( )"?
Here is the code we are talking about:
{
Feld_var temp = new Feld;
....
return temp._retn();
}
Immediately after "return ...;" temp goes out of scope.
Without "temp._retn();", "delete temp.pd_data;" will be called in
temp-destructor, so we would have nothing valid to return. Are there any other
ways except "._retn();" here ?

Kind Regards,
Evgeni


-----Urspr?ngliche Nachricht-----
Von: omniorb-list-***@omniorb-support.com
[mailto:omniorb-list-***@omniorb-support.com] Im Auftrag von DA SILVA
Antonio
Gesendet: Mittwoch, 30. Januar 2008 17:34
An: omniorb-***@omniorb-support.com
Betreff: Re: [omniORB] function and sequence




Hi Ronald,

You can use also for the strings :
temp[0] = ( const char * )"***@uni.de";

Evgni, what about reference counting
with the "_retn( )"?

Antonio.
Hello,
thanks, you have fixed my problem. :-)
Post by evgeni.rojkov at durr.com ()
Here are 2 improvement suggestions.
Regards, Evgeni
// 1.
// 2.
//return temp;
return temp._retn();
-----Urspr?ngliche Nachricht-----
Ronald Andrae
Gesendet: Mittwoch, 30. Januar 2008 15:16
Betreff: [omniORB] function and sequence
Hello,
I have function, which returns a variable array (sequence).
typedef sequence<string> Feld;
interface Student{
Feld getEmails();
};
class Student_impl : public POA_Student
{
Feld * getEmails() {
Feld_var temp = new Feld;
temp->length(3);
return temp;
}
};
There is a problem with the types Feld and Feld_var. Have anyone an
idea, how i can fix this problem, so that I can use the array at the
client side?
Thanks
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
DA SILVA Antonio
2008-01-31 20:05:14 UTC
Permalink
...temp-destructor, so we would have nothing valid to return. Are there any other
ways except "._retn();" here ?
I think there is no other way, in fact the "retn( )" detach the internal
pointer from the "var" reference-counting-pointer
and return it to the caller, the caller has the reponsability to destroy
the object.

Antonio.
Yes, both operator=(const char*) and CORBA::string_dup() will work correctly
here. I would prefer CORBA::string_dup() to avoid disaster if "const" is missing
and just "char*" used.
Evgeni, what about reference counting
with the "_retn( )"?
{
Feld_var temp = new Feld;
....
return temp._retn();
}
Immediately after "return ...;" temp goes out of scope.
Without "temp._retn();", "delete temp.pd_data;" will be called in
temp-destructor, so we would have nothing valid to return. Are there any other
ways except "._retn();" here ?
Kind Regards,
Evgeni
-----Urspr?ngliche Nachricht-----
Antonio
Gesendet: Mittwoch, 30. Januar 2008 17:34
Betreff: Re: [omniORB] function and sequence
Hi Ronald,
Evgni, what about reference counting
with the "_retn( )"?
Antonio.
Hello,
thanks, you have fixed my problem. :-)
Post by evgeni.rojkov at durr.com ()
Here are 2 improvement suggestions.
Regards, Evgeni
// 1.
// 2.
//return temp;
return temp._retn();
-----Urspr?ngliche Nachricht-----
Ronald Andrae
Gesendet: Mittwoch, 30. Januar 2008 15:16
Betreff: [omniORB] function and sequence
Hello,
I have function, which returns a variable array (sequence).
typedef sequence<string> Feld;
interface Student{
Feld getEmails();
};
class Student_impl : public POA_Student
{
Feld * getEmails() {
Feld_var temp = new Feld;
temp->length(3);
return temp;
}
};
There is a problem with the types Feld and Feld_var. Have anyone an
idea, how i can fix this problem, so that I can use the array at the
client side?
Thanks
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
--
_________________________
Antonio DA SILVA
C A R A X IT Department
Software Engineer
11 bis rue d'Aguesseau
75008 Paris, FRANCE
Tel +33 (0)1 70 91 67 94
_________________________
Clarke Brunt
2008-01-31 22:46:46 UTC
Permalink
Post by DA SILVA Antonio
...temp-destructor, so we would have nothing valid to return. Are
there any other ways except "._retn();" here ?
I think there is no other way, in fact the "retn( )" detach the
internal pointer from the "var" reference-counting-pointer
and return it to the caller, the caller has the reponsability to
destroy the object.
Of course, you could not use the _var at all, i.e.

Feld *pFeld = new Feld;
.... // fill in the sequence
return pFeld;

But of course, this is susceptible to failing to destroy the Feld if an
exception is thrown. Hence the var type, which is designed to help with
this.

Or you could return a _copy_ of the sequence, so that it doesn't matter
when the _var self-destructs:

Feld_var temp = new Feld;
....
return new Feld(temp.in()); // I think - not tried compiling this

But it's wasteful making a copy, and doesn't look nice.

Much better to use the var as intended, and the _retn().

Clarke Brunt
TRAFFICMASTER PLC
UNIT 22 / ST. JOHN'S INNOVATION CENTRE
COWLEY ROAD / CAMBRIDGE / CB4 0WS
T: 01223 422469
F:
E: ***@trafficmaster.co.uk


Please consider the environment before printing this email. --------------------------------------------------------

Trafficmaster PLC is a limited Company registered in England and Wales.
Registered number: 2292714 Registered office: Martell House, University Way, Cranfield, BEDS. MK43 0TR

This message (and any associated files) is intended only for the use of omniorb-***@omniorb-support.com and may contain information that is confidential, subject to copyright or constitutes a trade secret. If you are not omniorb-***@omniorb-support.com you are hereby notified that any dissemination, copying or distribution of this message, or files associated with this message, is strictly prohibited. If you have received this message in error, please notify us immediately by replying to the message and deleting it from your computer. Any views or opinions presented are solely those of the author ***@trafficmaster.co.uk and do not necessarily represent those of the company.

Warning: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.
--------------------------------------------------------

Continue reading on narkive:
Loading...