Discussion:
[omniORB] My program crashes when I try to dereference an object from a sequence
Lane, Frank L
2008-10-28 02:31:40 UTC
Permalink
Hi,

My program is crashing and I don't understand why, will someone please
tell me what I'm doing wrong?
Visual Studio 2008, XP, OmniORB 4.1.3

I printed out the addresses and the address of the sequence element is
the same as that of the CORBA object just created. Whenever I try to
use the sequence element my program crashes. BTW, here's what the screen
says followed by the relevant code listing.

<BEGIN SCREEN OUTPUT>

C:\Personal\Examples\ch5n6Home>sharedServer.exe
IOR:010000001800000049444c3a506f7274666f6c696f42726f6b65723a312e30000100
00000000
000064000000010102000e0000003133302e3132322e34322e35360028080e000000fe3d
32064900
000ba4000000000000000200000000000000080000000100000000545441010000001c00
00000100
0000010001000100000001000105090101000100000009010100
Upcall with name: a, account: 7
Trying to find: 7
Size: 0
Creating new customer, name: a, account: 7
New customer created, a, 7
_Customers[0]: 0036F738
TheCustomer: 0036F738
TheCustomer data, a, 7
omniORB: Assertion failed. This indicates a bug in the application
using omniORB, or maybe in omniORB itself.
file: current.cc
line: 141
info: !pd_callDescriptor

<END SCREEN OUTPUT>



<BEGIN SERVANT LISTING>

Customer_ptr
PortfolioBroker_impl::MakeCustomer
(const char * CustomerName, const char * CustomerAccount)
{
cout << "Upcall with name: " << CustomerName
<< ", account: " << CustomerAccount << endl;

Customer_var dup = FindCustomer (CustomerAccount);

if (!CORBA::is_nil(dup)) {
cout << "Bombing out" << endl;
throw PortfolioBroker::DuplicateCustomer (dup->Name());
}
else {
cout << "Creating new customer"
", name: " << CustomerName << ", account: " << CustomerAccount
<< endl;
}

Customer_impl * TheCustomer
= new Customer_impl (CustomerName, CustomerAccount);

cout << "New customer created, " << TheCustomer->Name()
<< ", " << TheCustomer->Account() << endl;

CORBA::Long size = _Customers.length();
_Customers.length(size+1);
_Customers[size] = (Customer_ptr)TheCustomer;

if (CORBA::is_nil(_Customers[0]))
cout << "The newly created seq member is nil?" << endl;
else {
cout << "_Customers[0]: " << _Customers[0] << endl;
cout << "TheCustomer: " << TheCustomer << endl;
cout << "TheCustomer data, " << TheCustomer->Name()
<< ", " << TheCustomer->Account() << endl;

!!!!! ----- Here is where it is crashing -----!!!!!!
!!!!! ----- The instant I try to get data back out of the sequence it
crashes ----- !!!!!!!


Customer_var temp = (Customer_ptr)_Customers[0];
cout << "The sequence data, " << temp->Name()
<< ", " << (*temp).Account() << endl;
//cout << "New customer created, " << _Customers[0]->Name() <<
endl;
}


return Customer::_duplicate((Customer_ptr)TheCustomer);

}// end MakeCustomer ()

<END SERVANT LISTING>

Any help will be greatly appreciated!

Thanks,
Frank
Martin Trappel
2008-10-28 15:16:30 UTC
Permalink
Post by Lane, Frank L
Hi,
My program is crashing and I don't understand why, will someone please
tell me what I'm doing wrong?
Visual Studio 2008, XP, OmniORB 4.1.3
(...)
Customer_impl * TheCustomer
= new Customer_impl (CustomerName, CustomerAccount);
cout << "New customer created, " << TheCustomer->Name()
<< ", " << TheCustomer->Account() << endl;
CORBA::Long size = _Customers.length();
_Customers.length(size+1);
_Customers[size] = (Customer_ptr)TheCustomer;
Never, ever use c-style casts.
What you probably wanted to do was:
_Customers[size] = TheCustomer->_this();
Post by Lane, Frank L
if (CORBA::is_nil(_Customers[0]))
cout << "The newly created seq member is nil?" << endl;
else {
cout << "_Customers[0]: " << _Customers[0] << endl;
cout << "TheCustomer: " << TheCustomer << endl;
cout << "TheCustomer data, " << TheCustomer->Name()
<< ", " << TheCustomer->Account() << endl;
You are aware that the calls on TheCustomer are direct calls on the
implementation object, and won't involve any CORBA?
Post by Lane, Frank L
!!!!! ----- Here is where it is crashing -----!!!!!!
!!!!! ----- The instant I try to get data back out of the sequence it
crashes ----- !!!!!!!
Customer_var temp = (Customer_ptr)_Customers[0];
Never, ever use c-style casts.
You should use a _ptr type for the temp or duplicate() the sequence element!
Post by Lane, Frank L
cout << "The sequence data, " << temp->Name()
<< ", " << (*temp).Account() << endl;
//cout << "New customer created, " << _Customers[0]->Name() <<
endl;
}
return Customer::_duplicate((Customer_ptr)TheCustomer);
Never, ever use c-style casts.


