new/delete mismatch

Cheng, Cheuk cheng@powertv.com
Wed Mar 10 22:01:00 GMT 2004


Hi, I am using sparc-elf-gcc 2.95.3 and it looks like there are cases
where objects will call new for new data, using our overloaded operator
new as expected, but when the element is deleted, the system delete
(__builtin_delete) is called on the data. I do not believe that this is
expected behavior. We are overriding operator delete and operator new.
In the final analysis when the struct in the case below is allocated,
the new from our new.cpp gets called, which calls ourOS_Calloc. But when
the struct is deleted, the system built-in delete gets called, and NOT
the delete from new.cpp, which calls ourOS_Free.  Also, we override
delete in CObject, but not new. I am not sure there is an issue with
this at runtime, but it is bad form.

Thanks.

Here is a sample, code is followed by its disassembly:

ui32 CEventClientList::Add (ui32 EventCode, ui32 EventMask, CEventSink
*Sink, void *Interest, CWindow *Window) {
	//## begin CEventClientList::Add%3ABA17A80157.body preserve=yes
	EventClient *evtc = new EventClient;
	evtc->EventCode = EventCode;
	evtc->EventMask = EventMask;
	evtc->Sink = Sink;
	evtc->EI = Interest;
	evtc->Window = Window;
	return (m_List.Add(evtc));
	//## end CEventClientList::Add%3ABA17A80157.body
}

075c57ec <_Add__16CEventClientListUiUiP10CEventSinkPvP7CWindow>:
75c57ec: 9d e3 bf 98 save %sp, -104, %sp
75c57f0: 90 10 20 14 mov 0x14, %o0
75c57f4: 7f fe fd c4 call 7584f04 <___nw__FUi8_NEWHEAP>
75c57f8: 92 10 20 00 clr %o1
75c57fc: 92 10 00 08 mov %o0, %o1
75c5800: 90 10 00 18 mov %i0, %o0
75c5804: f2 22 60 04 st %i1, [ %o1 + 4 ]
75c5808: f4 22 60 08 st %i2, [ %o1 + 8 ]
75c580c: f6 22 60 0c st %i3, [ %o1 + 0xc ]
75c5810: f8 22 60 10 st %i4, [ %o1 + 0x10 ]
75c5814: 40 00 35 6d call 75d2dc8 <_Add__5CListPv>
75c5818: fa 22 40 00 st %i5, [ %o1 ]
75c581c: 81 c7 e0 08 ret 
75c5820: 91 e8 00 08 restore %g0, %o0, %o0


Boolean CEventClientList::Delete (ui32 index)
{
	//## begin CEventClientList::Delete%3ABA1D810251.body
preserve=yes
	EventClient *evtc;
	Boolean result = FALSE;
	if (index<Count())
	{
		evtc = (EventClient *)m_List.Get(index);
		if (evtc)
		{
			result = TRUE;
			delete evtc;
		}
	m_List.Delete(index);
	}
	return (result);
	//## end CEventClientList::Delete%3ABA1D810251.body
}

075c5824 <_Delete__16CEventClientListUi>:
75c5824: 9d e3 bf 98 save %sp, -104, %sp
75c5828: 7f ff ff cd call 75c575c <_Count__16CEventClientList>
75c582c: 90 10 00 18 mov %i0, %o0
75c5830: 80 a6 40 08 cmp %i1, %o0
75c5834: 1a 80 00 0d bcc 75c5868 <_Delete__16CEventClientListUi+0x44>
75c5838: a0 10 20 00 clr %l0
75c583c: 90 10 00 18 mov %i0, %o0
75c5840: 40 00 34 de call 75d2bb8 <_Get__5CListUi>
75c5844: 92 10 00 19 mov %i1, %o1
75c5848: 80 a2 20 00 cmp %o0, 0
75c584c: 22 80 00 05 be,a 75c5860 <_Delete__16CEventClientListUi+0x3c>
75c5850: 90 10 00 18 mov %i0, %o0
75c5854: 40 2f 00 ca call 8185b7c <___builtin_delete>
// Is this wrong?
75c5858: a0 10 20 01 mov 1, %l0
75c585c: 90 10 00 18 mov %i0, %o0
75c5860: 40 00 35 81 call 75d2e64 <_Delete__5CListUi>
75c5864: 92 10 00 19 mov %i1, %o1
75c5868: 81 c7 e0 08 ret 
75c586c: 91 e8 00 10 restore %g0, %l0, %o0


- - - - - - - Appended by PowerTV, Inc. - - - - - - - 
This e-mail and any attachments may contain information that is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.



More information about the Gcc mailing list