473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C++ nothrow new() problem under Irix

I am trying to use nothrow new() and am encountering what seems
to be a bug in the SGI/Irix C++ environment. The following
program runs OK under Solaris and Linux, but dumps core at the
delete[] statement under Irix. Is this really an SGI implementation bug,
or have I done something stupid? (Other than trying to use nothrow
new(), that is ;-) )

#include <new>
#include <stdexcept>

std::nothrow_t NoThrow;

class Junk {
public:
Junk();
~Junk();
};

Junk::Junk() {
(void) fprintf(stderr, "constr\n"); (void) fflush(stderr);
}

Junk::~Junk() {
(void) fprintf(stderr, "destr\n"); (void) fflush(stderr);
}

main() {
Junk *jnk;

if ((jnk= new(NoThrow) Junk[5]) == (Junk *) 0) {
(void) fprintf(stderr, "memory allocation error\n");
exit(-1);
}

delete[] jnk;
}

My debugger stack looks like this:

_kill()
_raise()
abort()
_array_pointer_not_from_vec_new()
__array_delete_general2()
__vec_delete2()
main() <---- stopped on the delete[] statement

If I use regular new() instead, i.e.,

jnk= new Junk[5];

then the delete[] works OK under Irix. Do I need to be using some
special form of delete[] to indicate that the new() was called with
nothrow? I have seen no documentation anywhere that indicates that
I should, but maybe I am not looking in the right places.

I also tried

float *f;

f= new(NoThrow) float[100];
delete[] f;

under Irix and that works OK. The problem seems to occur only when
using delete[] on a non-primitive.

Thanks!
--
Roger Davis
University of Hawaii/SOEST
rb*@NoSpamHere.hawaii.edu
Jul 23 '05 #1
3 2445
In article <cv**********@news.hawaii.edu>,
Roger Davis <rb*@planet10.soest.hawaii.edu> wrote:
I am trying to use nothrow new() and am encountering what seems
to be a bug in the SGI/Irix C++ environment. The following


This is the subject of bug-id 862202.
(We added your report to that bug.)

Latest EDG front ends give a warning message about this
source code of yours, but we are not yet sure if this
warning is real or simply a mistaken (on our part)
integration of EDG front-end source.

I'm not a C++ language lawyer, but if I had to guess I'd guess
this is likely our bug, either in our runtime or our integration
of the EDG front end.

Sorry.
David Anderson [Not an official SGI spokesperson...]
PS: google 'nothrow new' to find the gotw (Guru Of
The Week) notes on nothrow. Before you use it too much :-)

PPS: IRIX CC has -LANG:exceptions=OFF to turn C++
into an older-style (before exceptions) so new returns 0
on failure. In IRIX virtual swap (like in Linux)
can mean malloc will succeed apparently but reference to
the memory can fail (Irrelevant Historical note: IRIX created
virtual swap before Linux had the concept).
Jul 23 '05 #2
In article <cv**********@news.hawaii.edu>,
Roger Davis <rb*@planet10.soest.hawaii.edu> wrote:
I am trying to use nothrow new() and am encountering what seems
to be a bug in the SGI/Irix C++ environment. The following
program runs OK under Solaris and Linux, but dumps core at the
delete[] statement under Irix. Is this really an SGI implementation bug,
or have I done something stupid? (Other than trying to use nothrow
new(), that is ;-) )

#include <new>
#include <stdexcept>

std::nothrow_t NoThrow;

class Junk {
public:
Junk();
~Junk();
};

Junk::Junk() {
(void) fprintf(stderr, "constr\n"); (void) fflush(stderr);
}

Junk::~Junk() {
(void) fprintf(stderr, "destr\n"); (void) fflush(stderr);
}

main() {
Junk *jnk;

if ((jnk= new(NoThrow) Junk[5]) == (Junk *) 0) {
(void) fprintf(stderr, "memory allocation error\n");
exit(-1);
}

delete[] jnk;
}

My debugger stack looks like this:

_kill()
_raise()
abort()
_array_pointer_not_from_vec_new()
__array_delete_general2()
__vec_delete2()
main() <---- stopped on the delete[] statement

If I use regular new() instead, i.e.,

jnk= new Junk[5];

then the delete[] works OK under Irix. Do I need to be using some
special form of delete[] to indicate that the new() was called with
nothrow? I have seen no documentation anywhere that indicates that
I should, but maybe I am not looking in the right places.

I also tried

float *f;

f= new(NoThrow) float[100];
delete[] f;

under Irix and that works OK. The problem seems to occur only when
using delete[] on a non-primitive.


This may be an issue with unsupported placement array new on
an older compiler.

Please provide the compiler/linker versions, and the c++_eoe
and compiler_eoe versions, and the compile/link command.

And the IRIX OS version (just because).

Joe
--
------------------------------------------------------------------------
Joseph Michaud - SGI Apps Eng 978-562-8894 x483-8894 jm******@sgi.com
Jul 23 '05 #3
> Please provide the compiler/linker versions, and the c++_eoe
and compiler_eoe versions, and the compile/link command.
% CC -version
MIPSpro Compilers: Version 7.3.1.3m

% ld -V
ld32: INFO 153: Version 7.30.

c++_eoe 7.3.1.3m
compiler_eoe 7.3.1.3m

% CC -o junk -g junk.cc
% ./junk
constr
constr
constr
constr
constr
Abort (core dumped)
And the IRIX OS version (just because).


eoe IRIX Execution Environment, 6.5.16m

(Thanks for looking into this, Joe.)
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marc Poinot | last post by:
Hi, I'm trying to add a dynamic module using MPI on a 2.3.4 Python with threads (posix). The interpreter blocks into the dlopen (dynload_shlib.c) if any reference to the IRIX libmpi.so (actually...
0
by: Andrea M. Segovia | last post by:
I just compiled (but did not install) perl 5.8.0 on an SGI Origin 300 server (IP35) running IRIX 6.5.20m. Make test reported one test error, which I narrowed down to .../lib/ExUtils/t/Constant.t...
4
by: Dave | last post by:
Is it possible for the nothrow form of the new operator to ever throw?
6
by: Evan David Light | last post by:
After agonizing over this problem for a few days, I've decided to seek help. No, not the variety that involes a jacket that zips up the back but this august body of intrepid individuals. I've...
0
by: Lamar | last post by:
I have been told that we cannot have both the SOAP::Lite and the DBI modules available on our IRIX box due to some conflict. Has anyone else encountered this problem and/or discovered a work...
1
by: Lighter | last post by:
Is there a way to write a memory leak detector supporting new(nothrow)? For example, #include <My_Debug_New.h> using namespace std; int main() {
9
by: Alex Vinokur | last post by:
What is difference between delete p; and delete(nothrow)p; ? -- Alex Vinokur email: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html
4
by: Alex Vinokur | last post by:
Foo* p = new (nothrow) Foo; Should we use operator delete (p, nothrow) ? Or can we use delete p; ? If we use operator delete (p, nothrow) how to replace it by operator style?
16
by: Dustan | last post by:
This is the biggie that has been keeping me from even trying to use C+ + for more than about 10 seconds: it doesn't work. I've been able to get java and (of course) python programs to compile and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.