[haiku-bugs] Re: [Haiku] #16638: ObjectDeleter: size in twice bigger then regular pointer

  • From: "Haiku" <trac@xxxxxxxxxxxx>
  • To: undisclosed-recipients: ;
  • Date: Fri, 04 Dec 2020 12:20:40 -0000

#16638: ObjectDeleter: size in twice bigger then regular pointer
------------------------+----------------------------
  Reporter:  X512       |      Owner:  nobody
      Type:  bug        |     Status:  new
  Priority:  normal     |  Milestone:  Unscheduled
 Component:  - General  |    Version:  R1/Development
Resolution:             |   Keywords:
Blocked By:             |   Blocking:
  Platform:  All        |
------------------------+----------------------------
Comment (by X512):

 Following trick can fix issue:

 {{{
 #!diff
 diff --git a/headers/private/shared/AutoDeleter.h
 b/headers/private/shared/AutoDeleter.h
 index 7f16091809..b77f007185 100644
 --- a/headers/private/shared/AutoDeleter.h
 +++ b/headers/private/shared/AutoDeleter.h
 @@ -29,25 +29,25 @@ template<typename C, typename DeleteFunc>
  class AutoDeleter {
  public:
         inline AutoDeleter()
 -               : fObject(NULL)
 +               : fInt(NULL)
         {
         }

         inline AutoDeleter(C *object)
 -               : fObject(object)
 +               : fInt(object)
         {
         }

         inline ~AutoDeleter()
         {
 -               fDelete(fObject);
 +               fInt(fInt.fObject);
         }

         inline void SetTo(C *object)
         {
 -               if (object != fObject) {
 -                       fDelete(fObject);
 -                       fObject = object;
 +               if (object != fInt.fObject) {
 +                       fInt(fInt.fObject);
 +                       fInt.fObject = object;
                 }
         }

 @@ -63,24 +63,26 @@ public:

         inline C *Get() const
         {
 -               return fObject;
 +               return fInt.fObject;
         }

         inline C *Detach()
         {
 -               C *object = fObject;
 -               fObject = NULL;
 +               C *object = fInt.fObject;
 +               fInt.fObject = NULL;
                 return object;
         }

         inline C *operator->() const
         {
 -               return fObject;
 +               return fInt.fObject;
         }

  protected:
 -       C                       *fObject;
 -       DeleteFunc      fDelete;
 +       struct Internal: DeleteFunc {
 +               C* fObject;
 +               inline Internal(C *object): fObject(object) {}
 +       } fInt;

  private:
         AutoDeleter(const AutoDeleter&);
 }}}
-- 
Ticket URL: <https://dev.haiku-os.org/ticket/16638#comment:2>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: