Trolltech Home | Qtopia-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qtopia-interest Archive, February 2008
Impressions when reading the server code


Message 1 in thread

Hey,

let me start with this impression. In a lot of places in the server and other 
places in Qtopia you use the following idiom:

	if (fooObject)
		delete fooObject;

According to §6.2.6 of the Stroustrup you may call delete on named objects if 
they were allocated with new or if it is Null. You should go through the 
Qtopia code and clean these things up.


z,

--
 [ signature omitted ] 

Message 2 in thread

Holger Freyther wrote:
> Hey,
>
> let me start with this impression. In a lot of places in the server and other 
> places in Qtopia you use the following idiom:
>
> 	if (fooObject)
> 		delete fooObject;
>
> According to §6.2.6 of the Stroustrup you may call delete on named objects if 
> they were allocated with new or if it is Null. You should go through the 
> Qtopia code and clean these things up.
>
>
> z,
>
> --
> To unsubscribe - send "unsubscribe" in the subject to qtopia-interest-request@xxxxxxxxxxxxx
>
>
>   
Reality does not always reflect the documentation. I know I've had
segfaults before from deleting a null'd object. Caution is always better
than 3 bytes saved.

-- 
 [ signature omitted ] 

Message 3 in thread

On Thursday 21 February 2008 00:48:39 Bill KING wrote:

> Reality does not always reflect the documentation. I know I've had
> segfaults before from deleting a null'd object. Caution is always better
> than 3 bytes saved.

Hehe, I knew that would come so please take a look at 
qtopia/qtopiaapplication.cpp and search for operator delete, e.g

void operator delete(void* p)
{
    if (p)
        free(p);
}

So what you write is:
	if (p)
		if (p)
			free(p);

this is not wrong it just looks stupid and clueless. Now the question is where 
your caution is coming from. None of the supported compilers of Qt need this 
check, why does Qtopia need it? By pure logic it can not support more 
compilers than Qt so there is no reason. But I remember times where these 
operators in qtopiaapplication.cpp (qpeapplication.cpp back then) didn't have 
this check and were in violation of the C++ spec.

Bottom line: These checks are not needed for any supported compiler, you might 
want to do briefings and such...


z.


PS: Actually for most of the targets these are 4 bytes, remember RISC and such 
things.

--
 [ signature omitted ]