1) Look at the omniORB examples. example #1 will show you how to
correctly instantiate and the use an object.

2) After looking at the examples, get "Adavced CORBA programming with
C++" by Henning,Vinoski


br,
Martin
Lane, Frank L
2008-10-28 22:38:11 UTC
Permalink
Hi,

Firstly, Martin, thank you!

I'm going to go over the examples better, and look into Messrs. Henning
and Vinoski tome (it's humongous).

I notice that most of what you talk about on this list are 'advanced'
topics. However, with that in mind, as a beginner I have no option
other than ask beginner questions.

If no one answers it won't hurt my feelings and I do appreciate it
should anyone deign to favor me with a response. Martin really pulled
my irons out of the fire. In my own mind my biggest problem is getting
my head wrapped around the terminology.

In code layman's terms, what is the difference between <interface>_impl
* and <interface>_ptr? They are related, I'm hoping? They are
obviously not as interchangeable as I'd imagined.

Based on Martin's response I'm assuming <interface>_impl * is known as
an object implementation?

Is <interface>_ptr what is referred to in omni documentation as an
"object reference"?

Double thank you to Martin because I was unaware that the call on
'TheCustomer' didn't involve CORBA.

Thank You For Your Time,
Frank

-------------------

Date: Tue, 28 Oct 2008 11:15:56 +0100
From: Martin Trappel <***@gmx.at>
Subject: Re: [omniORB] My program crashes when I try to dereference an
object from a sequence
To: omniorb-***@omniorb-support.com
Message-ID: <***@gmx.at>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Post by Lane, Frank L
Hi,
My program is crashing and I don't understand why, will someone please
tell me what I'm doing wrong?
Visual Studio 2008, XP, OmniORB 4.1.3
(...)
Customer_impl * TheCustomer
= new Customer_impl (CustomerName, CustomerAccount);
cout << "New customer created, " << TheCustomer->Name()
<< ", " << TheCustomer->Account() << endl;
CORBA::Long size = _Customers.length();
_Customers.length(size+1);
_Customers[size] = (Customer_ptr)TheCustomer;
Never, ever use c-style casts.
What you probably wanted to do was:
_Customers[size] = TheCustomer->_this();
Post by Lane, Frank L
if (CORBA::is_nil(_Customers[0]))
cout << "The newly created seq member is nil?" << endl;
else {
cout << "_Customers[0]: " << _Customers[0] << endl;
cout << "TheCustomer: " << TheCustomer << endl;
cout << "TheCustomer data, " << TheCustomer->Name()
<< ", " << TheCustomer->Account() << endl;
You are aware that the calls on TheCustomer are direct calls on the
implementation object, and won't involve any CORBA?
Post by Lane, Frank L
!!!!! ----- Here is where it is crashing -----!!!!!!
!!!!! ----- The instant I try to get data back out of the sequence it
crashes ----- !!!!!!!
Customer_var temp = (Customer_ptr)_Customers[0];
Never, ever use c-style casts.
You should use a _ptr type for the temp or duplicate() the sequence
element!
Post by Lane, Frank L
cout << "The sequence data, " << temp->Name()
<< ", " << (*temp).Account() << endl;
//cout << "New customer created, " << _Customers[0]->Name() <<
endl;
}
return Customer::_duplicate((Customer_ptr)TheCustomer);
Never, ever use c-style casts.


1) Look at the omniORB examples. example #1 will show you how to
correctly instantiate and the use an object.

2) After looking at the examples, get "Adavced CORBA programming with
C++" by Henning,Vinoski


br,
Martin


------------------------------

_______________________________________________
omniORB-list mailing list
omniORB-***@omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list


End of omniORB-list Digest, Vol 66, Issue 17
********************************************
Martin Trappel
2008-10-29 13:30:23 UTC
Permalink
Post by Lane, Frank L
...
I'm going to go over the examples better, and look into Messrs. Henning
and Vinoski tome (it's humongous).
I notice that most of what you talk about on this list are 'advanced'
topics. However, with that in mind, as a beginner I have no option
other than ask beginner questions.
Some of your beginners questions should be clarified by Ch2 and Ch3 of
this book.
Also - you might want to check out JAVA/CORBA Tutorials on the web as
they are more numerous and should be able to teach you the corba basics.
(And they have the benefit of not cluttering up the CORBA basics with
C++ memory management. :) )
Post by Lane, Frank L
...
In code layman's terms, what is the difference between <interface>_impl
* and <interface>_ptr? They are related, I'm hoping? They are
obviously not as interchangeable as I'd imagined.
The _impl classes (they can be aribtrarily named, "_impl" is just
something that's used often) are the (C++) implementation of a given
CORBA IDL interface. They are "related" insofar as you are able to get a
_ptr type from your _impl type (_this()) - but there is no other (C++)
relationship btw them.
Post by Lane, Frank L
Based on Martin's response I'm assuming <interface>_impl * is known as
an object implementation?
Is <interface>_ptr what is referred to in omni documentation as an
"object reference"?
I guess so. Note that a _var type is just a smart pointer type for _ptr.
So either a _var or a _ptr can be an object reference.

br,
Martin

Loading...