lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] [lmi-commits] master a67848a 1/3: Use 'new(wx)' to allocate me


From: Vadim Zeitlin
Subject: Re: [lmi] [lmi-commits] master a67848a 1/3: Use 'new(wx)' to allocate memory that will be freed by wx
Date: Tue, 9 Feb 2021 02:36:01 +0100

On Mon, 8 Feb 2021 22:11:00 +0000 Greg Chicares <gchicares@sbcglobal.net> wrote:

GC> On 2/8/21 11:30 AM, Vadim Zeitlin wrote:
GC> > On Sun, 7 Feb 2021 23:17:08 +0000 Greg Chicares <gchicares@sbcglobal.net> 
wrote:
GC> [...]
GC> > GC> Would we write
GC> > GC>   std::unique_ptr<InputSequenceEntry> z = new(wx) 
InputSequenceEntry(...);
GC> > GC> because there's no make_unique(wx) that would delegate to new(wx)?
GC> > 
GC> >  I could be wrong, but I thought we only need to use new(wx) for the
GC> > pointers deleted by wxWidgets. And normally this is the case for all 
window
GC> > pointers that we create in lmi code, which is why we use new(wx) for all 
of
GC> > them. However in this particular case we want to delete the window
GC> > ourselves, so it won't be deleted by wxWidgets and hence there is no need
GC> > for new(wx) and we can just write
GC> > 
GC> >   auto const z = std::make_unique<InputSequenceEntry>(...);
GC> 
GC> Should it be easy to write that in a way that compiles?

 Yes, I definitely hope so...

GC> I tried:
GC> 
GC> diff --git a/skeleton.cpp b/skeleton.cpp
GC> index 267582eba..b37aa3fbf 100644
GC> --- a/skeleton.cpp
GC> +++ b/skeleton.cpp
GC> @@ -1081,7 +1081,8 @@ void 
Skeleton::UponTestFloatingPointEnvironment(wxCommandEvent&)
GC>  
GC>  void Skeleton::UponTestPasting(wxCommandEvent&)
GC>  {
GC> -    InputSequenceEntry* z = new(wx) InputSequenceEntry(frame_, wxID_ANY, 
"Testing...");
GC> +    auto const z = std::make_unique<InputSequenceEntry>
GC> +        (InputSequenceEntry(frame_, wxID_ANY, "Testing..."));

 This doesn't compile because you're trying to use the copy ctor, which
doesn't exist for InputSequenceEntry (as for any wxWindow-derived class).
The correct version is just

    +        (frame_, wxID_ANY, "Testing...");

GC> I even tried making it a shared_ptr, in the hope that that would
GC> be less fussy, but got similar diagnostics.

 Which could be fixed in the same way because both make_xxx() functions
forward the arguments you give them to the class ctor -- so if you give
them an InputSequenceEntry object, they try using the copy ctor and fail.

 Regards,
VZ

Attachment: pgpz4VyxzZCzL.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]