Discussion:
[omniORB] Deletect failed allocation to a _var
EXT-Pennington, Dale K
2008-06-04 23:47:57 UTC
Permalink
I am doing a port of code from one OS/compiler/ORB to a different
OS/compiler/ORB (destination ORB being omniORB).

At one point of the code, they are performing as assert check to make
sure that a new operation succeeded. The code :

CosNaming::Name_var compound_name = new CosNaming::Name(count);
assert(compound_var != 0);

My compiler has issues on the assert, saying it has not != operation.
Looking at the Naming.hh header file I can understand this, as what is
really needed is to check if the internal reference pointer is NULL. How
they got this to work on their other system I do not know. It was either
an ORB specific extension, or a compiler quirk.

So the question. How would I check to confirm that the new worked
successfully. I guess maybe something with operator ->, but I am not
experienced enough in that part of C++ to see how.

Thanks,
Dale Pennington
Igor Lautar
2008-06-05 00:36:13 UTC
Permalink
Hi,

Doesn't new throw std::bad_alloc in case it cannot allocate mem?
Of course, only if exceptions are enabled.

You could also probably use CORBA::is_nil().

Regards,
Igor
Post by EXT-Pennington, Dale K
I am doing a port of code from one OS/compiler/ORB to a different
OS/compiler/ORB (destination ORB being omniORB).
At one point of the code, they are performing as assert check to make
CosNaming::Name_var compound_name = new CosNaming::Name(count);
assert(compound_var != 0);
My compiler has issues on the assert, saying it has not != operation.
Looking at the Naming.hh header file I can understand this, as what is
really needed is to check if the internal reference pointer is NULL.
How they got this to work on their other system I do not know. It was
either an ORB specific extension, or a compiler quirk.
So the question. How would I check to confirm that the new worked
successfully. I guess maybe something with operator ->, but I am not
experienced enough in that part of C++ to see how.
Thanks,
Dale Pennington
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
Clarke Brunt
2008-06-05 18:21:51 UTC
Permalink
Post by EXT-Pennington, Dale K
At one point of the code, they are performing as assert check to make
CosNaming::Name_var compound_name = new CosNaming::Name(count);
assert(compound_var != 0);
...
So the question. How would I check to confirm that the new worked
successfully. I guess maybe something with operator ->, but I am not
experienced enough in that part of C++ to see how.
As someone has already said, if 'new' itself throws an exception, then maybe
this isn't relevant. But I've wanted to check in programs whether or not a
var has been 'filled in' or not.

I half-recall the spec. saying that one mustn't 'use' vars before allocating
something to them, but anyway, the way with operator-> is simply:

assert(compound_var.operator->() != 0)

I don't think CORBA::is_nil() is any good - isn't that only for object
references?
--
Clarke Brunt
EXT-Pennington, Dale K
2008-06-05 19:38:12 UTC
Permalink
I recalled the same thing on CORBA::is_nil(), but your option at least
passed the compiler test.
Thanks
-----Original Message-----
Sent: Thursday, June 05, 2008 7:22 AM
Subject: RE: [omniORB] Deletect failed allocation to a _var
Post by EXT-Pennington, Dale K
At one point of the code, they are performing as assert
check to make
Post by EXT-Pennington, Dale K
CosNaming::Name_var compound_name = new CosNaming::Name(count);
assert(compound_var != 0); ...
So the question. How would I check to confirm that the new worked
successfully. I guess maybe something with operator ->, but
I am not
Post by EXT-Pennington, Dale K
experienced enough in that part of C++ to see how.
As someone has already said, if 'new' itself throws an
exception, then maybe this isn't relevant. But I've wanted to
check in programs whether or not a var has been 'filled in' or not.
I half-recall the spec. saying that one mustn't 'use' vars
before allocating something to them, but anyway, the way with
assert(compound_var.operator->() != 0)
I don't think CORBA::is_nil() is any good - isn't that only
for object references?
--
Clarke Brunt
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
Loading...