Bug 2941 - no new/delete operators for structures (Win32+MSVC)
Summary: no new/delete operators for structures (Win32+MSVC)
Status: NEW
Alias: None
Product: TAO
Classification: Unclassified
Component: IDL Compiler (show other bugs)
Version: 1.5.8
Hardware: All All
: P3 enhancement
Assignee: DOC Center Support List (internal)
URL:
Depends on: 2842
Blocks:
  Show dependency tree
 
Reported: 2007-05-23 14:00 CDT by Abdul Sowayan
Modified: 2018-01-15 11:21 CST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Abdul Sowayan 2007-05-23 14:00:09 CDT
Putting this discussion in Bugzilla so we won't lose this information.

Hi German,

German Zhivotnikov wrote:

> 
> could someone make clear the following issue.

 > [snip]

> 
> the following thing occurs: the instance of struct A is allocated by
> stub, which lives in Stub.dll, while the A_var would delete this
> instance within Client.exe.
> 
> I was sure C++ idl compiler must generate operator new and operator
> delete for each generated structure. However, tao_idl does not do it.
> Without such operators, we face the following problem with Win32+MSVC
> platform: if either Stub.dll or Client.exe, or both, are built with
> static runtime (/MT switch), the heap would be corrupted, since in
> Win32 each shared object built with static runtime has its own heap.
> So, the ways to get things working is either
> a) to use Dynamic Runtime (/MD switch), or
> b) not to use this approach with separating stubs into a DLL - at
> all.
> The problem would not appear, had tao_idl generated (exported from
> DLL) operator new and operator delete for the structures.
> 

All of the ACE+TAO tests and examples use the Dynamic Runtime (/MD or 
/MDd) so this hasn't been an issue in our builds.  I don't know of any 
applications built on TAO that are using a static runtime with user 
DLL's but there may be some out there.  For TAO to really support this, 
a switch could be added to tao_idl to generate the new and delete 
operators as you suggest.  You could send us patches or fund one of the 
commercial support vendors 
(http://www.cs.wustl.edu/~schmidt/commercial-support.html) to do it.

Thanks,
Adam Mitz
Software Engineer
Object Computing, Inc.
Comment 1 Abdul Sowayan 2007-05-23 14:00:22 CDT
Hi,

For structures, wouldn't this be as simple as having the IDL compiler
generate ACE_ALLOC_HOOK_DECLARE in the structure body? And generate
ACE_ALLOC_HOOK_DEFINE(...) in the cpp file? For instance:

HEADER FILE:
struct A
{ 
  /// Declare the dynamic allocation hooks.
  ACE_ALLOC_HOOK_DECLARE;
  .
  .
  .
};

CPP FILE:
ACE_ALLOC_HOOK_DEFINE(A)

Thanks,
Abdul
Comment 2 Abdul Sowayan 2007-05-23 14:00:43 CDT
Hi Abdul,

Yes, I think that should work. German, can you try to use the macros Abdul
has pointed out and handcraft a generated file and see if that works and let
us know the results?

Regards,

Johnny Willemsen
Remedy IT
Postbus 101
2650 AC  Berkel en Rodenrijs
The Netherlands
www.theaceorb.nl / www.remedy.nl  
Comment 3 Abdul Sowayan 2007-05-23 14:01:04 CDT
ACE_ALLOC_HOOK_DEFINE uses "new char[]" to allocate memory.  I'm not 
sure why we would want this.  Why not just defer to global operators new 
and delete?

Thanks,
Adam

Comment 4 Abdul Sowayan 2007-05-23 14:01:16 CDT
Adam,

It isn't clear to me either why "new char[]" is used either. Maybe when
ACE first started out in the early 90s some compilers didn't have it? 

At any rate, ACE_ALLOC_HOOK needs some enhancements. Look at Bugzilla
2842 for details.
http://deuce.doc.wustl.edu/bugzilla/﷒0﷓

Thanks,
Abdul
Comment 5 Johnny Willemsen 2007-05-23 14:36:28 CDT
added depends, changed severity
Comment 6 Johnny Willemsen 2007-05-24 08:55:46 CDT
enhancement